Hi, Having learned some things about gettext based on clues[1] from Peter E, I decided to see what it would take to expunge all (long long) and similar casts now that we're using the standard types with system support.
The short version is tha given uint64 x: Old: errmsg("hello %llu", (unsigned long long) x) New: errmsg("hello %" PRIu64, x) (And all other printf-like interfaces). That d can be x, X, u, etc and you can put the usual stuff between % and the macro, so it's cut up slightly differently than our own macros for that stuff. You can't make your own macros for this, if you want to localise it at least, because gettext() and the tools that scan your source tree only treat the ones from <inttypes.h> specially. 65 files changed, 358 insertions(+), 367 deletions(-) (Not counting the pgbench bits, that's non mechanical.) Thoughts? I know it's a fair bit of code churn, but not quite as bad as I was expecting. It would create an occasional back-patching speed-bump, but it's mechanical at least. I wonder how often bug fixes could conflict with this stuff. And no doubt .po file churn ... I don't know what tooling is used for that sort of stuff but I imagine that automated replacement might go a long way. [1] https://postgr.es/m/b936d2fb-590d-49c3-a615-92c3a88c6c19%40eisentraut.org
From 2a6c5a6fd9c902c6958e2fc3a7c5a98bff7d0f7e Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Fri, 6 Dec 2024 04:42:59 +1300 Subject: [PATCH 1/4] Use PRI*64 instead of "ll*" in format strings. Old: errmsg("hello %llu", (unsigned long long) x) New: errmsg("hello %" PRIu64, x) And likewise for everything printf-like. In the past we had to use long long so localized format strings remained architecture independent in message catalogs. Although long long is expected to be 64 bit everywhere, if we hadn't also cast the int64 values, we'd have generated compiler warnings on systems where int64 was long. Now that int64 is int64_t, C99 understand how to format them using <inttypes.h> macros, the casts are not necessary, and the gettext() tools recognize the macros and defer expansion until load time. (And if we ever manage to get -Wformat-signedness to work for us, that'd help with these too, but not the type-system-clobbering casts.) This patch mechanically removes most uses of [unsigned] long [long] for [u]int64 trafficking. A couple of places were cast from size_t or int and didn't need <inttypes.h>, and off_t is a bit of special case, where I had to keep casts, but make them (pgoff_t) which is at least better documentation. The remaining uses of long [long] are legitimate ECPG APIs dealing in those types, and pgbench, which required some slightly less mechanical cleanup that deserving a seperate patch. Suggested-by: Peter Eisentraut <pe...@eisentraut.org> Discussion: https://postgr.es/m/b936d2fb-590d-49c3-a615-92c3a88c6c19%40eisentraut.org --- contrib/file_fdw/file_fdw.c | 20 +++---- contrib/pageinspect/btreefuncs.c | 6 +- contrib/pageinspect/hashfuncs.c | 4 +- contrib/pg_prewarm/pg_prewarm.c | 8 +-- src/backend/access/brin/brin.c | 7 +-- src/backend/access/heap/vacuumlazy.c | 42 +++++++------- src/backend/access/rmgrdesc/clogdesc.c | 6 +- src/backend/access/rmgrdesc/committsdesc.c | 6 +- src/backend/access/rmgrdesc/mxactdesc.c | 2 +- src/backend/access/rmgrdesc/xactdesc.c | 4 +- src/backend/access/transam/multixact.c | 28 +++++----- src/backend/access/transam/slru.c | 3 +- src/backend/access/transam/twophase.c | 12 ++-- src/backend/access/transam/xlogarchive.c | 6 +- src/backend/access/transam/xloginsert.c | 8 +-- src/backend/access/transam/xlogreader.c | 10 ++-- src/backend/backup/basebackup.c | 6 +- src/backend/backup/basebackup_incremental.c | 6 +- src/backend/backup/walsummaryfuncs.c | 2 +- src/backend/catalog/catalog.c | 12 ++-- src/backend/commands/analyze.c | 16 +++--- src/backend/commands/copy.c | 4 +- src/backend/commands/copyfrom.c | 36 ++++++------ src/backend/commands/copyfromparse.c | 8 +-- src/backend/commands/explain.c | 50 ++++++++--------- src/backend/commands/sequence.c | 56 +++++++++---------- src/backend/commands/vacuum.c | 4 +- src/backend/replication/logical/logical.c | 18 +++--- src/backend/replication/slot.c | 6 +- src/backend/replication/walreceiver.c | 4 +- src/backend/storage/ipc/ipc.c | 4 +- src/backend/storage/ipc/signalfuncs.c | 6 +- src/backend/utils/activity/pgstat.c | 16 +++--- src/backend/utils/activity/pgstat_replslot.c | 4 +- src/backend/utils/activity/pgstat_shmem.c | 4 +- src/backend/utils/activity/pgstat_xact.c | 4 +- src/backend/utils/adt/datetime.c | 24 ++++---- src/backend/utils/adt/varlena.c | 8 +-- src/backend/utils/adt/xid8funcs.c | 4 +- src/backend/utils/error/csvlog.c | 2 +- src/backend/utils/error/elog.c | 8 +-- src/backend/utils/error/jsonlog.c | 4 +- src/backend/utils/mmgr/mcxt.c | 16 +++--- src/backend/utils/sort/logtape.c | 16 +++--- src/backend/utils/sort/tuplesort.c | 8 +-- src/bin/pg_basebackup/pg_createsubscriber.c | 10 ++-- src/bin/pg_basebackup/pg_receivewal.c | 4 +- src/bin/pg_checksums/pg_checksums.c | 16 +++--- src/bin/pg_combinebackup/load_manifest.c | 10 ++-- src/bin/pg_combinebackup/pg_combinebackup.c | 19 +++---- src/bin/pg_combinebackup/reconstruct.c | 10 ++-- src/bin/pg_combinebackup/write_manifest.c | 3 +- src/bin/pg_controldata/pg_controldata.c | 4 +- src/bin/pg_dump/pg_backup_tar.c | 18 +++--- src/bin/pg_resetwal/pg_resetwal.c | 4 +- src/bin/pg_rewind/libpq_source.c | 8 +-- src/bin/pg_verifybackup/astreamer_verify.c | 18 +++--- src/bin/pg_verifybackup/pg_verifybackup.c | 27 +++++---- src/fe_utils/archive.c | 6 +- src/fe_utils/print.c | 10 ++-- src/include/lib/radixtree.h | 6 +- .../modules/libpq_pipeline/libpq_pipeline.c | 2 +- .../test_copy_callbacks/test_copy_callbacks.c | 4 +- src/test/modules/test_slru/test_slru.c | 8 +-- .../modules/xid_wraparound/xid_wraparound.c | 10 ++-- 65 files changed, 358 insertions(+), 367 deletions(-) diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 1c81a7c073d..d343cabf5fe 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -793,8 +793,8 @@ retry: cstate->num_errors > cstate->opts.reject_limit) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("skipped more than REJECT_LIMIT (%lld) rows due to data type incompatibility", - (long long) cstate->opts.reject_limit))); + errmsg("skipped more than REJECT_LIMIT (%" PRId64 ") rows due to data type incompatibility", + cstate->opts.reject_limit))); /* Repeat NextCopyFrom() until no soft error occurs */ goto retry; @@ -850,10 +850,10 @@ fileEndForeignScan(ForeignScanState *node) festate->cstate->num_errors > 0 && festate->cstate->opts.log_verbosity >= COPY_LOG_VERBOSITY_DEFAULT) ereport(NOTICE, - errmsg_plural("%llu row was skipped due to data type incompatibility", - "%llu rows were skipped due to data type incompatibility", - (unsigned long long) festate->cstate->num_errors, - (unsigned long long) festate->cstate->num_errors)); + errmsg_plural("%" PRIu64 " row was skipped due to data type incompatibility", + "%" PRIu64 " rows were skipped due to data type incompatibility", + festate->cstate->num_errors, + festate->cstate->num_errors)); EndCopyFrom(festate->cstate); } @@ -1314,10 +1314,10 @@ file_acquire_sample_rows(Relation onerel, int elevel, cstate->num_errors > 0 && cstate->opts.log_verbosity >= COPY_LOG_VERBOSITY_DEFAULT) ereport(NOTICE, - errmsg_plural("%llu row was skipped due to data type incompatibility", - "%llu rows were skipped due to data type incompatibility", - (unsigned long long) cstate->num_errors, - (unsigned long long) cstate->num_errors)); + errmsg_plural("%" PRIu64 " row was skipped due to data type incompatibility", + "%" PRIu64 " rows were skipped due to data type incompatibility", + cstate->num_errors, + cstate->num_errors)); EndCopyFrom(cstate); diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c index 9cdc8e182b4..294821231fc 100644 --- a/contrib/pageinspect/btreefuncs.c +++ b/contrib/pageinspect/btreefuncs.c @@ -206,14 +206,12 @@ check_relation_block_range(Relation rel, int64 blkno) if (blkno < 0 || blkno > MaxBlockNumber) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid block number %lld", - (long long) blkno))); + errmsg("invalid block number %" PRId64, blkno))); if ((BlockNumber) (blkno) >= RelationGetNumberOfBlocks(rel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("block number %lld is out of range", - (long long) blkno))); + errmsg("block number %" PRId64 " is out of range", blkno))); } /* ----------------------------------------------- diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index d4f827a7e2d..9f9c88ae62f 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -436,8 +436,8 @@ hash_bitmap_info(PG_FUNCTION_ARGS) if (ovflblkno >= RelationGetNumberOfBlocks(indexRel)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("block number %lld is out of range for relation \"%s\"", - (long long int) ovflblkno, RelationGetRelationName(indexRel)))); + errmsg("block number %" PRId64 " is out of range for relation \"%s\"", + ovflblkno, RelationGetRelationName(indexRel)))); /* Read the metapage so we can determine which bitmap page to use */ metabuf = _hash_getbuf(indexRel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); diff --git a/contrib/pg_prewarm/pg_prewarm.c b/contrib/pg_prewarm/pg_prewarm.c index 243d36c46e8..5a0d4a9209b 100644 --- a/contrib/pg_prewarm/pg_prewarm.c +++ b/contrib/pg_prewarm/pg_prewarm.c @@ -126,8 +126,8 @@ pg_prewarm(PG_FUNCTION_ARGS) if (first_block < 0 || first_block >= nblocks) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("starting block number must be between 0 and %lld", - (long long) (nblocks - 1)))); + errmsg("starting block number must be between 0 and %" PRId64, + (nblocks - 1)))); } if (PG_ARGISNULL(4)) last_block = nblocks - 1; @@ -137,8 +137,8 @@ pg_prewarm(PG_FUNCTION_ARGS) if (last_block < 0 || last_block >= nblocks) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("ending block number must be between 0 and %lld", - (long long) (nblocks - 1)))); + errmsg("ending block number must be between 0 and %" PRId64, + (nblocks - 1)))); } /* Now we're ready to do the real work. */ diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c index 3aedec882cd..d8bfb3bc933 100644 --- a/src/backend/access/brin/brin.c +++ b/src/backend/access/brin/brin.c @@ -1391,8 +1391,7 @@ brin_summarize_range(PG_FUNCTION_ARGS) if (heapBlk64 > BRIN_ALL_BLOCKRANGES || heapBlk64 < 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("block number out of range: %lld", - (long long) heapBlk64))); + errmsg("block number out of range: %" PRId64, heapBlk64))); heapBlk = (BlockNumber) heapBlk64; /* @@ -1499,8 +1498,8 @@ brin_desummarize_range(PG_FUNCTION_ARGS) if (heapBlk64 > MaxBlockNumber || heapBlk64 < 0) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("block number out of range: %lld", - (long long) heapBlk64))); + errmsg("block number out of range: %" PRId64, + heapBlk64))); heapBlk = (BlockNumber) heapBlk64; /* diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 6a3588cf817..595fed471f2 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -665,14 +665,14 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, orig_rel_pages == 0 ? 100.0 : 100.0 * vacrel->scanned_pages / orig_rel_pages); appendStringInfo(&buf, - _("tuples: %lld removed, %lld remain, %lld are dead but not yet removable\n"), - (long long) vacrel->tuples_deleted, - (long long) vacrel->new_rel_tuples, - (long long) vacrel->recently_dead_tuples); + _("tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"), + vacrel->tuples_deleted, + (int64) vacrel->new_rel_tuples, + vacrel->recently_dead_tuples); if (vacrel->missed_dead_tuples > 0) appendStringInfo(&buf, - _("tuples missed: %lld dead from %u pages not removed due to cleanup lock contention\n"), - (long long) vacrel->missed_dead_tuples, + _("tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"), + vacrel->missed_dead_tuples, vacrel->missed_dead_pages); diff = (int32) (ReadNextTransactionId() - vacrel->cutoffs.OldestXmin); @@ -695,11 +695,11 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, _("new relminmxid: %u, which is %d MXIDs ahead of previous value\n"), vacrel->NewRelminMxid, diff); } - appendStringInfo(&buf, _("frozen: %u pages from table (%.2f%% of total) had %lld tuples frozen\n"), + appendStringInfo(&buf, _("frozen: %u pages from table (%.2f%% of total) had %" PRId64 " tuples frozen\n"), vacrel->frozen_pages, orig_rel_pages == 0 ? 100.0 : 100.0 * vacrel->frozen_pages / orig_rel_pages, - (long long) vacrel->tuples_frozen); + vacrel->tuples_frozen); if (vacrel->do_index_vacuuming) { if (vacrel->nindexes == 0 || vacrel->num_index_scans == 0) @@ -707,7 +707,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, else appendStringInfoString(&buf, _("index scan needed: ")); - msgfmt = _("%u pages from table (%.2f%% of total) had %lld dead item identifiers removed\n"); + msgfmt = _("%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n"); } else { @@ -716,13 +716,13 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, else appendStringInfoString(&buf, _("index scan bypassed by failsafe: ")); - msgfmt = _("%u pages from table (%.2f%% of total) have %lld dead item identifiers\n"); + msgfmt = _("%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n"); } appendStringInfo(&buf, msgfmt, vacrel->lpdead_item_pages, orig_rel_pages == 0 ? 100.0 : 100.0 * vacrel->lpdead_item_pages / orig_rel_pages, - (long long) vacrel->lpdead_items); + vacrel->lpdead_items); for (int i = 0; i < vacrel->nindexes; i++) { IndexBulkDeleteResult *istat = vacrel->indstats[i]; @@ -756,15 +756,15 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"), read_rate, write_rate); appendStringInfo(&buf, - _("buffer usage: %lld hits, %lld reads, %lld dirtied\n"), - (long long) total_blks_hit, - (long long) total_blks_read, - (long long) total_blks_dirtied); + _("buffer usage: %" PRId64 " hits, %" PRId64 " reads, %" PRId64 " dirtied\n"), + total_blks_hit, + total_blks_read, + total_blks_dirtied); appendStringInfo(&buf, - _("WAL usage: %lld records, %lld full page images, %llu bytes\n"), - (long long) walusage.wal_records, - (long long) walusage.wal_fpi, - (unsigned long long) walusage.wal_bytes); + _("WAL usage: %" PRId64 " records, %" PRId64 " full page images, %" PRIu64 " bytes\n"), + walusage.wal_records, + walusage.wal_fpi, + walusage.wal_bytes); appendStringInfo(&buf, _("system usage: %s"), pg_rusage_show(&ru0)); ereport(verbose ? INFO : LOG, @@ -2180,8 +2180,8 @@ lazy_vacuum_heap_rel(LVRelState *vacrel) vacuumed_pages == vacrel->lpdead_item_pages)); ereport(DEBUG2, - (errmsg("table \"%s\": removed %lld dead item identifiers in %u pages", - vacrel->relname, (long long) vacrel->dead_items_info->num_items, + (errmsg("table \"%s\": removed %" PRId64 " dead item identifiers in %u pages", + vacrel->relname, vacrel->dead_items_info->num_items, vacuumed_pages))); /* Revert to the previous phase information for error traceback */ diff --git a/src/backend/access/rmgrdesc/clogdesc.c b/src/backend/access/rmgrdesc/clogdesc.c index c1d47c219f9..83c712c6f9e 100644 --- a/src/backend/access/rmgrdesc/clogdesc.c +++ b/src/backend/access/rmgrdesc/clogdesc.c @@ -28,15 +28,15 @@ clog_desc(StringInfo buf, XLogReaderState *record) int64 pageno; memcpy(&pageno, rec, sizeof(pageno)); - appendStringInfo(buf, "page %lld", (long long) pageno); + appendStringInfo(buf, "page %" PRId64, pageno); } else if (info == CLOG_TRUNCATE) { xl_clog_truncate xlrec; memcpy(&xlrec, rec, sizeof(xl_clog_truncate)); - appendStringInfo(buf, "page %lld; oldestXact %u", - (long long) xlrec.pageno, xlrec.oldestXact); + appendStringInfo(buf, "page %" PRId64 "; oldestXact %u", + xlrec.pageno, xlrec.oldestXact); } } diff --git a/src/backend/access/rmgrdesc/committsdesc.c b/src/backend/access/rmgrdesc/committsdesc.c index f5f09a1bc79..c8125e00b03 100644 --- a/src/backend/access/rmgrdesc/committsdesc.c +++ b/src/backend/access/rmgrdesc/committsdesc.c @@ -28,14 +28,14 @@ commit_ts_desc(StringInfo buf, XLogReaderState *record) int64 pageno; memcpy(&pageno, rec, sizeof(pageno)); - appendStringInfo(buf, "%lld", (long long) pageno); + appendStringInfo(buf, "%" PRId64, pageno); } else if (info == COMMIT_TS_TRUNCATE) { xl_commit_ts_truncate *trunc = (xl_commit_ts_truncate *) rec; - appendStringInfo(buf, "pageno %lld, oldestXid %u", - (long long) trunc->pageno, trunc->oldestXid); + appendStringInfo(buf, "pageno %" PRId64 ", oldestXid %u", + trunc->pageno, trunc->oldestXid); } } diff --git a/src/backend/access/rmgrdesc/mxactdesc.c b/src/backend/access/rmgrdesc/mxactdesc.c index 3e8ad4d5ef8..29f77ba3c7c 100644 --- a/src/backend/access/rmgrdesc/mxactdesc.c +++ b/src/backend/access/rmgrdesc/mxactdesc.c @@ -58,7 +58,7 @@ multixact_desc(StringInfo buf, XLogReaderState *record) int64 pageno; memcpy(&pageno, rec, sizeof(pageno)); - appendStringInfo(buf, "%lld", (long long) pageno); + appendStringInfo(buf, "%" PRId64, pageno); } else if (info == XLOG_MULTIXACT_CREATE_ID) { diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c index 889cb955c18..132b79e4d05 100644 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@ -322,10 +322,10 @@ xact_desc_stats(StringInfo buf, const char *label, uint64 objid = ((uint64) dropped_stats[i].objid_hi) << 32 | dropped_stats[i].objid_lo; - appendStringInfo(buf, " %d/%u/%llu", + appendStringInfo(buf, " %d/%u/%" PRIu64, dropped_stats[i].kind, dropped_stats[i].dboid, - (unsigned long long) objid); + objid); } } } diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 8c37d7eba76..482693c303f 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -3058,8 +3058,8 @@ PerformMembersTruncation(MultiXactOffset oldestOffset, MultiXactOffset newOldest */ while (segment != endsegment) { - elog(DEBUG2, "truncating multixact members segment %llx", - (unsigned long long) segment); + elog(DEBUG2, "truncating multixact members segment %" PRIx64, + segment); SlruDeleteSegment(MultiXactMemberCtl, segment); /* move to next segment, handling wraparound correctly */ @@ -3210,14 +3210,14 @@ TruncateMultiXact(MultiXactId newOldestMulti, Oid newOldestMultiDB) } elog(DEBUG1, "performing multixact truncation: " - "offsets [%u, %u), offsets segments [%llx, %llx), " - "members [%u, %u), members segments [%llx, %llx)", + "offsets [%u, %u), offsets segments [%" PRIx64 ", %" PRIx64 "), " + "members [%u, %u), members segments [%" PRIx64 ", %" PRIx64 ")", oldestMulti, newOldestMulti, - (unsigned long long) MultiXactIdToOffsetSegment(oldestMulti), - (unsigned long long) MultiXactIdToOffsetSegment(newOldestMulti), + MultiXactIdToOffsetSegment(oldestMulti), + MultiXactIdToOffsetSegment(newOldestMulti), oldestOffset, newOldestOffset, - (unsigned long long) MXOffsetToMemberSegment(oldestOffset), - (unsigned long long) MXOffsetToMemberSegment(newOldestOffset)); + MXOffsetToMemberSegment(oldestOffset), + MXOffsetToMemberSegment(newOldestOffset)); /* * Do truncation, and the WAL logging of the truncation, in a critical @@ -3470,14 +3470,14 @@ multixact_redo(XLogReaderState *record) SizeOfMultiXactTruncate); elog(DEBUG1, "replaying multixact truncation: " - "offsets [%u, %u), offsets segments [%llx, %llx), " - "members [%u, %u), members segments [%llx, %llx)", + "offsets [%u, %u), offsets segments [%" PRIx64 ", %" PRIx64 "), " + "members [%u, %u), members segments [%" PRIx64 ", %" PRIx64 ")", xlrec.startTruncOff, xlrec.endTruncOff, - (unsigned long long) MultiXactIdToOffsetSegment(xlrec.startTruncOff), - (unsigned long long) MultiXactIdToOffsetSegment(xlrec.endTruncOff), + MultiXactIdToOffsetSegment(xlrec.startTruncOff), + MultiXactIdToOffsetSegment(xlrec.endTruncOff), xlrec.startTruncMemb, xlrec.endTruncMemb, - (unsigned long long) MXOffsetToMemberSegment(xlrec.startTruncMemb), - (unsigned long long) MXOffsetToMemberSegment(xlrec.endTruncMemb)); + MXOffsetToMemberSegment(xlrec.startTruncMemb), + MXOffsetToMemberSegment(xlrec.endTruncMemb)); /* should not be required, but more than cheap enough */ LWLockAcquire(MultiXactTruncationLock, LW_EXCLUSIVE); diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c index 0022c41c814..8d7f77fe181 100644 --- a/src/backend/access/transam/slru.c +++ b/src/backend/access/transam/slru.c @@ -100,8 +100,7 @@ SlruFileName(SlruCtl ctl, char *path, int64 segno) * that in the future we can't decrease SLRU_PAGES_PER_SEGMENT easily. */ Assert(segno >= 0 && segno <= INT64CONST(0xFFFFFFFFFFFFFFF)); - return snprintf(path, MAXPGPATH, "%s/%015llX", ctl->Dir, - (long long) segno); + return snprintf(path, MAXPGPATH, "%s/%015" PRIX64, ctl->Dir, segno); } else { diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 49be1df91c1..0415b85cfe0 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1342,10 +1342,10 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok) stat.st_size > MaxAllocSize) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg_plural("incorrect size of file \"%s\": %lld byte", - "incorrect size of file \"%s\": %lld bytes", - (long long int) stat.st_size, path, - (long long int) stat.st_size))); + errmsg_plural("incorrect size of file \"%s\": %" PRId64 " byte", + "incorrect size of file \"%s\": %" PRId64 " bytes", + (pgoff_t) stat.st_size, path, + (pgoff_t) stat.st_size))); crc_offset = stat.st_size - sizeof(pg_crc32c); if (crc_offset != MAXALIGN(crc_offset)) @@ -1369,8 +1369,8 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok) errmsg("could not read file \"%s\": %m", path))); else ereport(ERROR, - (errmsg("could not read file \"%s\": read %d of %lld", - path, r, (long long int) stat.st_size))); + (errmsg("could not read file \"%s\": read %d of %" PRId64, + path, r, (pgoff_t) stat.st_size))); } pgstat_report_wait_end(); diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c index 81999b48200..7eb9bcae708 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -210,10 +210,10 @@ RestoreArchivedFile(char *path, const char *xlogfname, else elevel = FATAL; ereport(elevel, - (errmsg("archive file \"%s\" has wrong size: %lld instead of %lld", + (errmsg("archive file \"%s\" has wrong size: %" PRId64 " instead of %" PRId64, xlogfname, - (long long int) stat_buf.st_size, - (long long int) expectedSize))); + (pgoff_t) stat_buf.st_size, + (pgoff_t) expectedSize))); return false; } else diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index f92d0626082..37949bfafd4 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -869,8 +869,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, if (mainrdata_len > PG_UINT32_MAX) ereport(ERROR, (errmsg_internal("too much WAL data"), - errdetail_internal("Main data length is %llu bytes for a maximum of %u bytes.", - (unsigned long long) mainrdata_len, + errdetail_internal("Main data length is %" PRIu64 " bytes for a maximum of %u bytes.", + mainrdata_len, PG_UINT32_MAX))); mainrdata_len_4b = (uint32) mainrdata_len; @@ -915,8 +915,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, if (total_len > XLogRecordMaxSize) ereport(ERROR, (errmsg_internal("oversized WAL record"), - errdetail_internal("WAL record would be %llu bytes (of maximum %u bytes); rmid %u flags %u.", - (unsigned long long) total_len, XLogRecordMaxSize, rmid, info))); + errdetail_internal("WAL record would be %" PRIu64 " bytes (of maximum %u bytes); rmid %u flags %u.", + total_len, XLogRecordMaxSize, rmid, info))); /* * Fill in the fields in the record header. Prev-link is filled in later, diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 0c5e040a946..21653602e77 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -768,9 +768,9 @@ restart: total_len != (pageHeader->xlp_rem_len + gotlen)) { report_invalid_record(state, - "invalid contrecord length %u (expected %lld) at %X/%X", + "invalid contrecord length %u (expected %u) at %X/%X", pageHeader->xlp_rem_len, - ((long long) total_len) - gotlen, + total_len - gotlen, LSN_FORMAT_ARGS(RecPtr)); goto err; } @@ -1271,9 +1271,9 @@ XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr, longhdr->xlp_sysid != state->system_identifier) { report_invalid_record(state, - "WAL file is from different database system: WAL file database system identifier is %llu, pg_control database system identifier is %llu", - (unsigned long long) longhdr->xlp_sysid, - (unsigned long long) state->system_identifier); + "WAL file is from different database system: WAL file database system identifier is %" PRIu64 ", pg_control database system identifier is %" PRIu64, + longhdr->xlp_sysid, + state->system_identifier); return false; } else if (longhdr->xlp_seg_size != state->segcxt.ws_segsize) diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c index e2ed9081d1c..bca3d041af1 100644 --- a/src/backend/backup/basebackup.c +++ b/src/backend/backup/basebackup.c @@ -123,7 +123,7 @@ static ssize_t basebackup_read_file(int fd, char *buf, size_t nbytes, off_t offs static bool backup_started_in_recovery = false; /* Total number of checksum failures during base backup. */ -static long long int total_checksum_failures; +static int64 total_checksum_failures; /* Do not verify checksums. */ static bool noverify_checksums = false; @@ -655,8 +655,8 @@ perform_base_backup(basebackup_options *opt, bbsink *sink, { if (total_checksum_failures > 1) ereport(WARNING, - (errmsg_plural("%lld total checksum verification failure", - "%lld total checksum verification failures", + (errmsg_plural("%" PRId64 " total checksum verification failure", + "%" PRId64 " total checksum verification failures", total_checksum_failures, total_checksum_failures))); diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c index 87cc1b96cbc..18ab9448b42 100644 --- a/src/backend/backup/basebackup_incremental.c +++ b/src/backend/backup/basebackup_incremental.c @@ -951,9 +951,9 @@ manifest_process_system_identifier(JsonManifestParseContext *context, if (manifest_system_identifier != system_identifier) context->error_cb(context, - "system identifier in backup manifest is %llu, but database system identifier is %llu", - (unsigned long long) manifest_system_identifier, - (unsigned long long) system_identifier); + "system identifier in backup manifest is %" PRIu64 ", but database system identifier is %" PRIu64, + manifest_system_identifier, + system_identifier); } /* diff --git a/src/backend/backup/walsummaryfuncs.c b/src/backend/backup/walsummaryfuncs.c index bb6a3a4a366..d79639f735f 100644 --- a/src/backend/backup/walsummaryfuncs.c +++ b/src/backend/backup/walsummaryfuncs.c @@ -92,7 +92,7 @@ pg_wal_summary_contents(PG_FUNCTION_ARGS) if (raw_tli < 1 || raw_tli > PG_INT32_MAX) ereport(ERROR, errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid timeline %lld", (long long) raw_tli)); + errmsg("invalid timeline %" PRId64, raw_tli)); /* Prepare to read the specified WAL summary file. */ ws.tli = (TimeLineID) raw_tli; diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index cfe8c5104b6..44eae35ae4b 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -474,10 +474,10 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn) ereport(LOG, (errmsg("still searching for an unused OID in relation \"%s\"", RelationGetRelationName(relation)), - errdetail_plural("OID candidates have been checked %llu time, but no unused OID has been found yet.", - "OID candidates have been checked %llu times, but no unused OID has been found yet.", + errdetail_plural("OID candidates have been checked %" PRIu64 " time, but no unused OID has been found yet.", + "OID candidates have been checked %" PRIu64 " times, but no unused OID has been found yet.", retries, - (unsigned long long) retries))); + retries))); /* * Double the number of retries to do before logging next until it @@ -499,10 +499,10 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn) if (retries > GETNEWOID_LOG_THRESHOLD) { ereport(LOG, - (errmsg_plural("new OID has been assigned in relation \"%s\" after %llu retry", - "new OID has been assigned in relation \"%s\" after %llu retries", + (errmsg_plural("new OID has been assigned in relation \"%s\" after %" PRIu64 " retry", + "new OID has been assigned in relation \"%s\" after %" PRIu64 " retries", retries, - RelationGetRelationName(relation), (unsigned long long) retries))); + RelationGetRelationName(relation), retries))); } return newOid; diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 9a56de2282f..0183047d1a4 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -816,15 +816,15 @@ do_analyze_rel(Relation onerel, VacuumParams *params, } appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"), read_rate, write_rate); - appendStringInfo(&buf, _("buffer usage: %lld hits, %lld reads, %lld dirtied\n"), - (long long) total_blks_hit, - (long long) total_blks_read, - (long long) total_blks_dirtied); + appendStringInfo(&buf, _("buffer usage: %" PRId64 " hits, %" PRId64 " reads, %" PRId64 " dirtied\n"), + total_blks_hit, + total_blks_read, + total_blks_dirtied); appendStringInfo(&buf, - _("WAL usage: %lld records, %lld full page images, %llu bytes\n"), - (long long) walusage.wal_records, - (long long) walusage.wal_fpi, - (unsigned long long) walusage.wal_bytes); + _("WAL usage: %" PRId64 " records, %" PRId64 " full page images, %" PRIu64 " bytes\n"), + walusage.wal_records, + walusage.wal_fpi, + walusage.wal_bytes); appendStringInfo(&buf, _("system usage: %s"), pg_rusage_show(&ru0)); ereport(verbose ? INFO : LOG, diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 2d98ecf3f4e..14c99b76fb0 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -443,8 +443,8 @@ defGetCopyRejectLimitOption(DefElem *def) if (reject_limit <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("REJECT_LIMIT (%lld) must be greater than zero", - (long long) reject_limit))); + errmsg("REJECT_LIMIT (%" PRId64 ") must be greater than zero", + reject_limit))); return reject_limit; } diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 4d52c93c301..bdef527ca78 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -126,14 +126,14 @@ CopyFromErrorCallback(void *arg) { /* can't usefully display the data */ if (cstate->cur_attname) - errcontext("COPY %s, line %llu, column %s", + errcontext("COPY %s, line %" PRIu64 ", column %s", cstate->cur_relname, - (unsigned long long) cstate->cur_lineno, + cstate->cur_lineno, cstate->cur_attname); else - errcontext("COPY %s, line %llu", + errcontext("COPY %s, line %" PRIu64, cstate->cur_relname, - (unsigned long long) cstate->cur_lineno); + cstate->cur_lineno); } else { @@ -143,9 +143,9 @@ CopyFromErrorCallback(void *arg) char *attval; attval = CopyLimitPrintoutLength(cstate->cur_attval); - errcontext("COPY %s, line %llu, column %s: \"%s\"", + errcontext("COPY %s, line %" PRIu64 ", column %s: \"%s\"", cstate->cur_relname, - (unsigned long long) cstate->cur_lineno, + cstate->cur_lineno, cstate->cur_attname, attval); pfree(attval); @@ -153,9 +153,9 @@ CopyFromErrorCallback(void *arg) else if (cstate->cur_attname) { /* error is relevant to a particular column, value is NULL */ - errcontext("COPY %s, line %llu, column %s: null input", + errcontext("COPY %s, line %" PRIu64 ", column %s: null input", cstate->cur_relname, - (unsigned long long) cstate->cur_lineno, + cstate->cur_lineno, cstate->cur_attname); } else @@ -170,16 +170,16 @@ CopyFromErrorCallback(void *arg) char *lineval; lineval = CopyLimitPrintoutLength(cstate->line_buf.data); - errcontext("COPY %s, line %llu: \"%s\"", + errcontext("COPY %s, line %" PRIu64 ": \"%s\"", cstate->cur_relname, - (unsigned long long) cstate->cur_lineno, lineval); + cstate->cur_lineno, lineval); pfree(lineval); } else { - errcontext("COPY %s, line %llu", + errcontext("COPY %s, line %" PRIu64, cstate->cur_relname, - (unsigned long long) cstate->cur_lineno); + cstate->cur_lineno); } } } @@ -1022,8 +1022,8 @@ CopyFrom(CopyFromState cstate) cstate->num_errors > cstate->opts.reject_limit) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("skipped more than REJECT_LIMIT (%lld) rows due to data type incompatibility", - (long long) cstate->opts.reject_limit))); + errmsg("skipped more than REJECT_LIMIT (%" PRId64 ") rows due to data type incompatibility", + cstate->opts.reject_limit))); /* Repeat NextCopyFrom() until no soft error occurs */ continue; @@ -1325,10 +1325,10 @@ CopyFrom(CopyFromState cstate) cstate->num_errors > 0 && cstate->opts.log_verbosity >= COPY_LOG_VERBOSITY_DEFAULT) ereport(NOTICE, - errmsg_plural("%llu row was skipped due to data type incompatibility", - "%llu rows were skipped due to data type incompatibility", - (unsigned long long) cstate->num_errors, - (unsigned long long) cstate->num_errors)); + errmsg_plural("%" PRIu64 " row was skipped due to data type incompatibility", + "%" PRIu64 " rows were skipped due to data type incompatibility", + cstate->num_errors, + cstate->num_errors)); if (bistate != NULL) FreeBulkInsertState(bistate); diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c index d1d43b53d83..06cd903b57a 100644 --- a/src/backend/commands/copyfromparse.c +++ b/src/backend/commands/copyfromparse.c @@ -978,16 +978,16 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext, attval = CopyLimitPrintoutLength(cstate->cur_attval); ereport(NOTICE, - errmsg("skipping row due to data type incompatibility at line %llu for column \"%s\": \"%s\"", - (unsigned long long) cstate->cur_lineno, + errmsg("skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": \"%s\"", + cstate->cur_lineno, cstate->cur_attname, attval)); pfree(attval); } else ereport(NOTICE, - errmsg("skipping row due to data type incompatibility at line %llu for column \"%s\": null input", - (unsigned long long) cstate->cur_lineno, + errmsg("skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": null input", + cstate->cur_lineno, cstate->cur_attname)); /* reset relname_only */ diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index a3f1d53d7a5..3797f982a60 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -4091,17 +4091,17 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage) { appendStringInfoString(es->str, " shared"); if (usage->shared_blks_hit > 0) - appendStringInfo(es->str, " hit=%lld", - (long long) usage->shared_blks_hit); + appendStringInfo(es->str, " hit=%" PRId64, + usage->shared_blks_hit); if (usage->shared_blks_read > 0) - appendStringInfo(es->str, " read=%lld", - (long long) usage->shared_blks_read); + appendStringInfo(es->str, " read=%" PRId64, + usage->shared_blks_read); if (usage->shared_blks_dirtied > 0) - appendStringInfo(es->str, " dirtied=%lld", - (long long) usage->shared_blks_dirtied); + appendStringInfo(es->str, " dirtied=%" PRId64, + usage->shared_blks_dirtied); if (usage->shared_blks_written > 0) - appendStringInfo(es->str, " written=%lld", - (long long) usage->shared_blks_written); + appendStringInfo(es->str, " written=%" PRId64, + usage->shared_blks_written); if (has_local || has_temp) appendStringInfoChar(es->str, ','); } @@ -4109,17 +4109,17 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage) { appendStringInfoString(es->str, " local"); if (usage->local_blks_hit > 0) - appendStringInfo(es->str, " hit=%lld", - (long long) usage->local_blks_hit); + appendStringInfo(es->str, " hit=%" PRId64, + usage->local_blks_hit); if (usage->local_blks_read > 0) - appendStringInfo(es->str, " read=%lld", - (long long) usage->local_blks_read); + appendStringInfo(es->str, " read=%" PRId64, + usage->local_blks_read); if (usage->local_blks_dirtied > 0) - appendStringInfo(es->str, " dirtied=%lld", - (long long) usage->local_blks_dirtied); + appendStringInfo(es->str, " dirtied=%" PRId64, + usage->local_blks_dirtied); if (usage->local_blks_written > 0) - appendStringInfo(es->str, " written=%lld", - (long long) usage->local_blks_written); + appendStringInfo(es->str, " written=%" PRId64, + usage->local_blks_written); if (has_temp) appendStringInfoChar(es->str, ','); } @@ -4127,11 +4127,11 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage) { appendStringInfoString(es->str, " temp"); if (usage->temp_blks_read > 0) - appendStringInfo(es->str, " read=%lld", - (long long) usage->temp_blks_read); + appendStringInfo(es->str, " read=%" PRId64, + usage->temp_blks_read); if (usage->temp_blks_written > 0) - appendStringInfo(es->str, " written=%lld", - (long long) usage->temp_blks_written); + appendStringInfo(es->str, " written=%" PRId64, + usage->temp_blks_written); } appendStringInfoChar(es->str, '\n'); } @@ -4241,13 +4241,13 @@ show_wal_usage(ExplainState *es, const WalUsage *usage) appendStringInfoString(es->str, "WAL:"); if (usage->wal_records > 0) - appendStringInfo(es->str, " records=%lld", - (long long) usage->wal_records); + appendStringInfo(es->str, " records=%" PRId64, + usage->wal_records); if (usage->wal_fpi > 0) - appendStringInfo(es->str, " fpi=%lld", - (long long) usage->wal_fpi); + appendStringInfo(es->str, " fpi=%" PRId64, + usage->wal_fpi); if (usage->wal_bytes > 0) - appendStringInfo(es->str, " bytes=" UINT64_FORMAT, + appendStringInfo(es->str, " bytes=%" PRIu64, usage->wal_bytes); appendStringInfoChar(es->str, '\n'); } diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 0188e8bbd5b..1301dd99774 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -745,9 +745,9 @@ nextval_internal(Oid relid, bool check_permissions) if (!cycle) ereport(ERROR, (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED), - errmsg("nextval: reached maximum value of sequence \"%s\" (%lld)", + errmsg("nextval: reached maximum value of sequence \"%s\" (%" PRId64 ")", RelationGetRelationName(seqrel), - (long long) maxv))); + maxv))); next = minv; } else @@ -764,9 +764,9 @@ nextval_internal(Oid relid, bool check_permissions) if (!cycle) ereport(ERROR, (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED), - errmsg("nextval: reached minimum value of sequence \"%s\" (%lld)", + errmsg("nextval: reached minimum value of sequence \"%s\" (%" PRId64 ")", RelationGetRelationName(seqrel), - (long long) minv))); + minv))); next = maxv; } else @@ -988,9 +988,9 @@ do_setval(Oid relid, int64 next, bool iscalled) if ((next < minv) || (next > maxv)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), - errmsg("setval: value %lld is out of bounds for sequence \"%s\" (%lld..%lld)", - (long long) next, RelationGetRelationName(seqrel), - (long long) minv, (long long) maxv))); + errmsg("setval: value %" PRId64 " is out of bounds for sequence \"%s\" (%" PRId64 "..%" PRId64 ")", + next, RelationGetRelationName(seqrel), + minv, maxv))); /* Set the currval() state only if iscalled = true */ if (iscalled) @@ -1463,8 +1463,8 @@ init_params(ParseState *pstate, List *options, bool for_identity, || (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX))) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MAXVALUE (%lld) is out of range for sequence data type %s", - (long long) seqform->seqmax, + errmsg("MAXVALUE (%" PRId64 ") is out of range for sequence data type %s", + seqform->seqmax, format_type_be(seqform->seqtypid)))); /* MINVALUE (null arg means NO MINVALUE) */ @@ -1495,17 +1495,17 @@ init_params(ParseState *pstate, List *options, bool for_identity, || (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX))) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MINVALUE (%lld) is out of range for sequence data type %s", - (long long) seqform->seqmin, + errmsg("MINVALUE (%" PRId64 ") is out of range for sequence data type %s", + seqform->seqmin, format_type_be(seqform->seqtypid)))); /* crosscheck min/max */ if (seqform->seqmin >= seqform->seqmax) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("MINVALUE (%lld) must be less than MAXVALUE (%lld)", - (long long) seqform->seqmin, - (long long) seqform->seqmax))); + errmsg("MINVALUE (%" PRId64 ") must be less than MAXVALUE (%" PRId64 ")", + seqform->seqmin, + seqform->seqmax))); /* START WITH */ if (start_value != NULL) @@ -1524,15 +1524,15 @@ init_params(ParseState *pstate, List *options, bool for_identity, if (seqform->seqstart < seqform->seqmin) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("START value (%lld) cannot be less than MINVALUE (%lld)", - (long long) seqform->seqstart, - (long long) seqform->seqmin))); + errmsg("START value (%" PRId64 ") cannot be less than MINVALUE (%" PRId64 ")", + seqform->seqstart, + seqform->seqmin))); if (seqform->seqstart > seqform->seqmax) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("START value (%lld) cannot be greater than MAXVALUE (%lld)", - (long long) seqform->seqstart, - (long long) seqform->seqmax))); + errmsg("START value (%" PRId64 ") cannot be greater than MAXVALUE (%" PRId64 ")", + seqform->seqstart, + seqform->seqmax))); /* RESTART [WITH] */ if (restart_value != NULL) @@ -1554,15 +1554,15 @@ init_params(ParseState *pstate, List *options, bool for_identity, if (seqdataform->last_value < seqform->seqmin) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("RESTART value (%lld) cannot be less than MINVALUE (%lld)", - (long long) seqdataform->last_value, - (long long) seqform->seqmin))); + errmsg("RESTART value (%" PRId64 ") cannot be less than MINVALUE (%" PRId64 ")", + seqdataform->last_value, + seqform->seqmin))); if (seqdataform->last_value > seqform->seqmax) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("RESTART value (%lld) cannot be greater than MAXVALUE (%lld)", - (long long) seqdataform->last_value, - (long long) seqform->seqmax))); + errmsg("RESTART value (%" PRId64 ") cannot be greater than MAXVALUE (%" PRId64 ")", + seqdataform->last_value, + seqform->seqmax))); /* CACHE */ if (cache_value != NULL) @@ -1571,8 +1571,8 @@ init_params(ParseState *pstate, List *options, bool for_identity, if (seqform->seqcache <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("CACHE (%lld) must be greater than zero", - (long long) seqform->seqcache))); + errmsg("CACHE (%" PRId64 ") must be greater than zero", + seqform->seqcache))); seqdataform->log_cnt = 0; } else if (isInit) diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index bb639ef51fb..7fca11c826c 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -2521,9 +2521,9 @@ vac_bulkdel_one_index(IndexVacuumInfo *ivinfo, IndexBulkDeleteResult *istat, dead_items); ereport(ivinfo->message_level, - (errmsg("scanned index \"%s\" to remove %lld row versions", + (errmsg("scanned index \"%s\" to remove %" PRId64 " row versions", RelationGetRelationName(ivinfo->index), - (long long) dead_items_info->num_items))); + dead_items_info->num_items))); return istat; } diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 4dc14fdb495..63c14608faa 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -1940,16 +1940,16 @@ UpdateDecodingStats(LogicalDecodingContext *ctx) if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0) return; - elog(DEBUG2, "UpdateDecodingStats: updating stats %p %lld %lld %lld %lld %lld %lld %lld %lld", + elog(DEBUG2, "UpdateDecodingStats: updating stats %p %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, rb, - (long long) rb->spillTxns, - (long long) rb->spillCount, - (long long) rb->spillBytes, - (long long) rb->streamTxns, - (long long) rb->streamCount, - (long long) rb->streamBytes, - (long long) rb->totalTxns, - (long long) rb->totalBytes); + rb->spillTxns, + rb->spillCount, + rb->spillBytes, + rb->streamTxns, + rb->streamCount, + rb->streamBytes, + rb->totalTxns, + rb->totalBytes); repSlotStat.spill_txns = rb->spillTxns; repSlotStat.spill_count = rb->spillCount; diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 4a206f95277..07cf2741494 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1519,12 +1519,12 @@ ReportSlotInvalidation(ReplicationSlotInvalidationCause cause, { case RS_INVAL_WAL_REMOVED: { - unsigned long long ex = oldestLSN - restart_lsn; + uint64 ex = oldestLSN - restart_lsn; hint = true; appendStringInfo(&err_detail, - ngettext("The slot's restart_lsn %X/%X exceeds the limit by %llu byte.", - "The slot's restart_lsn %X/%X exceeds the limit by %llu bytes.", + ngettext("The slot's restart_lsn %X/%X exceeds the limit by %" PRIu64 " byte.", + "The slot's restart_lsn %X/%X exceeds the limit by %" PRIu64 " bytes.", ex), LSN_FORMAT_ARGS(restart_lsn), ex); diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 5f641d27905..20fd4a7ac1a 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -387,8 +387,8 @@ WalReceiverMain(char *startup_data, size_t startup_data_len) if (is_temp_slot) { snprintf(slotname, sizeof(slotname), - "pg_walreceiver_%lld", - (long long int) walrcv_get_backend_pid(wrconn)); + "pg_walreceiver_%" PRId64, + (int64) walrcv_get_backend_pid(wrconn)); walrcv_create_slot(wrconn, slotname, true, false, false, 0, NULL); diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c index b06e4b84528..2b9e3899023 100644 --- a/src/backend/storage/ipc/ipc.c +++ b/src/backend/storage/ipc/ipc.c @@ -399,8 +399,8 @@ cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg) before_shmem_exit_list[before_shmem_exit_index - 1].arg == arg) --before_shmem_exit_index; else - elog(ERROR, "before_shmem_exit callback (%p,0x%llx) is not the latest entry", - function, (long long) arg); + elog(ERROR, "before_shmem_exit callback (%p,0x%" PRIx64 ") is not the latest entry", + function, arg); } /* ---------------------------------------------------------------- diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c index d8353276007..57d1ae8b39b 100644 --- a/src/backend/storage/ipc/signalfuncs.c +++ b/src/backend/storage/ipc/signalfuncs.c @@ -215,10 +215,10 @@ pg_wait_until_termination(int pid, int64 timeout) } while (remainingtime > 0); ereport(WARNING, - (errmsg_plural("backend with PID %d did not terminate within %lld millisecond", - "backend with PID %d did not terminate within %lld milliseconds", + (errmsg_plural("backend with PID %d did not terminate within %" PRId64 " millisecond", + "backend with PID %d did not terminate within %" PRId64 " milliseconds", timeout, - pid, (long long int) timeout))); + pid, timeout))); return false; } diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index 6f8d2378266..170aabb5a6b 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -1666,9 +1666,9 @@ pgstat_write_statsfile(XLogRecPtr redo) */ if (!pgstat_is_kind_valid(ps->key.kind)) { - elog(WARNING, "found unknown stats entry %u/%u/%llu", + elog(WARNING, "found unknown stats entry %u/%u/%" PRIu64, ps->key.kind, ps->key.dboid, - (unsigned long long) ps->key.objid); + ps->key.objid); continue; } @@ -1908,9 +1908,9 @@ pgstat_read_statsfile(XLogRecPtr redo) if (!pgstat_is_kind_valid(key.kind)) { - elog(WARNING, "invalid stats kind for entry %u/%u/%llu of type %c", + elog(WARNING, "invalid stats kind for entry %u/%u/%" PRIu64 " of type %c", key.kind, key.dboid, - (unsigned long long) key.objid, t); + key.objid, t); goto error; } } @@ -1981,9 +1981,9 @@ pgstat_read_statsfile(XLogRecPtr redo) if (found) { dshash_release_lock(pgStatLocal.shared_hash, p); - elog(WARNING, "found duplicate stats entry %u/%u/%llu of type %c", + elog(WARNING, "found duplicate stats entry %u/%u/%" PRIu64 " of type %c", key.kind, key.dboid, - (unsigned long long) key.objid, t); + key.objid, t); goto error; } @@ -1994,9 +1994,9 @@ pgstat_read_statsfile(XLogRecPtr redo) pgstat_get_entry_data(key.kind, header), pgstat_get_entry_len(key.kind))) { - elog(WARNING, "could not read data for entry %u/%u/%llu of type %c", + elog(WARNING, "could not read data for entry %u/%u/%" PRIu64 " of type %c", key.kind, key.dboid, - (unsigned long long) key.objid, t); + key.objid, t); goto error; } diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index ddf2ab9928d..220e18aa093 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -194,8 +194,8 @@ pgstat_replslot_to_serialized_name_cb(const PgStat_HashKey *key, const PgStatSha * at the offset. */ if (!ReplicationSlotName(key->objid, name)) - elog(ERROR, "could not find name for replication slot index %llu", - (unsigned long long) key->objid); + elog(ERROR, "could not find name for replication slot index %" PRIu64, + key->objid); } bool diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 041c262b9fb..5aae64fc57c 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -857,10 +857,10 @@ pgstat_drop_entry_internal(PgStatShared_HashEntry *shent, */ if (shent->dropped) elog(ERROR, - "trying to drop stats entry already dropped: kind=%s dboid=%u objid=%llu refcount=%u", + "trying to drop stats entry already dropped: kind=%s dboid=%u objid=%" PRIu64 " refcount=%u", pgstat_get_kind_info(shent->key.kind)->name, shent->key.dboid, - (unsigned long long) shent->key.objid, + shent->key.objid, pg_atomic_read_u32(&shent->refcount)); shent->dropped = true; diff --git a/src/backend/utils/activity/pgstat_xact.c b/src/backend/utils/activity/pgstat_xact.c index f87a195996a..3124b4f2f16 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -363,9 +363,9 @@ pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid) if (pgstat_get_entry_ref(kind, dboid, objid, false, NULL)) { ereport(WARNING, - errmsg("resetting existing statistics for kind %s, db=%u, oid=%llu", + errmsg("resetting existing statistics for kind %s, db=%u, oid=%" PRIu64, (pgstat_get_kind_info(kind))->name, dboid, - (unsigned long long) objid)); + objid)); pgstat_reset(kind, dboid, objid); } diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 0b19cddf54b..67dbc0d13a1 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -4514,7 +4514,7 @@ AddISO8601IntPart(char *cp, int64 value, char units) { if (value == 0) return cp; - sprintf(cp, "%lld%c", (long long) value, units); + sprintf(cp, "%" PRId64 "%c", value, units); return cp + strlen(cp); } @@ -4525,10 +4525,10 @@ AddPostgresIntPart(char *cp, int64 value, const char *units, { if (value == 0) return cp; - sprintf(cp, "%s%s%lld %s%s", + sprintf(cp, "%s%s%" PRId64 " %s%s", (!*is_zero) ? " " : "", (*is_before && value > 0) ? "+" : "", - (long long) value, + value, units, (value != 1) ? "s" : ""); @@ -4556,7 +4556,7 @@ AddVerboseIntPart(char *cp, int64 value, const char *units, } else if (*is_before) value = -value; - sprintf(cp, " %lld %s%s", (long long) value, units, (value == 1) ? "" : "s"); + sprintf(cp, " %" PRId64 " %s%s", value, units, (value == 1) ? "" : "s"); *is_zero = false; return cp + strlen(cp); } @@ -4651,10 +4651,10 @@ EncodeInterval(struct pg_itm *itm, int style, char *str) char sec_sign = (hour < 0 || min < 0 || sec < 0 || fsec < 0) ? '-' : '+'; - sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:", + sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:", year_sign, abs(year), abs(mon), - day_sign, (long long) i64abs(mday), - sec_sign, (long long) i64abs(hour), abs(min)); + day_sign, i64abs(mday), + sec_sign, i64abs(hour), abs(min)); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; @@ -4665,15 +4665,15 @@ EncodeInterval(struct pg_itm *itm, int style, char *str) } else if (has_day) { - sprintf(cp, "%lld %lld:%02d:", - (long long) mday, (long long) hour, min); + sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:", + mday, hour, min); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; } else { - sprintf(cp, "%lld:%02d:", (long long) hour, min); + sprintf(cp, "%" PRId64 ":%02d:", hour, min); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; @@ -4723,10 +4723,10 @@ EncodeInterval(struct pg_itm *itm, int style, char *str) { bool minus = (hour < 0 || min < 0 || sec < 0 || fsec < 0); - sprintf(cp, "%s%s%02lld:%02d:", + sprintf(cp, "%s%s%02" PRId64 ":%02d:", is_zero ? "" : " ", (minus ? "-" : (is_before ? "+" : "")), - (long long) i64abs(hour), abs(min)); + i64abs(hour), abs(min)); cp += strlen(cp); cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true); *cp = '\0'; diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 533bebc1c7b..010c995214b 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -3224,8 +3224,8 @@ byteaGetBit(PG_FUNCTION_ARGS) if (n < 0 || n >= (int64) len * 8) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), - errmsg("index %lld out of valid range, 0..%lld", - (long long) n, (long long) len * 8 - 1))); + errmsg("index %" PRId64 " out of valid range, 0..%" PRId64, + n, (int64) len * 8 - 1))); /* n/8 is now known < len, so safe to cast to int */ byteNo = (int) (n / 8); @@ -3296,8 +3296,8 @@ byteaSetBit(PG_FUNCTION_ARGS) if (n < 0 || n >= (int64) len * 8) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), - errmsg("index %lld out of valid range, 0..%lld", - (long long) n, (long long) len * 8 - 1))); + errmsg("index %" PRId64 " out of valid range, 0..%" PRId64, + n, (int64) len * 8 - 1))); /* n/8 is now known < len, so safe to cast to int */ byteNo = (int) (n / 8); diff --git a/src/backend/utils/adt/xid8funcs.c b/src/backend/utils/adt/xid8funcs.c index 12d20b72a03..d8c35895046 100644 --- a/src/backend/utils/adt/xid8funcs.c +++ b/src/backend/utils/adt/xid8funcs.c @@ -121,8 +121,8 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid) if (!FullTransactionIdPrecedes(fxid, now_fullxid)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("transaction ID %llu is in the future", - (unsigned long long) U64FromFullTransactionId(fxid)))); + errmsg("transaction ID %" PRIu64 " is in the future", + U64FromFullTransactionId(fxid)))); /* * TransamVariables->oldestClogXid is protected by XactTruncationLock, but diff --git a/src/backend/utils/error/csvlog.c b/src/backend/utils/error/csvlog.c index acdffb6d067..60e1e919534 100644 --- a/src/backend/utils/error/csvlog.c +++ b/src/backend/utils/error/csvlog.c @@ -248,7 +248,7 @@ write_csvlog(ErrorData *edata) appendStringInfoChar(&buf, ','); /* query id */ - appendStringInfo(&buf, "%lld", (long long) pgstat_get_my_query_id()); + appendStringInfo(&buf, "%" PRId64, pgstat_get_my_query_id()); appendStringInfoChar(&buf, '\n'); diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 289059435a9..9e561fa651c 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -3148,11 +3148,11 @@ log_status_format(StringInfo buf, const char *format, ErrorData *edata) break; case 'Q': if (padding != 0) - appendStringInfo(buf, "%*lld", padding, - (long long) pgstat_get_my_query_id()); + appendStringInfo(buf, "%*" PRId64, padding, + pgstat_get_my_query_id()); else - appendStringInfo(buf, "%lld", - (long long) pgstat_get_my_query_id()); + appendStringInfo(buf, "%" PRId64, + pgstat_get_my_query_id()); break; default: /* format error - ignore it */ diff --git a/src/backend/utils/error/jsonlog.c b/src/backend/utils/error/jsonlog.c index 492383a89e2..b2af1ef82df 100644 --- a/src/backend/utils/error/jsonlog.c +++ b/src/backend/utils/error/jsonlog.c @@ -284,8 +284,8 @@ write_jsonlog(ErrorData *edata) } /* query id */ - appendJSONKeyValueFmt(&buf, "query_id", false, "%lld", - (long long) pgstat_get_my_query_id()); + appendJSONKeyValueFmt(&buf, "query_id", false, "%" PRId64, + pgstat_get_my_query_id()); /* Finish string */ appendStringInfoChar(&buf, '}'); diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 70d33226cb9..01fa0033024 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -285,31 +285,31 @@ MemoryContextTraverseNext(MemoryContext curr, MemoryContext top) static void BogusFree(void *pointer) { - elog(ERROR, "pfree called with invalid pointer %p (header 0x%016llx)", - pointer, (unsigned long long) GetMemoryChunkHeader(pointer)); + elog(ERROR, "pfree called with invalid pointer %p (header 0x%016" PRIx64 ")", + pointer, GetMemoryChunkHeader(pointer)); } static void * BogusRealloc(void *pointer, Size size, int flags) { - elog(ERROR, "repalloc called with invalid pointer %p (header 0x%016llx)", - pointer, (unsigned long long) GetMemoryChunkHeader(pointer)); + elog(ERROR, "repalloc called with invalid pointer %p (header 0x%016" PRIx64 ")", + pointer, GetMemoryChunkHeader(pointer)); return NULL; /* keep compiler quiet */ } static MemoryContext BogusGetChunkContext(void *pointer) { - elog(ERROR, "GetMemoryChunkContext called with invalid pointer %p (header 0x%016llx)", - pointer, (unsigned long long) GetMemoryChunkHeader(pointer)); + elog(ERROR, "GetMemoryChunkContext called with invalid pointer %p (header 0x%016" PRIx64 ")", + pointer, GetMemoryChunkHeader(pointer)); return NULL; /* keep compiler quiet */ } static Size BogusGetChunkSpace(void *pointer) { - elog(ERROR, "GetMemoryChunkSpace called with invalid pointer %p (header 0x%016llx)", - pointer, (unsigned long long) GetMemoryChunkHeader(pointer)); + elog(ERROR, "GetMemoryChunkSpace called with invalid pointer %p (header 0x%016" PRIx64 ")", + pointer, GetMemoryChunkHeader(pointer)); return 0; /* keep compiler quiet */ } diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c index 44b30e86adf..b2afddbaf38 100644 --- a/src/backend/utils/sort/logtape.c +++ b/src/backend/utils/sort/logtape.c @@ -263,8 +263,8 @@ ltsWriteBlock(LogicalTapeSet *lts, int64 blocknum, const void *buffer) if (BufFileSeekBlock(lts->pfile, blocknum) != 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not seek to block %lld of temporary file", - (long long) blocknum))); + errmsg("could not seek to block %" PRId64 " of temporary file", + blocknum))); BufFileWrite(lts->pfile, buffer, BLCKSZ); /* Update nBlocksWritten, if we extended the file */ @@ -284,8 +284,8 @@ ltsReadBlock(LogicalTapeSet *lts, int64 blocknum, void *buffer) if (BufFileSeekBlock(lts->pfile, blocknum) != 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not seek to block %lld of temporary file", - (long long) blocknum))); + errmsg("could not seek to block %" PRId64 " of temporary file", + blocknum))); BufFileReadExact(lts->pfile, buffer, BLCKSZ); } @@ -1100,10 +1100,10 @@ LogicalTapeBackspace(LogicalTape *lt, size_t size) ltsReadBlock(lt->tapeSet, prev, lt->buffer); if (TapeBlockGetTrailer(lt->buffer)->next != lt->curBlockNumber) - elog(ERROR, "broken tape, next of block %lld is %lld, expected %lld", - (long long) prev, - (long long) (TapeBlockGetTrailer(lt->buffer)->next), - (long long) lt->curBlockNumber); + elog(ERROR, "broken tape, next of block %" PRId64 " is %" PRId64 ", expected %" PRId64, + prev, + (TapeBlockGetTrailer(lt->buffer)->next), + lt->curBlockNumber); lt->nbytes = TapeBlockPayloadSize; lt->curBlockNumber = prev; diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index c960cfa8231..2a808e7818c 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -918,13 +918,13 @@ tuplesort_free(Tuplesortstate *state) if (trace_sort) { if (state->tapeset) - elog(LOG, "%s of worker %d ended, %lld disk blocks used: %s", + elog(LOG, "%s of worker %d ended, %" PRId64 " disk blocks used: %s", SERIAL(state) ? "external sort" : "parallel external sort", - state->worker, (long long) spaceUsed, pg_rusage_show(&state->ru_start)); + state->worker, spaceUsed, pg_rusage_show(&state->ru_start)); else - elog(LOG, "%s of worker %d ended, %lld KB used: %s", + elog(LOG, "%s of worker %d ended, %" PRId64 " KB used: %s", SERIAL(state) ? "internal sort" : "unperformed parallel sort", - state->worker, (long long) spaceUsed, pg_rusage_show(&state->ru_start)); + state->worker, spaceUsed, pg_rusage_show(&state->ru_start)); } TRACE_POSTGRESQL_SORT_DONE(state->tapeset != NULL, spaceUsed); diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index e96370a9ec1..0077a454aa3 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -582,8 +582,7 @@ get_primary_sysid(const char *conninfo) sysid = strtou64(PQgetvalue(res, 0, 0), NULL, 10); - pg_log_info("system identifier is %llu on publisher", - (unsigned long long) sysid); + pg_log_info("system identifier is %" PRIu64 " on publisher", sysid); PQclear(res); disconnect_database(conn, false); @@ -611,8 +610,7 @@ get_standby_sysid(const char *datadir) sysid = cf->system_identifier; - pg_log_info("system identifier is %llu on subscriber", - (unsigned long long) sysid); + pg_log_info("system identifier is %" PRIu64 " on subscriber", sysid); pg_free(cf); @@ -652,8 +650,8 @@ modify_subscriber_sysid(const struct CreateSubscriberOptions *opt) if (!dry_run) update_controlfile(subscriber_dir, cf, true); - pg_log_info("system identifier is %llu on subscriber", - (unsigned long long) cf->system_identifier); + pg_log_info("system identifier is %" PRIu64 " on subscriber", + cf->system_identifier); pg_log_info("running pg_resetwal on the subscriber"); diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index 555f0175f0e..cc89cf81f91 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -320,8 +320,8 @@ FindStreamingStart(uint32 *tli) if (statbuf.st_size != WalSegSz) { - pg_log_warning("segment file \"%s\" has incorrect size %lld, skipping", - dirent->d_name, (long long int) statbuf.st_size); + pg_log_warning("segment file \"%s\" has incorrect size %" PRId64 ", skipping", + dirent->d_name, (pgoff_t) statbuf.st_size); continue; } } diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index b86bc417c9c..ddeba04f756 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -141,9 +141,9 @@ progress_report(bool finished) /* Calculate current percentage of size done */ percent = total_size ? (int) ((current_size) * 100 / total_size) : 0; - fprintf(stderr, _("%lld/%lld MB (%d%%) computed"), - (long long) (current_size / (1024 * 1024)), - (long long) (total_size / (1024 * 1024)), + fprintf(stderr, _("%" PRId64 "/%" PRId64 " MB (%d%%) computed"), + (current_size / (1024 * 1024)), + (total_size / (1024 * 1024)), percent); /* @@ -603,11 +603,11 @@ main(int argc, char *argv[]) progress_report(true); printf(_("Checksum operation completed\n")); - printf(_("Files scanned: %lld\n"), (long long) files_scanned); - printf(_("Blocks scanned: %lld\n"), (long long) blocks_scanned); + printf(_("Files scanned: %" PRId64 "\n"), files_scanned); + printf(_("Blocks scanned: %" PRId64 "\n"), blocks_scanned); if (mode == PG_MODE_CHECK) { - printf(_("Bad checksums: %lld\n"), (long long) badblocks); + printf(_("Bad checksums: %" PRId64 "\n"), badblocks); printf(_("Data checksum version: %u\n"), ControlFile->data_checksum_version); if (badblocks > 0) @@ -615,8 +615,8 @@ main(int argc, char *argv[]) } else if (mode == PG_MODE_ENABLE) { - printf(_("Files written: %lld\n"), (long long) files_written); - printf(_("Blocks written: %lld\n"), (long long) blocks_written); + printf(_("Files written: %" PRId64 "\n"), files_written); + printf(_("Blocks written: %" PRId64 "\n"), blocks_written); } } diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c index 54adb5a41d2..d347e2122bd 100644 --- a/src/bin/pg_combinebackup/load_manifest.c +++ b/src/bin/pg_combinebackup/load_manifest.c @@ -160,8 +160,8 @@ load_backup_manifest(char *backup_directory) if (rc < 0) pg_fatal("could not read file \"%s\": %m", pathname); else - pg_fatal("could not read file \"%s\": read %d of %lld", - pathname, rc, (long long int) statbuf.st_size); + pg_fatal("could not read file \"%s\": read %d of %" PRId64, + pathname, rc, (pgoff_t) statbuf.st_size); } /* Close the manifest file. */ @@ -198,10 +198,10 @@ load_backup_manifest(char *backup_directory) if (rc < 0) pg_fatal("could not read file \"%s\": %m", pathname); else - pg_fatal("could not read file \"%s\": read %lld of %lld", + pg_fatal("could not read file \"%s\": read %" PRId64 " of %" PRId64, pathname, - (long long int) (statbuf.st_size + rc - bytes_left), - (long long int) statbuf.st_size); + (pgoff_t) (statbuf.st_size + rc - bytes_left), + (pgoff_t) statbuf.st_size); } bytes_left -= rc; json_parse_manifest_incremental_chunk(inc_state, buffer, rc, bytes_left == 0); diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c index 5f1f62f1db6..a54f0dfbe4f 100644 --- a/src/bin/pg_combinebackup/pg_combinebackup.c +++ b/src/bin/pg_combinebackup/pg_combinebackup.c @@ -298,10 +298,10 @@ main(int argc, char *argv[]) controlpath = psprintf("%s/%s", prior_backup_dirs[i], "global/pg_control"); - pg_fatal("%s: manifest system identifier is %llu, but control file has %llu", + pg_fatal("%s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64, controlpath, - (unsigned long long) manifests[i]->system_identifier, - (unsigned long long) system_identifier); + manifests[i]->system_identifier, + system_identifier); } } @@ -622,9 +622,9 @@ check_control_files(int n_backups, char **backup_dirs) if (i == n_backups - 1) system_identifier = control_file->system_identifier; else if (system_identifier != control_file->system_identifier) - pg_fatal("%s: expected system identifier %llu, but found %llu", - controlpath, (unsigned long long) system_identifier, - (unsigned long long) control_file->system_identifier); + pg_fatal("%s: expected system identifier %" PRIu64 ", but found %" PRIu64, + controlpath, system_identifier, + control_file->system_identifier); /* * Detect checksum mismatches, but only if the last backup in the @@ -645,8 +645,7 @@ check_control_files(int n_backups, char **backup_dirs) * If debug output is enabled, make a note of the system identifier that * we found in all of the relevant control files. */ - pg_log_debug("system identifier is %llu", - (unsigned long long) system_identifier); + pg_log_debug("system identifier is %" PRIu64, system_identifier); /* * Warn the user if not all backups are in the same state with regards to @@ -1399,8 +1398,8 @@ slurp_file(int fd, char *filename, StringInfo buf, int maxlen) if (rb < 0) pg_fatal("could not read file \"%s\": %m", filename); else - pg_fatal("could not read file \"%s\": read %zd of %lld", - filename, rb, (long long int) st.st_size); + pg_fatal("could not read file \"%s\": read %zd of %" PRId64, + filename, rb, (pgoff_t) st.st_size); } /* Adjust buffer length for new data and restore trailing-\0 invariant */ diff --git a/src/bin/pg_combinebackup/reconstruct.c b/src/bin/pg_combinebackup/reconstruct.c index 37ae38b6108..6b0ea2b93ff 100644 --- a/src/bin/pg_combinebackup/reconstruct.c +++ b/src/bin/pg_combinebackup/reconstruct.c @@ -420,10 +420,10 @@ debug_reconstruction(int n_source, rfile **sources, bool dry_run) if (fstat(s->fd, &sb) < 0) pg_fatal("could not stat file \"%s\": %m", s->filename); if (sb.st_size < s->highest_offset_read) - pg_fatal("file \"%s\" is too short: expected %llu, found %llu", + pg_fatal("file \"%s\" is too short: expected %" PRIu64 ", found %" PRIu64, s->filename, - (unsigned long long) s->highest_offset_read, - (unsigned long long) sb.st_size); + (pgoff_t) s->highest_offset_read, + (pgoff_t) sb.st_size); } } } @@ -783,7 +783,7 @@ read_block(rfile *s, off_t off, uint8 *buffer) if (rb < 0) pg_fatal("could not read from file \"%s\": %m", s->filename); else - pg_fatal("could not read from file \"%s\", offset %llu: read %d of %d", - s->filename, (unsigned long long) off, rb, BLCKSZ); + pg_fatal("could not read from file \"%s\", offset %" PRIu64 ": read %d of %d", + s->filename, (uint64) off, rb, BLCKSZ); } } diff --git a/src/bin/pg_combinebackup/write_manifest.c b/src/bin/pg_combinebackup/write_manifest.c index 6fea07e7c64..871a3ef4dff 100644 --- a/src/bin/pg_combinebackup/write_manifest.c +++ b/src/bin/pg_combinebackup/write_manifest.c @@ -104,8 +104,7 @@ add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path, appendStringInfoString(&mwriter->buf, "\", "); } - appendStringInfo(&mwriter->buf, "\"Size\": %llu, ", - (unsigned long long) size); + appendStringInfo(&mwriter->buf, "\"Size\": %" PRIu64 ", ", size); appendStringInfoString(&mwriter->buf, "\"Last-Modified\": \""); enlargeStringInfo(&mwriter->buf, 128); diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c index 93a05d80ca7..5a0faafe130 100644 --- a/src/bin/pg_controldata/pg_controldata.c +++ b/src/bin/pg_controldata/pg_controldata.c @@ -228,8 +228,8 @@ main(int argc, char *argv[]) ControlFile->pg_control_version); printf(_("Catalog version number: %u\n"), ControlFile->catalog_version_no); - printf(_("Database system identifier: %llu\n"), - (unsigned long long) ControlFile->system_identifier); + printf(_("Database system identifier: %" PRIu64 "\n"), + ControlFile->system_identifier); printf(_("Database cluster state: %s\n"), dbState(ControlFile->state)); printf(_("pg_control last modified: %s\n"), diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index b5ba3b46dd9..22a991bce6d 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -1048,8 +1048,8 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th) pg_fatal("could not close temporary file: %m"); if (len != th->fileLen) - pg_fatal("actual file length (%lld) does not match expected (%lld)", - (long long) len, (long long) th->fileLen); + pg_fatal("actual file length (%" PRId64 ") does not match expected (%" PRId64 ")", + len, th->fileLen); pad = tarPaddingBytesRequired(len); for (i = 0; i < pad; i++) @@ -1079,14 +1079,14 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename) /* Go to end of current file, if any */ if (ctx->tarFHpos != 0) { - pg_log_debug("moving from position %lld to next member at file position %lld", - (long long) ctx->tarFHpos, (long long) ctx->tarNextMember); + pg_log_debug("moving from position %" PRId64 " to next member at file position %" PRId64, + ctx->tarFHpos, ctx->tarNextMember); while (ctx->tarFHpos < ctx->tarNextMember) _tarReadRaw(AH, &c, 1, NULL, ctx->tarFH); } - pg_log_debug("now at file position %lld", (long long) ctx->tarFHpos); + pg_log_debug("now at file position %" PRId64, ctx->tarFHpos); /* We are at the start of the file, or at the next member */ @@ -1194,12 +1194,12 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) len = read_tar_number(&h[TAR_OFFSET_SIZE], 12); - pg_log_debug("TOC Entry %s at %llu (length %llu, checksum %d)", - tag, (unsigned long long) hPos, (unsigned long long) len, sum); + pg_log_debug("TOC Entry %s at %" PRIu64 " (length %" PRIu64 ", checksum %d)", + tag, hPos, len, sum); if (chk != sum) - pg_fatal("corrupt tar header found in %s (expected %d, computed %d) file position %llu", - tag, sum, chk, (unsigned long long) ftello(ctx->tarFH)); + pg_fatal("corrupt tar header found in %s (expected %d, computed %d) file position %" PRIu64, + tag, sum, chk, ftello(ctx->tarFH)); th->targetFile = pg_strdup(tag); th->fileLen = len; diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index e9dcb5a6d89..2173964c445 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -724,8 +724,8 @@ PrintControlValues(bool guessed) ControlFile.pg_control_version); printf(_("Catalog version number: %u\n"), ControlFile.catalog_version_no); - printf(_("Database system identifier: %llu\n"), - (unsigned long long) ControlFile.system_identifier); + printf(_("Database system identifier: %" PRIu64 "\n"), + ControlFile.system_identifier); printf(_("Latest checkpoint's TimeLineID: %u\n"), ControlFile.checkPointCopy.ThisTimeLineID); printf(_("Latest checkpoint's full_page_writes: %s\n"), diff --git a/src/bin/pg_rewind/libpq_source.c b/src/bin/pg_rewind/libpq_source.c index 62610a4efaf..bcfdba14c89 100644 --- a/src/bin/pg_rewind/libpq_source.c +++ b/src/bin/pg_rewind/libpq_source.c @@ -567,8 +567,8 @@ process_queued_fetch_requests(libpq_source *src) } else { - pg_log_debug("received chunk for file \"%s\", offset %lld, size %d", - filename, (long long int) chunkoff, chunksize); + pg_log_debug("received chunk for file \"%s\", offset %" PRId64 ", size %d", + filename, chunkoff, chunksize); if (strcmp(filename, rq->path) != 0) { @@ -576,8 +576,8 @@ process_queued_fetch_requests(libpq_source *src) filename, rq->path); } if (chunkoff != rq->offset) - pg_fatal("received data at offset %lld of file \"%s\", when requested for offset %lld", - (long long int) chunkoff, rq->path, (long long int) rq->offset); + pg_fatal("received data at offset %" PRId64 " of file \"%s\", when requested for offset %" PRId64, + chunkoff, rq->path, (pgoff_t) rq->offset); /* * We should not receive more data than we requested, or diff --git a/src/bin/pg_verifybackup/astreamer_verify.c b/src/bin/pg_verifybackup/astreamer_verify.c index a442b2849fc..8de612b432c 100644 --- a/src/bin/pg_verifybackup/astreamer_verify.c +++ b/src/bin/pg_verifybackup/astreamer_verify.c @@ -207,11 +207,11 @@ member_verify_header(astreamer *streamer, astreamer_member *member) if (m->size != member->size) { report_backup_error(mystreamer->context, - "\"%s\" has size %llu in \"%s\" but size %llu in the manifest", + "\"%s\" has size %" PRId64 " in \"%s\" but size %" PRId64 " in the manifest", member->pathname, - (unsigned long long) member->size, + member->size, mystreamer->archive_name, - (unsigned long long) m->size); + m->size); m->bad = true; return; } @@ -296,10 +296,10 @@ member_verify_checksum(astreamer *streamer) if (mystreamer->checksum_bytes != m->size) { report_backup_error(mystreamer->context, - "file \"%s\" in \"%s\" should contain %llu bytes, but read %llu bytes", + "file \"%s\" in \"%s\" should contain %" PRId64 " bytes, but read %" PRIu64 " bytes", m->pathname, mystreamer->archive_name, - (unsigned long long) m->size, - (unsigned long long) mystreamer->checksum_bytes); + m->size, + mystreamer->checksum_bytes); return; } @@ -408,11 +408,11 @@ member_verify_control_data(astreamer *streamer) /* System identifiers should match. */ if (manifest->system_identifier != mystreamer->control_file.system_identifier) - report_fatal_error("%s: %s: manifest system identifier is %llu, but control file has %llu", + report_fatal_error("%s: %s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64, mystreamer->archive_name, mystreamer->mfile->pathname, - (unsigned long long) manifest->system_identifier, - (unsigned long long) mystreamer->control_file.system_identifier); + manifest->system_identifier, + mystreamer->control_file.system_identifier); } /* diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c index 0719cb89783..6b9368b2d25 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -438,8 +438,8 @@ parse_manifest_file(char *manifest_path) if (rc < 0) pg_fatal("could not read file \"%s\": %m", manifest_path); else - pg_fatal("could not read file \"%s\": read %d of %lld", - manifest_path, rc, (long long int) statbuf.st_size); + pg_fatal("could not read file \"%s\": read %d of %" PRId64, + manifest_path, rc, (pgoff_t) statbuf.st_size); } /* Close the manifest file. */ @@ -476,10 +476,10 @@ parse_manifest_file(char *manifest_path) if (rc < 0) pg_fatal("could not read file \"%s\": %m", manifest_path); else - pg_fatal("could not read file \"%s\": read %lld of %lld", + pg_fatal("could not read file \"%s\": read %" PRId64 " of %" PRId64, manifest_path, - (long long int) (statbuf.st_size + rc - bytes_left), - (long long int) statbuf.st_size); + (pgoff_t) (statbuf.st_size + rc - bytes_left), + (pgoff_t) statbuf.st_size); } bytes_left -= rc; json_parse_manifest_incremental_chunk(inc_state, buffer, rc, @@ -719,9 +719,9 @@ verify_plain_backup_file(verifier_context *context, char *relpath, if (m->size != sb.st_size) { report_backup_error(context, - "\"%s\" has size %llu on disk but size %llu in the manifest", - relpath, (unsigned long long) sb.st_size, - (unsigned long long) m->size); + "\"%s\" has size %" PRId64 " on disk but size %" PRId64 " in the manifest", + relpath, (pgoff_t) sb.st_size, + m->size); m->bad = true; } @@ -770,10 +770,10 @@ verify_control_file(const char *controlpath, uint64 manifest_system_identifier) /* System identifiers should match. */ if (manifest_system_identifier != control_file->system_identifier) - report_fatal_error("%s: manifest system identifier is %llu, but control file has %llu", + report_fatal_error("%s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64, controlpath, - (unsigned long long) manifest_system_identifier, - (unsigned long long) control_file->system_identifier); + manifest_system_identifier, + control_file->system_identifier); /* Release memory. */ pfree(control_file); @@ -1165,9 +1165,8 @@ verify_file_checksum(verifier_context *context, manifest_file *m, if (bytes_read != m->size) { report_backup_error(context, - "file \"%s\" should contain %llu bytes, but read %llu bytes", - relpath, (unsigned long long) m->size, - (unsigned long long) bytes_read); + "file \"%s\" should contain %" PRIu64 " bytes, but read %" PRIu64, + relpath, m->size, bytes_read); return; } diff --git a/src/fe_utils/archive.c b/src/fe_utils/archive.c index f194809d53b..0a1cc2c1bc8 100644 --- a/src/fe_utils/archive.c +++ b/src/fe_utils/archive.c @@ -66,9 +66,9 @@ RestoreArchivedFile(const char *path, const char *xlogfname, if (stat(xlogpath, &stat_buf) == 0) { if (expectedSize > 0 && stat_buf.st_size != expectedSize) - pg_fatal("unexpected file size for \"%s\": %lld instead of %lld", - xlogfname, (long long int) stat_buf.st_size, - (long long int) expectedSize); + pg_fatal("unexpected file size for \"%s\": %" PRId64 " instead of %" PRId64, + xlogfname, (pgoff_t) stat_buf.st_size, + (pgoff_t) expectedSize); else { int xlogfd = open(xlogpath, O_RDONLY | PG_BINARY, 0); diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c index d6c4d78f981..3613daf35be 100644 --- a/src/fe_utils/print.c +++ b/src/fe_utils/print.c @@ -3185,9 +3185,9 @@ printTableInit(printTableContent *const content, const printTableOpt *opt, /* Catch possible overflow. Using >= here allows adding 1 below */ if (total_cells >= SIZE_MAX / sizeof(*content->cells)) { - fprintf(stderr, _("Cannot print table contents: number of cells %lld is equal to or exceeds maximum %lld.\n"), - (long long int) total_cells, - (long long int) (SIZE_MAX / sizeof(*content->cells))); + fprintf(stderr, _("Cannot print table contents: number of cells %" PRId64 " is equal to or exceeds maximum %zd.\n"), + total_cells, + SIZE_MAX / sizeof(*content->cells)); exit(EXIT_FAILURE); } content->cells = pg_malloc0((total_cells + 1) * sizeof(*content->cells)); @@ -3269,8 +3269,8 @@ printTableAddCell(printTableContent *const content, char *cell, total_cells = (uint64) content->ncolumns * content->nrows; if (content->cellsadded >= total_cells) { - fprintf(stderr, _("Cannot add cell to table content: total cell count of %lld exceeded.\n"), - (long long int) total_cells); + fprintf(stderr, _("Cannot add cell to table content: total cell count of %" PRIu64 " exceeded.\n"), + total_cells); exit(EXIT_FAILURE); } diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h index 88bf695e3f3..480b18ce876 100644 --- a/src/include/lib/radixtree.h +++ b/src/include/lib/radixtree.h @@ -2782,7 +2782,7 @@ RT_SCOPE void RT_STATS(RT_RADIX_TREE * tree) { fprintf(stderr, "max_val = " UINT64_FORMAT "\n", tree->ctl->max_val); - fprintf(stderr, "num_keys = %lld\n", (long long) tree->ctl->num_keys); + fprintf(stderr, "num_keys = %" PRId64 "\n", tree->ctl->num_keys); #ifdef RT_SHMEM fprintf(stderr, "handle = " DSA_POINTER_FORMAT "\n", tree->ctl->handle); @@ -2794,10 +2794,10 @@ RT_STATS(RT_RADIX_TREE * tree) { RT_SIZE_CLASS_ELEM size_class = RT_SIZE_CLASS_INFO[i]; - fprintf(stderr, ", n%d = %lld", size_class.fanout, (long long) tree->ctl->num_nodes[i]); + fprintf(stderr, ", n%d = %" PRId64, size_class.fanout, tree->ctl->num_nodes[i]); } - fprintf(stderr, ", leaves = %lld", (long long) tree->ctl->num_leaves); + fprintf(stderr, ", leaves = %" PRId64, tree->ctl->num_leaves); fprintf(stderr, "\n"); } diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index 1323e4c598d..91b43dfe910 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -1186,7 +1186,7 @@ test_pipelined_insert(PGconn *conn, int n_rows) { snprintf(insert_param_0, MAXINTLEN, "%d", rows_to_send); /* use up some buffer space with a wide value */ - snprintf(insert_param_1, MAXINT8LEN, "%lld", 1LL << 62); + snprintf(insert_param_1, MAXINT8LEN, "%" PRId64, UINT64_C(1) << 62); if (PQsendQueryPrepared(conn, "my_insert", 2, insert_params, NULL, NULL, 0) == 1) diff --git a/src/test/modules/test_copy_callbacks/test_copy_callbacks.c b/src/test/modules/test_copy_callbacks/test_copy_callbacks.c index 0bbd2aa6bb9..96baa710fea 100644 --- a/src/test/modules/test_copy_callbacks/test_copy_callbacks.c +++ b/src/test/modules/test_copy_callbacks/test_copy_callbacks.c @@ -42,8 +42,8 @@ test_copy_to_callback(PG_FUNCTION_ARGS) processed = DoCopyTo(cstate); EndCopyTo(cstate); - ereport(NOTICE, (errmsg("COPY TO callback has processed %lld rows", - (long long) processed))); + ereport(NOTICE, (errmsg("COPY TO callback has processed %" PRId64 " rows", + processed))); table_close(rel, NoLock); diff --git a/src/test/modules/test_slru/test_slru.c b/src/test/modules/test_slru/test_slru.c index d227b067034..c53d9d061b0 100644 --- a/src/test/modules/test_slru/test_slru.c +++ b/src/test/modules/test_slru/test_slru.c @@ -151,8 +151,8 @@ test_slru_page_sync(PG_FUNCTION_ARGS) ftag.segno = pageno / SLRU_PAGES_PER_SEGMENT; SlruSyncFileTag(TestSlruCtl, &ftag, path); - elog(NOTICE, "Called SlruSyncFileTag() for segment %lld on path %s", - (long long) ftag.segno, path); + elog(NOTICE, "Called SlruSyncFileTag() for segment %" PRId64 " on path %s", + ftag.segno, path); PG_RETURN_VOID(); } @@ -166,8 +166,8 @@ test_slru_page_delete(PG_FUNCTION_ARGS) ftag.segno = pageno / SLRU_PAGES_PER_SEGMENT; SlruDeleteSegment(TestSlruCtl, ftag.segno); - elog(NOTICE, "Called SlruDeleteSegment() for segment %lld", - (long long) ftag.segno); + elog(NOTICE, "Called SlruDeleteSegment() for segment %" PRId64, + ftag.segno); PG_RETURN_VOID(); } diff --git a/src/test/modules/xid_wraparound/xid_wraparound.c b/src/test/modules/xid_wraparound/xid_wraparound.c index dce81c0c6d6..4846bc01ecf 100644 --- a/src/test/modules/xid_wraparound/xid_wraparound.c +++ b/src/test/modules/xid_wraparound/xid_wraparound.c @@ -35,7 +35,7 @@ consume_xids(PG_FUNCTION_ARGS) FullTransactionId lastxid; if (nxids < 0) - elog(ERROR, "invalid nxids argument: %lld", (long long) nxids); + elog(ERROR, "invalid nxids argument: %" PRId64, nxids); if (nxids == 0) lastxid = ReadNextFullTransactionId(); @@ -56,8 +56,8 @@ consume_xids_until(PG_FUNCTION_ARGS) FullTransactionId lastxid; if (!FullTransactionIdIsNormal(targetxid)) - elog(ERROR, "targetxid %llu is not normal", - (unsigned long long) U64FromFullTransactionId(targetxid)); + elog(ERROR, "targetxid %" PRIu64 " is not normal", + U64FromFullTransactionId(targetxid)); lastxid = consume_xids_common(targetxid, 0); @@ -136,8 +136,8 @@ consume_xids_common(FullTransactionId untilxid, uint64 nxids) if (consumed - last_reported_at >= REPORT_INTERVAL) { if (nxids > 0) - elog(NOTICE, "consumed %llu / %llu XIDs, latest %u:%u", - (unsigned long long) consumed, (unsigned long long) nxids, + elog(NOTICE, "consumed %" PRIu64 " / %" PRIu64 " XIDs, latest %u:%u", + consumed, nxids, EpochFromFullTransactionId(lastxid), XidFromFullTransactionId(lastxid)); else -- 2.39.5
From 3155d31e12b4301cce738ceeaebe8fc8b3aba282 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Fri, 6 Dec 2024 08:46:34 +1300 Subject: [PATCH 2/4] pgbench: Make set_random_seed() 64-bit everywhere. Delete an intermediate variable, a redundant cast, a use of long and a use of long long. scanf() the seed directly into a uint64, now that we can do that with SCNu64 from <inttypes.h>. The previous coding was from pre-C99 times when %lld might not have been there, so it was reading into an unsigned long. Therefore behavior varied by OS, and --random-seed would accept either 32 or 64 bit seeds. Now it's the same everywhere. --- src/bin/pgbench/pgbench.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index c4c38099c5b..d1a802c5e6b 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -6611,27 +6611,23 @@ set_random_seed(const char *seed) } else { - /* parse unsigned-int seed value */ - unsigned long ulseed; char garbage; - /* Don't try to use UINT64_FORMAT here; it might not work for sscanf */ - if (sscanf(seed, "%lu%c", &ulseed, &garbage) != 1) + if (sscanf(seed, "%" SCNu64 "%c", &iseed, &garbage) != 1) { pg_log_error("unrecognized random seed option \"%s\"", seed); pg_log_error_detail("Expecting an unsigned integer, \"time\" or \"rand\"."); return false; } - iseed = (uint64) ulseed; } if (seed != NULL) - pg_log_info("setting random seed to %llu", (unsigned long long) iseed); + pg_log_info("setting random seed to %" PRIu64, iseed); random_seed = iseed; /* Initialize base_random_sequence using seed */ - pg_prng_seed(&base_random_sequence, (uint64) iseed); + pg_prng_seed(&base_random_sequence, iseed); return true; } -- 2.39.5
From 4e997fcf86d0f454371f9efe17e20d5741e2daf9 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Fri, 6 Dec 2024 09:09:53 +1300 Subject: [PATCH 3/4] pgbench: Rationalize types in parseScriptWeight(). This function wanted to parse a 64 bit number, but complain if it was out of range for int, and then include the number in the error message. OK, but long is not always bigger than int, so it won't work the same on all systems (and the cast to long long in the error message won't really make it longer). Parse with strtoi64(), and print it out with PRId64, so now it will behave the same everywhere. --- src/bin/pgbench/pgbench.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index d1a802c5e6b..d4736fe5117 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -6173,7 +6173,7 @@ parseScriptWeight(const char *option, char **script) if ((sep = strrchr(option, WSEP))) { int namelen = sep - option; - long wtmp; + int64 wtmp; char *badp; /* generate the script name */ @@ -6183,12 +6183,12 @@ parseScriptWeight(const char *option, char **script) /* process digits of the weight spec */ errno = 0; - wtmp = strtol(sep + 1, &badp, 10); + wtmp = strtoi64(sep + 1, &badp, 10); if (errno != 0 || badp == sep + 1 || *badp != '\0') pg_fatal("invalid weight specification: %s", sep); if (wtmp > INT_MAX || wtmp < 0) - pg_fatal("weight specification out of range (0 .. %d): %lld", - INT_MAX, (long long) wtmp); + pg_fatal("weight specification out of range (0 .. %d): %" PRId64, + INT_MAX, wtmp); weight = wtmp; } else -- 2.39.5
From 9f543ffdd916f54822fb6bd9f66e5963d735f6d2 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Fri, 6 Dec 2024 09:31:16 +1300 Subject: [PATCH 4/4] pgbench: Modernize integer parsing routine. strtoint64() is from pre-C99 times and had comments about scanf() not being sure to handle long long. Even though C99 scanf() can do SCNi64, it seems like we'd lose a bit of error reporting. A more obvious modern drop-in is strtoi64(). Then strtoint64() can log the same errors as before. --- src/bin/pgbench/pgbench.c | 72 ++++++--------------------------------- 1 file changed, 11 insertions(+), 61 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index d4736fe5117..37a53a7474e 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -977,9 +977,6 @@ is_an_int(const char *str) /* * strtoint64 -- convert a string to 64-bit integer * - * This function is a slightly modified version of pg_strtoint64() from - * src/backend/utils/adt/numutils.c. - * * The function returns whether the conversion worked, and if so * "*result" is set to the result. * @@ -988,71 +985,24 @@ is_an_int(const char *str) bool strtoint64(const char *str, bool errorOK, int64 *result) { - const char *ptr = str; - int64 tmp = 0; - bool neg = false; - - /* - * Do our own scan, rather than relying on sscanf which might be broken - * for long long. - * - * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate - * value as a negative number. - */ + char *end; - /* skip leading spaces */ - while (*ptr && isspace((unsigned char) *ptr)) - ptr++; + errno = 0; + *result = strtoi64(str, &end, 10); - /* handle sign */ - if (*ptr == '-') + if (errno == ERANGE) { - ptr++; - neg = true; - } - else if (*ptr == '+') - ptr++; - - /* require at least one digit */ - if (unlikely(!isdigit((unsigned char) *ptr))) - goto invalid_syntax; - - /* process digits */ - while (*ptr && isdigit((unsigned char) *ptr)) - { - int8 digit = (*ptr++ - '0'); - - if (unlikely(pg_mul_s64_overflow(tmp, 10, &tmp)) || - unlikely(pg_sub_s64_overflow(tmp, digit, &tmp))) - goto out_of_range; + if (!errorOK) + pg_log_error("value \"%s\" is out of range for type bigint", str); + return false; } - - /* allow trailing whitespace, but not other trailing chars */ - while (*ptr != '\0' && isspace((unsigned char) *ptr)) - ptr++; - - if (unlikely(*ptr != '\0')) - goto invalid_syntax; - - if (!neg) + if (str == end || *end != '\0') { - if (unlikely(tmp == PG_INT64_MIN)) - goto out_of_range; - tmp = -tmp; + if (!errorOK) + pg_log_error("invalid input syntax for type bigint: \"%s\"", str); + return false; } - - *result = tmp; return true; - -out_of_range: - if (!errorOK) - pg_log_error("value \"%s\" is out of range for type bigint", str); - return false; - -invalid_syntax: - if (!errorOK) - pg_log_error("invalid input syntax for type bigint: \"%s\"", str); - return false; } /* convert string to double, detecting overflows/underflows */ -- 2.39.5