mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Allow use of "z" flag in our printf calls, and use it where appropriate.
Since C99, it's been standard for printf and friends to accept a "z" size modifier, meaning "whatever size size_t has". Up to now we've generally dealt with printing size_t values by explicitly casting them to unsigned long and using the "l" modifier; but this is really the wrong thing on platforms where pointers are wider than longs (such as Win64). So let's start using "z" instead. To ensure we can do that on all platforms, teach src/port/snprintf.c to understand "z", and add a configure test to force use of that implementation when the platform's version doesn't handle "z". Having done that, modify a bunch of places that were using the unsigned-long hack to use "z" instead. This patch doesn't pretend to have gotten everyplace that could benefit, but it catches many of them. I made an effort in particular to ensure that all uses of the same error message text were updated together, so as not to increase the number of translatable strings. It's possible that this change will result in format-string warnings from pre-C99 compilers. We might have to reconsider if there are any popular compilers that will warn about this; but let's start by seeing what the buildfarm thinks. Andres Freund, with a little additional work by me
This commit is contained in:
@@ -676,8 +676,7 @@ AllocSetAlloc(MemoryContext context, Size size)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory"),
|
||||
errdetail("Failed on request of size %lu.",
|
||||
(unsigned long) size)));
|
||||
errdetail("Failed on request of size %zu.", size)));
|
||||
}
|
||||
block->aset = set;
|
||||
block->freeptr = block->endptr = ((char *) block) + blksize;
|
||||
@@ -871,8 +870,7 @@ AllocSetAlloc(MemoryContext context, Size size)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory"),
|
||||
errdetail("Failed on request of size %lu.",
|
||||
(unsigned long) size)));
|
||||
errdetail("Failed on request of size %zu.", size)));
|
||||
}
|
||||
|
||||
block->aset = set;
|
||||
@@ -1114,8 +1112,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory"),
|
||||
errdetail("Failed on request of size %lu.",
|
||||
(unsigned long) size)));
|
||||
errdetail("Failed on request of size %zu.", size)));
|
||||
}
|
||||
block->freeptr = block->endptr = ((char *) block) + blksize;
|
||||
|
||||
@@ -1245,10 +1242,10 @@ static void
|
||||
AllocSetStats(MemoryContext context, int level)
|
||||
{
|
||||
AllocSet set = (AllocSet) context;
|
||||
long nblocks = 0;
|
||||
long nchunks = 0;
|
||||
long totalspace = 0;
|
||||
long freespace = 0;
|
||||
Size nblocks = 0;
|
||||
Size nchunks = 0;
|
||||
Size totalspace = 0;
|
||||
Size freespace = 0;
|
||||
AllocBlock block;
|
||||
AllocChunk chunk;
|
||||
int fidx;
|
||||
@@ -1274,7 +1271,7 @@ AllocSetStats(MemoryContext context, int level)
|
||||
fprintf(stderr, " ");
|
||||
|
||||
fprintf(stderr,
|
||||
"%s: %lu total in %ld blocks; %lu free (%ld chunks); %lu used\n",
|
||||
"%s: %zu total in %zd blocks; %zu free (%zd chunks); %zu used\n",
|
||||
set->header.name, totalspace, nblocks, freespace, nchunks,
|
||||
totalspace - freespace);
|
||||
}
|
||||
@@ -1338,8 +1335,8 @@ AllocSetCheck(MemoryContext context)
|
||||
elog(WARNING, "problem in alloc set %s: req size > alloc size for chunk %p in block %p",
|
||||
name, chunk, block);
|
||||
if (chsize < (1 << ALLOC_MINBITS))
|
||||
elog(WARNING, "problem in alloc set %s: bad size %lu for chunk %p in block %p",
|
||||
name, (unsigned long) chsize, chunk, block);
|
||||
elog(WARNING, "problem in alloc set %s: bad size %zu for chunk %p in block %p",
|
||||
name, chsize, chunk, block);
|
||||
|
||||
/* single-chunk block? */
|
||||
if (chsize > set->allocChunkLimit &&
|
||||
|
||||
Reference in New Issue
Block a user