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:
Tom Lane 2014-01-23 17:18:23 -05:00
parent ec8f692c3c
commit ac4ef637ad
27 changed files with 221 additions and 125 deletions

View File

@ -273,16 +273,16 @@ case $pgac_cv_snprintf_long_long_int_format in
esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
# PGAC_FUNC_PRINTF_ARG_CONTROL # PGAC_FUNC_SNPRINTF_ARG_CONTROL
# --------------------------------------- # ---------------------------------------
# Determine if printf supports %1$ argument selection, e.g. %5$ selects # Determine if snprintf supports %1$ argument selection, e.g. %5$ selects
# the fifth argument after the printf print string. # the fifth argument after the printf format string.
# This is not in the C99 standard, but in the Single Unix Specification (SUS). # This is not in the C99 standard, but in the Single Unix Specification (SUS).
# It is used in our language translation strings. # It is used in our language translation strings.
# #
AC_DEFUN([PGAC_FUNC_PRINTF_ARG_CONTROL], AC_DEFUN([PGAC_FUNC_SNPRINTF_ARG_CONTROL],
[AC_MSG_CHECKING([whether printf supports argument control]) [AC_MSG_CHECKING([whether snprintf supports argument control])
AC_CACHE_VAL(pgac_cv_printf_arg_control, AC_CACHE_VAL(pgac_cv_snprintf_arg_control,
[AC_TRY_RUN([#include <stdio.h> [AC_TRY_RUN([#include <stdio.h>
#include <string.h> #include <string.h>
@ -296,12 +296,48 @@ int main()
return 1; return 1;
return 0; return 0;
}], }],
[pgac_cv_printf_arg_control=yes], [pgac_cv_snprintf_arg_control=yes],
[pgac_cv_printf_arg_control=no], [pgac_cv_snprintf_arg_control=no],
[pgac_cv_printf_arg_control=cross]) [pgac_cv_snprintf_arg_control=cross])
])dnl AC_CACHE_VAL ])dnl AC_CACHE_VAL
AC_MSG_RESULT([$pgac_cv_printf_arg_control]) AC_MSG_RESULT([$pgac_cv_snprintf_arg_control])
])# PGAC_FUNC_PRINTF_ARG_CONTROL ])# PGAC_FUNC_SNPRINTF_ARG_CONTROL
# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
# ---------------------------------------
# Determine if snprintf supports the z length modifier for printing
# size_t-sized variables. That's supported by C99 and POSIX but not
# all platforms play ball, so we must test whether it's working.
#
AC_DEFUN([PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT],
[AC_MSG_CHECKING([whether snprintf supports the %z modifier])
AC_CACHE_VAL(pgac_cv_snprintf_size_t_support,
[AC_TRY_RUN([#include <stdio.h>
#include <string.h>
int main()
{
char bufz[100];
char buf64[100];
/*
* Print the largest unsigned number fitting in a size_t using both %zu
* and the previously-determined format for 64-bit integers. Note that
* we don't run this code unless we know snprintf handles 64-bit ints.
*/
bufz[0] = '\0'; /* in case snprintf fails to emit anything */
snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
snprintf(buf64, sizeof(buf64), UINT64_FORMAT, (PG_INT64_TYPE) ~((size_t) 0));
if (strcmp(bufz, buf64) != 0)
return 1;
return 0;
}],
[pgac_cv_snprintf_size_t_support=yes],
[pgac_cv_snprintf_size_t_support=no],
[pgac_cv_snprintf_size_t_support=cross])
])dnl AC_CACHE_VAL
AC_MSG_RESULT([$pgac_cv_snprintf_size_t_support])
])# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
# PGAC_TYPE_LOCALE_T # PGAC_TYPE_LOCALE_T

70
configure vendored
View File

@ -12698,13 +12698,13 @@ fi
# Force use of our snprintf if system's doesn't do arg control # Force use of our snprintf if system's doesn't do arg control
# See comment above at snprintf test for details. # See comment above at snprintf test for details.
if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether printf supports argument control" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf supports argument control" >&5
$as_echo_n "checking whether printf supports argument control... " >&6; } $as_echo_n "checking whether snprintf supports argument control... " >&6; }
if ${pgac_cv_printf_arg_control+:} false; then : if ${pgac_cv_snprintf_arg_control+:} false; then :
$as_echo_n "(cached) " >&6 $as_echo_n "(cached) " >&6
else else
if test "$cross_compiling" = yes; then : if test "$cross_compiling" = yes; then :
pgac_cv_printf_arg_control=cross pgac_cv_snprintf_arg_control=cross
else else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@ -12723,9 +12723,9 @@ int main()
} }
_ACEOF _ACEOF
if ac_fn_c_try_run "$LINENO"; then : if ac_fn_c_try_run "$LINENO"; then :
pgac_cv_printf_arg_control=yes pgac_cv_snprintf_arg_control=yes
else else
pgac_cv_printf_arg_control=no pgac_cv_snprintf_arg_control=no
fi fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext conftest.$ac_objext conftest.beam conftest.$ac_ext
@ -12733,10 +12733,10 @@ fi
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_printf_arg_control" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_arg_control" >&5
$as_echo "$pgac_cv_printf_arg_control" >&6; } $as_echo "$pgac_cv_snprintf_arg_control" >&6; }
if test $pgac_cv_printf_arg_control != yes ; then if test $pgac_cv_snprintf_arg_control != yes ; then
pgac_need_repl_snprintf=yes pgac_need_repl_snprintf=yes
fi fi
fi fi
@ -13036,6 +13036,58 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
# Also force use of our snprintf if the system's doesn't support the %z flag.
if test "$pgac_need_repl_snprintf" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf supports the %z modifier" >&5
$as_echo_n "checking whether snprintf supports the %z modifier... " >&6; }
if ${pgac_cv_snprintf_size_t_support+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
pgac_cv_snprintf_size_t_support=cross
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdio.h>
#include <string.h>
int main()
{
char bufz[100];
char buf64[100];
/*
* Print the largest unsigned number fitting in a size_t using both %zu
* and the previously-determined format for 64-bit integers. Note that
* we don't run this code unless we know snprintf handles 64-bit ints.
*/
bufz[0] = '\0'; /* in case snprintf fails to emit anything */
snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
snprintf(buf64, sizeof(buf64), UINT64_FORMAT, (PG_INT64_TYPE) ~((size_t) 0));
if (strcmp(bufz, buf64) != 0)
return 1;
return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
pgac_cv_snprintf_size_t_support=yes
else
pgac_cv_snprintf_size_t_support=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_size_t_support" >&5
$as_echo "$pgac_cv_snprintf_size_t_support" >&6; }
if test "$pgac_cv_snprintf_size_t_support" != yes; then
pgac_need_repl_snprintf=yes
fi
fi
# Now we have checked all the reasons to replace snprintf # Now we have checked all the reasons to replace snprintf
if test $pgac_need_repl_snprintf = yes; then if test $pgac_need_repl_snprintf = yes; then

View File

@ -1533,8 +1533,8 @@ for the exact reason.]])],
# Force use of our snprintf if system's doesn't do arg control # Force use of our snprintf if system's doesn't do arg control
# See comment above at snprintf test for details. # See comment above at snprintf test for details.
if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
PGAC_FUNC_PRINTF_ARG_CONTROL PGAC_FUNC_SNPRINTF_ARG_CONTROL
if test $pgac_cv_printf_arg_control != yes ; then if test $pgac_cv_snprintf_arg_control != yes ; then
pgac_need_repl_snprintf=yes pgac_need_repl_snprintf=yes
fi fi
fi fi
@ -1617,6 +1617,14 @@ AC_DEFINE_UNQUOTED(INT64_FORMAT, $INT64_FORMAT,
AC_DEFINE_UNQUOTED(UINT64_FORMAT, $UINT64_FORMAT, AC_DEFINE_UNQUOTED(UINT64_FORMAT, $UINT64_FORMAT,
[Define to the appropriate snprintf format for unsigned 64-bit ints.]) [Define to the appropriate snprintf format for unsigned 64-bit ints.])
# Also force use of our snprintf if the system's doesn't support the %z flag.
if test "$pgac_need_repl_snprintf" = no; then
PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
if test "$pgac_cv_snprintf_size_t_support" != yes; then
pgac_need_repl_snprintf=yes
fi
fi
# Now we have checked all the reasons to replace snprintf # Now we have checked all the reasons to replace snprintf
if test $pgac_need_repl_snprintf = yes; then if test $pgac_need_repl_snprintf = yes; then
AC_DEFINE(USE_REPL_SNPRINTF, 1, [Use replacement snprintf() functions.]) AC_DEFINE(USE_REPL_SNPRINTF, 1, [Use replacement snprintf() functions.])

View File

@ -165,9 +165,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
if ((size & INDEX_SIZE_MASK) != size) if ((size & INDEX_SIZE_MASK) != size)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row requires %lu bytes, maximum size is %lu", errmsg("index row requires %zu bytes, maximum size is %zu",
(unsigned long) size, size, (Size) INDEX_SIZE_MASK)));
(unsigned long) INDEX_SIZE_MASK)));
infomask |= size; infomask |= size;

View File

@ -105,9 +105,8 @@ GinFormTuple(GinState *ginstate,
if (errorTooBig) if (errorTooBig)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
(unsigned long) newsize, (Size) newsize, (Size) GinMaxItemSize,
(unsigned long) GinMaxItemSize,
RelationGetRelationName(ginstate->index)))); RelationGetRelationName(ginstate->index))));
pfree(itup); pfree(itup);
return NULL; return NULL;

View File

@ -65,9 +65,8 @@ _hash_doinsert(Relation rel, IndexTuple itup)
if (itemsz > HashMaxItemSize((Page) metap)) if (itemsz > HashMaxItemSize((Page) metap))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds hash maximum %lu", errmsg("index row size %zu exceeds hash maximum %zu",
(unsigned long) itemsz, itemsz, HashMaxItemSize((Page) metap)),
(unsigned long) HashMaxItemSize((Page) metap)),
errhint("Values larger than a buffer page cannot be indexed."))); errhint("Values larger than a buffer page cannot be indexed.")));
/* /*

View File

@ -237,9 +237,8 @@ RelationGetBufferForTuple(Relation relation, Size len,
if (len > MaxHeapTupleSize) if (len > MaxHeapTupleSize)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("row is too big: size %lu, maximum size %lu", errmsg("row is too big: size %zu, maximum size %zu",
(unsigned long) len, len, MaxHeapTupleSize)));
(unsigned long) MaxHeapTupleSize)));
/* Compute desired extra freespace due to fillfactor option */ /* Compute desired extra freespace due to fillfactor option */
saveFreeSpace = RelationGetTargetPageFreeSpace(relation, saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
@ -477,7 +476,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
if (len > PageGetHeapFreeSpace(page)) if (len > PageGetHeapFreeSpace(page))
{ {
/* We should not get here given the test at the top */ /* We should not get here given the test at the top */
elog(PANIC, "tuple is too big: size %lu", (unsigned long) len); elog(PANIC, "tuple is too big: size %zu", len);
} }
/* /*

View File

@ -601,9 +601,8 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
if (len > MaxHeapTupleSize) if (len > MaxHeapTupleSize)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("row is too big: size %lu, maximum size %lu", errmsg("row is too big: size %zu, maximum size %zu",
(unsigned long) len, len, MaxHeapTupleSize)));
(unsigned long) MaxHeapTupleSize)));
/* Compute desired extra freespace due to fillfactor option */ /* Compute desired extra freespace due to fillfactor option */
saveFreeSpace = RelationGetTargetPageFreeSpace(state->rs_new_rel, saveFreeSpace = RelationGetTargetPageFreeSpace(state->rs_new_rel,

View File

@ -537,9 +537,8 @@ _bt_findinsertloc(Relation rel,
if (itemsz > BTMaxItemSize(page)) if (itemsz > BTMaxItemSize(page))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
(unsigned long) itemsz, itemsz, BTMaxItemSize(page),
(unsigned long) BTMaxItemSize(page),
RelationGetRelationName(rel)), RelationGetRelationName(rel)),
errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n" errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
"Consider a function index of an MD5 hash of the value, " "Consider a function index of an MD5 hash of the value, "

View File

@ -482,9 +482,8 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
if (itupsz > BTMaxItemSize(npage)) if (itupsz > BTMaxItemSize(npage))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
(unsigned long) itupsz, itupsz, BTMaxItemSize(npage),
(unsigned long) BTMaxItemSize(npage),
RelationGetRelationName(wstate->index)), RelationGetRelationName(wstate->index)),
errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n" errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
"Consider a function index of an MD5 hash of the value, " "Consider a function index of an MD5 hash of the value, "

View File

@ -1885,9 +1885,9 @@ spgdoinsert(Relation index, SpGistState *state,
if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK) if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
(unsigned long) (leafSize - sizeof(ItemIdData)), leafSize - sizeof(ItemIdData),
(unsigned long) (SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)), SPGIST_PAGE_CAPACITY - sizeof(ItemIdData),
RelationGetRelationName(index)), RelationGetRelationName(index)),
errhint("Values larger than a buffer page cannot be indexed."))); errhint("Values larger than a buffer page cannot be indexed.")));

View File

@ -602,9 +602,8 @@ spgFormNodeTuple(SpGistState *state, Datum label, bool isnull)
if ((size & INDEX_SIZE_MASK) != size) if ((size & INDEX_SIZE_MASK) != size)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row requires %lu bytes, maximum size is %lu", errmsg("index row requires %zu bytes, maximum size is %zu",
(unsigned long) size, (Size) size, (Size) INDEX_SIZE_MASK)));
(unsigned long) INDEX_SIZE_MASK)));
tup = (SpGistNodeTuple) palloc0(size); tup = (SpGistNodeTuple) palloc0(size);
@ -661,9 +660,9 @@ spgFormInnerTuple(SpGistState *state, bool hasPrefix, Datum prefix,
if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)) if (size > SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("SP-GiST inner tuple size %lu exceeds maximum %lu", errmsg("SP-GiST inner tuple size %zu exceeds maximum %zu",
(unsigned long) size, (Size) size,
(unsigned long) (SPGIST_PAGE_CAPACITY - sizeof(ItemIdData))), SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)),
errhint("Values larger than a buffer page cannot be indexed."))); errhint("Values larger than a buffer page cannot be indexed.")));
/* /*

View File

@ -2738,9 +2738,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
ereport(PANIC, ereport(PANIC,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not write to log file %s " errmsg("could not write to log file %s "
"at offset %u, length %lu: %m", "at offset %u, length %zu: %m",
XLogFileNameP(ThisTimeLineID, openLogSegNo), XLogFileNameP(ThisTimeLineID, openLogSegNo),
openLogOff, (unsigned long) nbytes))); openLogOff, nbytes)));
} }
nleft -= written; nleft -= written;
from += written; from += written;

View File

@ -1439,15 +1439,13 @@ readDatum(bool typbyval)
token = pg_strtok(&tokenLength); /* read the '[' */ token = pg_strtok(&tokenLength); /* read the '[' */
if (token == NULL || token[0] != '[') if (token == NULL || token[0] != '[')
elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu", elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
token ? (const char *) token : "[NULL]", token ? (const char *) token : "[NULL]", length);
(unsigned long) length);
if (typbyval) if (typbyval)
{ {
if (length > (Size) sizeof(Datum)) if (length > (Size) sizeof(Datum))
elog(ERROR, "byval datum but length = %lu", elog(ERROR, "byval datum but length = %zu", length);
(unsigned long) length);
res = (Datum) 0; res = (Datum) 0;
s = (char *) (&res); s = (char *) (&res);
for (i = 0; i < (Size) sizeof(Datum); i++) for (i = 0; i < (Size) sizeof(Datum); i++)
@ -1471,9 +1469,8 @@ readDatum(bool typbyval)
token = pg_strtok(&tokenLength); /* read the ']' */ token = pg_strtok(&tokenLength); /* read the ']' */
if (token == NULL || token[0] != ']') if (token == NULL || token[0] != ']')
elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu", elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
token ? (const char *) token : "[NULL]", token ? (const char *) token : "[NULL]", length);
(unsigned long) length);
return res; return res;
} }

View File

@ -138,8 +138,8 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
*/ */
ereport(FATAL, ereport(FATAL,
(errmsg("could not create shared memory segment: %m"), (errmsg("could not create shared memory segment: %m"),
errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).", errdetail("Failed system call was shmget(key=%lu, size=%zu, 0%o).",
(unsigned long) memKey, (unsigned long) size, (unsigned long) memKey, size,
IPC_CREAT | IPC_EXCL | IPCProtection), IPC_CREAT | IPC_EXCL | IPCProtection),
(errno == EINVAL) ? (errno == EINVAL) ?
errhint("This error usually means that PostgreSQL's request for a shared memory " errhint("This error usually means that PostgreSQL's request for a shared memory "
@ -395,10 +395,10 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
errhint("This error usually means that PostgreSQL's request " errhint("This error usually means that PostgreSQL's request "
"for a shared memory segment exceeded available memory " "for a shared memory segment exceeded available memory "
"or swap space. To reduce the request size (currently " "or swap space. To reduce the request size (currently "
"%lu bytes), reduce PostgreSQL's shared memory usage, " "%zu bytes), reduce PostgreSQL's shared memory usage, "
"perhaps by reducing shared_buffers or " "perhaps by reducing shared_buffers or "
"max_connections.", "max_connections.",
(unsigned long) size) : 0)); size) : 0));
AnonymousShmemSize = size; AnonymousShmemSize = size;
/* Now we need only allocate a minimal-sized SysV shmem block. */ /* Now we need only allocate a minimal-sized SysV shmem block. */

View File

@ -166,8 +166,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
if (!hmap) if (!hmap)
ereport(FATAL, ereport(FATAL,
(errmsg("could not create shared memory segment: error code %lu", GetLastError()), (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was CreateFileMapping(size=%lu, name=%s).", errdetail("Failed system call was CreateFileMapping(size=%zu, name=%s).",
(unsigned long) size, szShareMem))); size, szShareMem)));
/* /*
* If the segment already existed, CreateFileMapping() will return a * If the segment already existed, CreateFileMapping() will return a

View File

@ -829,7 +829,7 @@ AllocateVfd(void)
Index i; Index i;
File file; File file;
DO_DB(elog(LOG, "AllocateVfd. Size %lu", (unsigned long) SizeVfdCache)); DO_DB(elog(LOG, "AllocateVfd. Size %zu", SizeVfdCache));
Assert(SizeVfdCache > 0); /* InitFileAccess not called? */ Assert(SizeVfdCache > 0); /* InitFileAccess not called? */

View File

@ -379,8 +379,7 @@ fsm_space_needed_to_cat(Size needed)
/* Can't ask for more space than the highest category represents */ /* Can't ask for more space than the highest category represents */
if (needed > MaxFSMRequestSize) if (needed > MaxFSMRequestSize)
elog(ERROR, "invalid FSM request size %lu", elog(ERROR, "invalid FSM request size %zu", needed);
(unsigned long) needed);
if (needed == 0) if (needed == 0)
return 1; return 1;

View File

@ -201,8 +201,8 @@ dsm_postmaster_startup(void)
dsm_control = dsm_control_address; dsm_control = dsm_control_address;
on_shmem_exit(dsm_postmaster_shutdown, 0); on_shmem_exit(dsm_postmaster_shutdown, 0);
elog(DEBUG2, elog(DEBUG2,
"created dynamic shared memory control segment %u (%lu bytes)", "created dynamic shared memory control segment %u (%zu bytes)",
dsm_control_handle, (unsigned long) segsize); dsm_control_handle, segsize);
dsm_write_state_file(dsm_control_handle); dsm_write_state_file(dsm_control_handle);
/* Initialize control segment. */ /* Initialize control segment. */

View File

@ -329,8 +329,8 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel, ereport(elevel,
(errcode_for_dynamic_shared_memory(), (errcode_for_dynamic_shared_memory(),
errmsg("could not resize shared memory segment %s to %lu bytes: %m", errmsg("could not resize shared memory segment %s to %zu bytes: %m",
name, (unsigned long) request_size))); name, request_size)));
return false; return false;
} }
@ -871,8 +871,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel, ereport(elevel,
(errcode_for_dynamic_shared_memory(), (errcode_for_dynamic_shared_memory(),
errmsg("could not resize shared memory segment %s to %lu bytes: %m", errmsg("could not resize shared memory segment %s to %zu bytes: %m",
name, (unsigned long) request_size))); name, request_size)));
return false; return false;
} }
else if (*mapped_size < request_size) else if (*mapped_size < request_size)
@ -919,8 +919,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel, ereport(elevel,
(errcode_for_dynamic_shared_memory(), (errcode_for_dynamic_shared_memory(),
errmsg("could not resize shared memory segment %s to %lu bytes: %m", errmsg("could not resize shared memory segment %s to %zu bytes: %m",
name, (unsigned long) request_size))); name, request_size)));
return false; return false;
} }
} }

View File

@ -142,8 +142,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
/* might as well round it off to a multiple of a typical page size */ /* might as well round it off to a multiple of a typical page size */
size = add_size(size, 8192 - (size % 8192)); size = add_size(size, 8192 - (size % 8192));
elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)", elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
(unsigned long) size);
/* /*
* Create the shmem segment * Create the shmem segment

View File

@ -359,8 +359,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for data structure" errmsg("not enough shared memory for data structure"
" \"%s\" (%lu bytes requested)", " \"%s\" (%zu bytes requested)",
name, (unsigned long) size))); name, size)));
shmemseghdr->index = structPtr; shmemseghdr->index = structPtr;
*foundPtr = FALSE; *foundPtr = FALSE;
} }
@ -393,10 +393,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
LWLockRelease(ShmemIndexLock); LWLockRelease(ShmemIndexLock);
ereport(ERROR, ereport(ERROR,
(errmsg("ShmemIndex entry size is wrong for data structure" (errmsg("ShmemIndex entry size is wrong for data structure"
" \"%s\": expected %lu, actual %lu", " \"%s\": expected %zu, actual %zu",
name, name, size, result->size)));
(unsigned long) size,
(unsigned long) result->size)));
} }
structPtr = result->location; structPtr = result->location;
} }
@ -412,8 +410,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for data structure" errmsg("not enough shared memory for data structure"
" \"%s\" (%lu bytes requested)", " \"%s\" (%zu bytes requested)",
name, (unsigned long) size))); name, size)));
} }
result->size = size; result->size = size;
result->location = structPtr; result->location = structPtr;

View File

@ -1185,8 +1185,8 @@ InitPredicateLocks(void)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for elements of data structure" errmsg("not enough shared memory for elements of data structure"
" \"%s\" (%lu bytes requested)", " \"%s\" (%zu bytes requested)",
"PredXactList", (unsigned long) requestSize))); "PredXactList", requestSize)));
/* Add all elements to available list, clean. */ /* Add all elements to available list, clean. */
memset(PredXact->element, 0, requestSize); memset(PredXact->element, 0, requestSize);
for (i = 0; i < max_table_size; i++) for (i = 0; i < max_table_size; i++)
@ -1257,8 +1257,8 @@ InitPredicateLocks(void)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for elements of data structure" errmsg("not enough shared memory for elements of data structure"
" \"%s\" (%lu bytes requested)", " \"%s\" (%zu bytes requested)",
"RWConflictPool", (unsigned long) requestSize))); "RWConflictPool", requestSize)));
/* Add all elements to available list, clean. */ /* Add all elements to available list, clean. */
memset(RWConflictPool->element, 0, requestSize); memset(RWConflictPool->element, 0, requestSize);
for (i = 0; i < max_table_size; i++) for (i = 0; i < max_table_size; i++)

View File

@ -676,8 +676,7 @@ AllocSetAlloc(MemoryContext context, Size size)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"), errmsg("out of memory"),
errdetail("Failed on request of size %lu.", errdetail("Failed on request of size %zu.", size)));
(unsigned long) size)));
} }
block->aset = set; block->aset = set;
block->freeptr = block->endptr = ((char *) block) + blksize; block->freeptr = block->endptr = ((char *) block) + blksize;
@ -871,8 +870,7 @@ AllocSetAlloc(MemoryContext context, Size size)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"), errmsg("out of memory"),
errdetail("Failed on request of size %lu.", errdetail("Failed on request of size %zu.", size)));
(unsigned long) size)));
} }
block->aset = set; block->aset = set;
@ -1114,8 +1112,7 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"), errmsg("out of memory"),
errdetail("Failed on request of size %lu.", errdetail("Failed on request of size %zu.", size)));
(unsigned long) size)));
} }
block->freeptr = block->endptr = ((char *) block) + blksize; block->freeptr = block->endptr = ((char *) block) + blksize;
@ -1245,10 +1242,10 @@ static void
AllocSetStats(MemoryContext context, int level) AllocSetStats(MemoryContext context, int level)
{ {
AllocSet set = (AllocSet) context; AllocSet set = (AllocSet) context;
long nblocks = 0; Size nblocks = 0;
long nchunks = 0; Size nchunks = 0;
long totalspace = 0; Size totalspace = 0;
long freespace = 0; Size freespace = 0;
AllocBlock block; AllocBlock block;
AllocChunk chunk; AllocChunk chunk;
int fidx; int fidx;
@ -1274,7 +1271,7 @@ AllocSetStats(MemoryContext context, int level)
fprintf(stderr, " "); fprintf(stderr, " ");
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, set->header.name, totalspace, nblocks, freespace, nchunks,
totalspace - freespace); 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", elog(WARNING, "problem in alloc set %s: req size > alloc size for chunk %p in block %p",
name, chunk, block); name, chunk, block);
if (chsize < (1 << ALLOC_MINBITS)) if (chsize < (1 << ALLOC_MINBITS))
elog(WARNING, "problem in alloc set %s: bad size %lu for chunk %p in block %p", elog(WARNING, "problem in alloc set %s: bad size %zu for chunk %p in block %p",
name, (unsigned long) chsize, chunk, block); name, chsize, chunk, block);
/* single-chunk block? */ /* single-chunk block? */
if (chsize > set->allocChunkLimit && if (chsize > set->allocChunkLimit &&

View File

@ -577,8 +577,7 @@ MemoryContextAlloc(MemoryContext context, Size size)
AssertArg(MemoryContextIsValid(context)); AssertArg(MemoryContextIsValid(context));
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
context->isReset = false; context->isReset = false;
@ -603,8 +602,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
AssertArg(MemoryContextIsValid(context)); AssertArg(MemoryContextIsValid(context));
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
context->isReset = false; context->isReset = false;
@ -631,8 +629,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
AssertArg(MemoryContextIsValid(context)); AssertArg(MemoryContextIsValid(context));
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
context->isReset = false; context->isReset = false;
@ -653,8 +650,7 @@ palloc(Size size)
AssertArg(MemoryContextIsValid(CurrentMemoryContext)); AssertArg(MemoryContextIsValid(CurrentMemoryContext));
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
CurrentMemoryContext->isReset = false; CurrentMemoryContext->isReset = false;
@ -673,8 +669,7 @@ palloc0(Size size)
AssertArg(MemoryContextIsValid(CurrentMemoryContext)); AssertArg(MemoryContextIsValid(CurrentMemoryContext));
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
CurrentMemoryContext->isReset = false; CurrentMemoryContext->isReset = false;
@ -726,8 +721,7 @@ repalloc(void *pointer, Size size)
void *ret; void *ret;
if (!AllocSizeIsValid(size)) if (!AllocSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
/* /*
* Try to detect bogus pointers handed to us, poorly though we can. * Try to detect bogus pointers handed to us, poorly though we can.
@ -768,8 +762,7 @@ MemoryContextAllocHuge(MemoryContext context, Size size)
AssertArg(MemoryContextIsValid(context)); AssertArg(MemoryContextIsValid(context));
if (!AllocHugeSizeIsValid(size)) if (!AllocHugeSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
context->isReset = false; context->isReset = false;
@ -791,8 +784,7 @@ repalloc_huge(void *pointer, Size size)
void *ret; void *ret;
if (!AllocHugeSizeIsValid(size)) if (!AllocHugeSizeIsValid(size))
elog(ERROR, "invalid memory alloc request size %lu", elog(ERROR, "invalid memory alloc request size %zu", size);
(unsigned long) size);
/* /*
* Try to detect bogus pointers handed to us, poorly though we can. * Try to detect bogus pointers handed to us, poorly though we can.

View File

@ -671,8 +671,8 @@
/* Define to the name of a signed 64-bit integer type. */ /* Define to the name of a signed 64-bit integer type. */
#undef PG_INT64_TYPE #undef PG_INT64_TYPE
/* Define to the name of the default PostgreSQL service principal in Kerberos. /* Define to the name of the default PostgreSQL service principal in Kerberos
(--with-krb-srvnam=NAME) */ (GSSAPI). (--with-krb-srvnam=NAME) */
#undef PG_KRB_SRVNAM #undef PG_KRB_SRVNAM
/* PostgreSQL major version as a string */ /* PostgreSQL major version as a string */

View File

@ -386,6 +386,19 @@ nextch1:
else else
longflag = 1; longflag = 1;
goto nextch1; goto nextch1;
case 'z':
#if SIZEOF_SIZE_T == 8
#ifdef HAVE_LONG_INT_64
longflag = 1;
#elif defined(HAVE_LONG_LONG_INT_64)
longlongflag = 1;
#else
#error "Don't know how to print 64bit integers"
#endif
#else
/* assume size_t is same size as int */
#endif
goto nextch1;
case 'h': case 'h':
case '\'': case '\'':
/* ignore these */ /* ignore these */
@ -619,6 +632,19 @@ nextch2:
else else
longflag = 1; longflag = 1;
goto nextch2; goto nextch2;
case 'z':
#if SIZEOF_SIZE_T == 8
#ifdef HAVE_LONG_INT_64
longflag = 1;
#elif defined(HAVE_LONG_LONG_INT_64)
longlongflag = 1;
#else
#error "Don't know how to print 64bit integers"
#endif
#else
/* assume size_t is same size as int */
#endif
goto nextch2;
case 'h': case 'h':
case '\'': case '\'':
/* ignore these */ /* ignore these */