From 26f5e20580b087e517350d4dede6d8fb77090a91 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Sat, 9 Apr 2022 21:34:39 -0700 Subject: [PATCH] PG15: update integer parsing APIs. Account for PG commits 3c6f8c011f and cfc7191dfe. --- src/backend/distributed/commands/function.c | 2 +- .../distributed/executor/adaptive_executor.c | 3 +-- .../distributed/operations/shard_rebalancer.c | 5 ++--- .../distributed/operations/stage_protocol.c | 2 +- .../distributed/test/shard_rebalancer.c | 1 - .../distributed/transaction/lock_graph.c | 2 +- .../transaction/remote_transaction.c | 2 +- .../worker/worker_data_fetch_protocol.c | 2 +- src/include/pg_version_compat.h | 18 ++++++++++++++++++ 9 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index 879aa4770..51141c4d5 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -490,7 +490,7 @@ GetDistributionArgIndex(Oid functionOid, char *distributionArgumentName, distributionArgumentName++; /* throws error if the input is not an integer */ - distributionArgumentIndex = pg_atoi(distributionArgumentName, 4, 0); + distributionArgumentIndex = pg_strtoint32(distributionArgumentName); if (distributionArgumentIndex < 1 || distributionArgumentIndex > numberOfArgs) { diff --git a/src/backend/distributed/executor/adaptive_executor.c b/src/backend/distributed/executor/adaptive_executor.c index 2b32916ee..347bd4d35 100644 --- a/src/backend/distributed/executor/adaptive_executor.c +++ b/src/backend/distributed/executor/adaptive_executor.c @@ -171,7 +171,6 @@ #include "storage/fd.h" #include "storage/latch.h" #include "utils/builtins.h" -#include "utils/int8.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/syscache.h" @@ -4513,7 +4512,7 @@ ReceiveResults(WorkerSession *session, bool storeRows) /* if there are multiple replicas, make sure to consider only one */ if (storeRows && *currentAffectedTupleString != '\0') { - scanint8(currentAffectedTupleString, false, ¤tAffectedTupleCount); + currentAffectedTupleCount = pg_strtoint64(currentAffectedTupleString); Assert(currentAffectedTupleCount >= 0); execution->rowsProcessed += currentAffectedTupleCount; } diff --git a/src/backend/distributed/operations/shard_rebalancer.c b/src/backend/distributed/operations/shard_rebalancer.c index 16ee50c52..ecb0d6673 100644 --- a/src/backend/distributed/operations/shard_rebalancer.c +++ b/src/backend/distributed/operations/shard_rebalancer.c @@ -54,7 +54,6 @@ #include "storage/lmgr.h" #include "utils/builtins.h" #include "utils/fmgroids.h" -#include "utils/int8.h" #include "utils/json.h" #include "utils/lsyscache.h" #include "utils/memutils.h" @@ -1396,9 +1395,9 @@ GetShardStatistics(MultiConnection *connection, HTAB *shardIds) for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { char *shardIdString = PQgetvalue(result, rowIndex, 0); - uint64 shardId = pg_strtouint64(shardIdString, NULL, 10); + uint64 shardId = strtou64(shardIdString, NULL, 10); char *sizeString = PQgetvalue(result, rowIndex, 1); - uint64 totalSize = pg_strtouint64(sizeString, NULL, 10); + uint64 totalSize = strtou64(sizeString, NULL, 10); ShardStatistics *statistics = hash_search(shardStatistics, &shardId, HASH_ENTER, NULL); diff --git a/src/backend/distributed/operations/stage_protocol.c b/src/backend/distributed/operations/stage_protocol.c index d6e9c0f2a..8f77205cb 100644 --- a/src/backend/distributed/operations/stage_protocol.c +++ b/src/backend/distributed/operations/stage_protocol.c @@ -923,7 +923,7 @@ WorkerShardStats(ShardPlacement *placement, Oid relationId, const char *shardNam } errno = 0; - uint64 tableSize = pg_strtouint64(tableSizeString, &tableSizeStringEnd, 0); + uint64 tableSize = strtou64(tableSizeString, &tableSizeStringEnd, 0); if (errno != 0 || (*tableSizeStringEnd) != '\0') { PQclear(queryResult); diff --git a/src/backend/distributed/test/shard_rebalancer.c b/src/backend/distributed/test/shard_rebalancer.c index ea770cb6e..f3640f415 100644 --- a/src/backend/distributed/test/shard_rebalancer.c +++ b/src/backend/distributed/test/shard_rebalancer.c @@ -28,7 +28,6 @@ #include "funcapi.h" #include "miscadmin.h" #include "utils/builtins.h" -#include "utils/int8.h" #include "utils/json.h" #include "utils/lsyscache.h" #include "utils/memutils.h" diff --git a/src/backend/distributed/transaction/lock_graph.c b/src/backend/distributed/transaction/lock_graph.c index 62b5e4e04..e672dafd8 100644 --- a/src/backend/distributed/transaction/lock_graph.c +++ b/src/backend/distributed/transaction/lock_graph.c @@ -309,7 +309,7 @@ ParseIntField(PGresult *result, int rowIndex, int colIndex) char *resultString = PQgetvalue(result, rowIndex, colIndex); - return pg_strtouint64(resultString, NULL, 10); + return strtou64(resultString, NULL, 10); } diff --git a/src/backend/distributed/transaction/remote_transaction.c b/src/backend/distributed/transaction/remote_transaction.c index 2859ec4c9..55a560575 100644 --- a/src/backend/distributed/transaction/remote_transaction.c +++ b/src/backend/distributed/transaction/remote_transaction.c @@ -1408,7 +1408,7 @@ ParsePreparedTransactionName(char *preparedTransactionName, /* step ahead of the current '_' character */ ++currentCharPointer; - *transactionNumber = pg_strtouint64(currentCharPointer, NULL, 10); + *transactionNumber = strtou64(currentCharPointer, NULL, 10); if ((*transactionNumber == 0 && errno != 0) || (*transactionNumber == ULLONG_MAX && errno == ERANGE)) { diff --git a/src/backend/distributed/worker/worker_data_fetch_protocol.c b/src/backend/distributed/worker/worker_data_fetch_protocol.c index 5e78c19ce..cbc7af89a 100644 --- a/src/backend/distributed/worker/worker_data_fetch_protocol.c +++ b/src/backend/distributed/worker/worker_data_fetch_protocol.c @@ -387,7 +387,7 @@ ExtractShardIdFromTableName(const char *tableName, bool missingOk) shardIdString++; errno = 0; - uint64 shardId = pg_strtouint64(shardIdString, &shardIdStringEnd, 0); + uint64 shardId = strtou64(shardIdString, &shardIdStringEnd, 0); if (errno != 0 || (*shardIdStringEnd != '\0')) { diff --git a/src/include/pg_version_compat.h b/src/include/pg_version_compat.h index dc21acf5f..fd7767a2b 100644 --- a/src/include/pg_version_compat.h +++ b/src/include/pg_version_compat.h @@ -19,10 +19,28 @@ #else #include "storage/smgr.h" +#include "utils/int8.h" #include "utils/rel.h" + +#ifdef HAVE_LONG_INT_64 +#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base)) +#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base)) +#else +#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base)) +#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base)) +#endif #define RelationCreateStorage_compat(a, b, c) RelationCreateStorage(a, b) +static inline int64 +pg_strtoint64(char *s) +{ + int64 result; + (void) scanint8(s, false, &result); + return result; +} + + static inline SMgrRelation RelationGetSmgr(Relation rel) {