On 2013-12-06 09:54:59 -0500, Peter Eisentraut wrote:
> On 11/11/13, 12:01 PM, Tom Lane wrote:
> > I do recall Peter saying that the infrastructure knows how to
> > verify conversion specs in translated strings, so it would have to be
> > aware of 'z' flags for this to work.
> 
> It just checks that the same conversion placeholders appear in the
> translation.  It doesn't interpret the actual placeholders.  I don't
> think this will be a problem.

Ok, so here's a patch.

Patch 01 introduces infrastructure, and elog.c implementation.
Patch 02 converts some elog/ereport() callers to using the z modifier,
      some were wrong at least on 64 bit windows.

In patch 01, I've modified configure to not define [U]INT64_FORMAT
directly, but rather just define INT64_LENGTH_MODIFIER as
appropriate. The formats are now defined in c.h.
INT64_LENGTH_MODIFIER is defined without quotes - I am not sure whether
that was the right choice, it requires using CppAsString2() in some
places. Maybe I should just have defined it with quotes instead. Happy
to rejigger it if somebody thinks the other way would be better.

Note that I have decided to only support the z modifier properly if no
further modifiers (precision, width) are present. That seems sufficient
for now, given the usecases, and more complete support seems to be
potentially expensive without much use.

I wonder if we should also introduce SIZE_T_FORMAT and SSIZE_T_FORMAT,
there's some places that have #ifdef _WIN64 guards and similar that look
like they could be simplified.

Btw, walsender.c/walreceiver.c upcast an int into an unsigned long for
printing? That's a bit strange.

Greetings,

Andres Freund

-- 
 Andres Freund                     http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
>From b31f7c5fc2b2d4451c650a54bb02e656b8fd3bbf Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 7 Dec 2013 19:23:15 +0100
Subject: [PATCH 1/2] Add support for printing Size arguments to
 elog()/ereport() using %zu.

Similar to the way %m is special-case supported in elog.c routines, add
support for the z length modifier by replacing it by the platform's modifier
for the pointer size.

To do that, refactor the configure checks that define [U]INT64_FORMAT, to
instead define the used length modifier as INT64_LENGTH_MODIFIER. Currently we
don't support flag, width, precision modifiers in addition to z, but that's
fine for the current callsites.
---
 config/c-library.m4            | 36 ++++++++++++++---------------
 configure                      | 51 +++++++++++++++++-------------------------
 configure.in                   | 28 +++++++++--------------
 src/backend/utils/error/elog.c | 16 +++++++++++++
 src/include/c.h                | 10 ++++++---
 src/include/pg_config.h.in     |  7 ++----
 src/include/pg_config.h.win32  |  8 ++-----
 7 files changed, 77 insertions(+), 79 deletions(-)

diff --git a/config/c-library.m4 b/config/c-library.m4
index 1e3997b..b836c2a 100644
--- a/config/c-library.m4
+++ b/config/c-library.m4
@@ -221,22 +221,22 @@ HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
 AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS
 
 
-# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
+# PGAC_FUNC_SNPRINTF_LONG_LONG_LENGTH_MODIFIER
 # ---------------------------------------
-# Determine which format snprintf uses for long long int.  We handle
-# %lld, %qd, %I64d.  The result is in shell variable
-# LONG_LONG_INT_FORMAT.
+# Determine which format snprintf uses for long long integers.  We
+# handle %ll, %q, %I64.  The detected length modifer is stored in
+# the shell variable LONG_LONG_LENGTH_MODIFIER.
 #
-# MinGW uses '%I64d', though gcc throws an warning with -Wall,
-# while '%lld' doesn't generate a warning, but doesn't work.
+# MinGW uses '%I64', though gcc throws an warning with -Wall,
+# while '%ll' doesn't generate a warning, but doesn't work.
 #
-AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT],
-[AC_MSG_CHECKING([snprintf format for long long int])
-AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
-[for pgac_format in '%lld' '%qd' '%I64d'; do
+AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_LENGTH_MODIFIER],
+[AC_MSG_CHECKING([snprintf length modifier for long long])
+AC_CACHE_VAL(pgac_cv_snprintf_long_long_length_modifier,
+[for pgac_format in 'll' 'q' 'I64'; do
 AC_TRY_RUN([#include <stdio.h>
 typedef long long int ac_int64;
-#define INT64_FORMAT "$pgac_format"
+#define INT64_FORMAT "%${pgac_format}d"
 
 ac_int64 a = 20000001;
 ac_int64 b = 40000005;
@@ -258,19 +258,19 @@ int does_int64_snprintf_work()
 main() {
   exit(! does_int64_snprintf_work());
 }],
-[pgac_cv_snprintf_long_long_int_format=$pgac_format; break],
+[pgac_cv_snprintf_long_long_length_modifier=$pgac_format; break],
 [],
-[pgac_cv_snprintf_long_long_int_format=cross; break])
+[pgac_cv_snprintf_long_long_length_modifier=cross; break])
 done])dnl AC_CACHE_VAL
 
-LONG_LONG_INT_FORMAT=''
+LONG_LONG_LENGTH_MODIFIER=''
 
-case $pgac_cv_snprintf_long_long_int_format in
+case $pgac_cv_snprintf_long_long_length_modifier in
   cross) AC_MSG_RESULT([cannot test (not on host machine)]);;
-  ?*)    AC_MSG_RESULT([$pgac_cv_snprintf_long_long_int_format])
-         LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
+  ?*)    AC_MSG_RESULT([$pgac_cv_snprintf_long_long_length_modifier])
+         LONG_LONG_LENGTH_MODIFIER=$pgac_cv_snprintf_long_long_length_modifier;;
   *)     AC_MSG_RESULT(none);;
-esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
+esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_LENGTH_MODIFIER
 
 
 # PGAC_FUNC_PRINTF_ARG_CONTROL
diff --git a/configure b/configure
index 0165c3c..8a04cc9 100755
--- a/configure
+++ b/configure
@@ -24812,19 +24812,19 @@ fi
 
 # If we found "long int" is 64 bits, assume snprintf handles it.  If
 # we found we need to use "long long int", better check.  We cope with
-# snprintfs that use %lld, %qd, or %I64d as the format.  If none of these
-# work, fall back to our own snprintf emulation (which we know uses %lld).
+# snprintfs that use lld, qd, or I64d as the modifier.  If none of these
+# work, fall back to our own snprintf emulation (which we know uses ll).
 
 if test "$HAVE_LONG_LONG_INT_64" = yes ; then
   if test $pgac_need_repl_snprintf = no; then
-    { $as_echo "$as_me:$LINENO: checking snprintf format for long long int" >&5
-$as_echo_n "checking snprintf format for long long int... " >&6; }
-if test "${pgac_cv_snprintf_long_long_int_format+set}" = set; then
+    { $as_echo "$as_me:$LINENO: checking snprintf length modifier for long long" >&5
+$as_echo_n "checking snprintf length modifier for long long... " >&6; }
+if test "${pgac_cv_snprintf_long_long_length_modifier+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  for pgac_format in '%lld' '%qd' '%I64d'; do
+  for pgac_format in 'll' 'q' 'I64'; do
 if test "$cross_compiling" = yes; then
-  pgac_cv_snprintf_long_long_int_format=cross; break
+  pgac_cv_snprintf_long_long_length_modifier=cross; break
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -24834,7 +24834,7 @@ cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <stdio.h>
 typedef long long int ac_int64;
-#define INT64_FORMAT "$pgac_format"
+#define INT64_FORMAT "%${pgac_format}d"
 
 ac_int64 a = 20000001;
 ac_int64 b = 40000005;
@@ -24879,7 +24879,7 @@ $as_echo "$ac_try_echo") >&5
   ac_status=$?
   $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  pgac_cv_snprintf_long_long_int_format=$pgac_format; break
+  pgac_cv_snprintf_long_long_length_modifier=$pgac_format; break
 else
   $as_echo "$as_me: program exited with status $ac_status" >&5
 $as_echo "$as_me: failed program was:" >&5
@@ -24894,44 +24894,35 @@ fi
 done
 fi
 
-LONG_LONG_INT_FORMAT=''
+LONG_LONG_LENGTH_MODIFIER=''
 
-case $pgac_cv_snprintf_long_long_int_format in
+case $pgac_cv_snprintf_long_long_length_modifier in
   cross) { $as_echo "$as_me:$LINENO: result: cannot test (not on host machine)" >&5
 $as_echo "cannot test (not on host machine)" >&6; };;
-  ?*)    { $as_echo "$as_me:$LINENO: result: $pgac_cv_snprintf_long_long_int_format" >&5
-$as_echo "$pgac_cv_snprintf_long_long_int_format" >&6; }
-         LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
+  ?*)    { $as_echo "$as_me:$LINENO: result: $pgac_cv_snprintf_long_long_length_modifier" >&5
+$as_echo "$pgac_cv_snprintf_long_long_length_modifier" >&6; }
+         LONG_LONG_LENGTH_MODIFIER=$pgac_cv_snprintf_long_long_length_modifier;;
   *)     { $as_echo "$as_me:$LINENO: result: none" >&5
 $as_echo "none" >&6; };;
 esac
-    if test "$LONG_LONG_INT_FORMAT" = ""; then
+    if test "$LONG_LONG_LENGTH_MODIFIER" = ""; then
       # Force usage of our own snprintf, since system snprintf is broken
       pgac_need_repl_snprintf=yes
-      LONG_LONG_INT_FORMAT='%lld'
+      LONG_LONG_LENGTH_MODIFIER='ll'
     fi
   else
     # Here if we previously decided we needed to use our own snprintf
-    LONG_LONG_INT_FORMAT='%lld'
+    LONG_LONG_LENGTH_MODIFIER='ll'
   fi
-  LONG_LONG_UINT_FORMAT=`echo "$LONG_LONG_INT_FORMAT" | sed 's/d$/u/'`
-  INT64_FORMAT="\"$LONG_LONG_INT_FORMAT\""
-  UINT64_FORMAT="\"$LONG_LONG_UINT_FORMAT\""
+  INT64_LENGTH_MODIFIER="$LONG_LONG_LENGTH_MODIFIER"
 else
-  # Here if we are not using 'long long int' at all
-  INT64_FORMAT='"%ld"'
-  UINT64_FORMAT='"%lu"'
+  # Here if we are not using 'long long' at all
+  INT64_LENGTH_MODIFIER='l'
 fi
 
 
 cat >>confdefs.h <<_ACEOF
-#define INT64_FORMAT $INT64_FORMAT
-_ACEOF
-
-
-
-cat >>confdefs.h <<_ACEOF
-#define UINT64_FORMAT $UINT64_FORMAT
+#define INT64_LENGTH_MODIFIER $INT64_LENGTH_MODIFIER
 _ACEOF
 
 
diff --git a/configure.in b/configure.in
index 5479eab..134ea55 100644
--- a/configure.in
+++ b/configure.in
@@ -1628,35 +1628,29 @@ fi
 
 # If we found "long int" is 64 bits, assume snprintf handles it.  If
 # we found we need to use "long long int", better check.  We cope with
-# snprintfs that use %lld, %qd, or %I64d as the format.  If none of these
-# work, fall back to our own snprintf emulation (which we know uses %lld).
+# snprintfs that use lld, qd, or I64d as the modifier.  If none of these
+# work, fall back to our own snprintf emulation (which we know uses ll).
 
 if test "$HAVE_LONG_LONG_INT_64" = yes ; then
   if test $pgac_need_repl_snprintf = no; then
-    PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
-    if test "$LONG_LONG_INT_FORMAT" = ""; then
+    PGAC_FUNC_SNPRINTF_LONG_LONG_LENGTH_MODIFIER
+    if test "$LONG_LONG_LENGTH_MODIFIER" = ""; then
       # Force usage of our own snprintf, since system snprintf is broken
       pgac_need_repl_snprintf=yes
-      LONG_LONG_INT_FORMAT='%lld'
+      LONG_LONG_LENGTH_MODIFIER='ll'
     fi
   else
     # Here if we previously decided we needed to use our own snprintf
-    LONG_LONG_INT_FORMAT='%lld'
+    LONG_LONG_LENGTH_MODIFIER='ll'
   fi
-  LONG_LONG_UINT_FORMAT=`echo "$LONG_LONG_INT_FORMAT" | sed 's/d$/u/'`
-  INT64_FORMAT="\"$LONG_LONG_INT_FORMAT\""
-  UINT64_FORMAT="\"$LONG_LONG_UINT_FORMAT\""
+  INT64_LENGTH_MODIFIER="$LONG_LONG_LENGTH_MODIFIER"
 else
-  # Here if we are not using 'long long int' at all
-  INT64_FORMAT='"%ld"'
-  UINT64_FORMAT='"%lu"'
+  # Here if we are not using 'long long' at all
+  INT64_LENGTH_MODIFIER='l'
 fi
 
-AC_DEFINE_UNQUOTED(INT64_FORMAT, $INT64_FORMAT,
-                   [Define to the appropriate snprintf format for 64-bit ints.])
-
-AC_DEFINE_UNQUOTED(UINT64_FORMAT, $UINT64_FORMAT,
-                   [Define to the appropriate snprintf format for unsigned 64-bit ints.])
+AC_DEFINE_UNQUOTED(INT64_LENGTH_MODIFIER, $INT64_LENGTH_MODIFIER,
+                   [Define to the appropriate snprintf length modifier for 64-bit ints.])
 
 # Now we have checked all the reasons to replace snprintf
 if test $pgac_need_repl_snprintf = yes; then
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 65eb3bd..a2d0856 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -3185,6 +3185,22 @@ expand_fmt_string(const char *fmt, ErrorData *edata)
 					appendStringInfoCharMacro(&buf, *cp2);
 				}
 			}
+			else if (*cp == 'z')
+			{
+				/*
+				 * Replace %z by the appropriate length modifier for printing
+				 * Size/size_t or ssize_t arguments for the current
+				 * platform. Note that we don't support specifying with and
+				 * precision modifiers, but that's ok for the current
+				 * callsites.
+				 */
+#if SIZEOF_SIZE_T == 4
+				/* no modifier needed */
+#else
+				appendBinaryStringInfo(&buf, CppAsString2(INT64_LENGTH_MODIFIER),
+									   strlen(CppAsString2(INT64_LENGTH_MODIFIER)));
+#endif
+			}
 			else
 			{
 				/* copy % and next char --- this avoids trouble with %%m */
diff --git a/src/include/c.h b/src/include/c.h
index beb20b0..4e6f827 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -127,6 +127,8 @@
 /*
  * CppAsString
  *		Convert the argument to a string, using the C preprocessor.
+ * CppAsString2
+ *		Convert the argument's value to a string, using the C preprocessor.
  * CppConcat
  *		Concatenate two arguments together, using the C preprocessor.
  *
@@ -135,6 +137,8 @@
  * backward compatibility with existing PostgreSQL code.
  */
 #define CppAsString(identifier) #identifier
+/* need a second indirection because we want to stringize the macro value, not the name */
+#define CppAsString2(x) CppAsString(x)
 #define CppConcat(x, y)			x##y
 
 /*
@@ -279,6 +283,9 @@ typedef unsigned long long int uint64;
 #define UINT64CONST(x) ((uint64) x)
 #endif
 
+/* format codes for 64bit integers */
+#define INT64_FORMAT "%"CppAsString2(INT64_LENGTH_MODIFIER)"d"
+#define UINT64_FORMAT "%"CppAsString2(INT64_LENGTH_MODIFIER)"u"
 
 /* Select timestamp representation (float8 or int64) */
 #ifdef USE_INTEGER_DATETIMES
@@ -894,9 +901,6 @@ typedef NameData *Name;
  * Make sure this matches the installation rules in nls-global.mk.
  */
 
-/* need a second indirection because we want to stringize the macro value, not the name */
-#define CppAsString2(x) CppAsString(x)
-
 #ifdef SO_MAJOR_VERSION
 #define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
 #else
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d482e58..52aa03d 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -650,8 +650,8 @@
 /* Define to 1 if your compiler understands __VA_ARGS__ in macros. */
 #undef HAVE__VA_ARGS
 
-/* Define to the appropriate snprintf format for 64-bit ints. */
-#undef INT64_FORMAT
+/* Define to the appropriate snprintf length modifier for 64-bit ints. */
+#undef INT64_LENGTH_MODIFIER
 
 /* Define to build with Kerberos 5 support. (--with-krb5) */
 #undef KRB5
@@ -745,9 +745,6 @@
 /* Define to 1 if your <sys/time.h> declares `struct tm'. */
 #undef TM_IN_SYS_TIME
 
-/* Define to the appropriate snprintf format for unsigned 64-bit ints. */
-#undef UINT64_FORMAT
-
 /* Define to 1 to build with assertion checks. (--enable-cassert) */
 #undef USE_ASSERT_CHECKING
 
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index b69414f..e7eac3a 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -538,8 +538,8 @@
 /* Define to 1 if your compiler understands __VA_ARGS__ in macros. */
 #define HAVE__VA_ARGS 1
 
-/* Define to the appropriate snprintf format for 64-bit ints, if any. */
-#define INT64_FORMAT "%lld"
+/* Define to the appropriate snprintf length modifier for 64-bit ints. */
+#define INT64_LENGTH_MODIFIER ll
 
 /* Define to build with Kerberos 5 support. (--with-krb5) */
 /* #undef KRB5 */
@@ -617,10 +617,6 @@
 /* Define to 1 if your <sys/time.h> declares `struct tm'. */
 /* #undef TM_IN_SYS_TIME */
 
-/* Define to the appropriate snprintf format for unsigned 64-bit ints, if any.
-   */
-#define UINT64_FORMAT "%llu"
-
 /* Define to 1 to build with assertion checks. (--enable-cassert) */
 /* #undef USE_ASSERT_CHECKING */
 
-- 
1.8.5.rc2.dirty

>From 9614445f287f49a1f30fc6c1aab3b4c003d278cc Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Sat, 7 Dec 2013 19:23:39 +0100
Subject: [PATCH 2/2] Use the new %z support in several elog()/ereport()
 callers.

Some of the callsites were actually wrong, notably in aset.c and
mcxt.c, because they simply cast Size arguments to unsigned long,
which will give wrong results on LLP64 platforms like 64bit
windows. Many others just are shorter the new way.
---
 src/backend/access/hash/hashinsert.c      |  5 ++---
 src/backend/access/heap/hio.c             |  7 +++----
 src/backend/access/heap/rewriteheap.c     |  5 ++---
 src/backend/access/spgist/spgdoinsert.c   |  6 +++---
 src/backend/access/transam/xlog.c         |  4 ++--
 src/backend/nodes/readfuncs.c             | 13 +++++--------
 src/backend/port/sysv_shmem.c             |  4 ++--
 src/backend/port/win32_shmem.c            |  4 ++--
 src/backend/storage/file/fd.c             |  2 +-
 src/backend/storage/freespace/freespace.c |  3 +--
 src/backend/storage/ipc/dsm.c             |  4 ++--
 src/backend/storage/ipc/dsm_impl.c        | 12 ++++++------
 src/backend/storage/ipc/ipci.c            |  3 +--
 src/backend/storage/ipc/shmem.c           | 14 ++++++--------
 src/backend/storage/lmgr/predicate.c      |  8 ++++----
 src/backend/utils/mmgr/aset.c             | 23 ++++++++++-------------
 src/backend/utils/mmgr/mcxt.c             | 24 ++++++++----------------
 17 files changed, 60 insertions(+), 81 deletions(-)

diff --git a/src/backend/access/hash/hashinsert.c b/src/backend/access/hash/hashinsert.c
index 4508a36..bcc1713 100644
--- a/src/backend/access/hash/hashinsert.c
+++ b/src/backend/access/hash/hashinsert.c
@@ -65,9 +65,8 @@ _hash_doinsert(Relation rel, IndexTuple itup)
 	if (itemsz > HashMaxItemSize((Page) metap))
 		ereport(ERROR,
 				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-				 errmsg("index row size %lu exceeds hash maximum %lu",
-						(unsigned long) itemsz,
-						(unsigned long) HashMaxItemSize((Page) metap)),
+				 errmsg("index row size %zu exceeds hash maximum %zu",
+						itemsz, HashMaxItemSize((Page) metap)),
 			errhint("Values larger than a buffer page cannot be indexed.")));
 
 	/*
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c
index 8da2690..e15c416 100644
--- a/src/backend/access/heap/hio.c
+++ b/src/backend/access/heap/hio.c
@@ -237,9 +237,8 @@ RelationGetBufferForTuple(Relation relation, Size len,
 	if (len > MaxHeapTupleSize)
 		ereport(ERROR,
 				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-				 errmsg("row is too big: size %lu, maximum size %lu",
-						(unsigned long) len,
-						(unsigned long) MaxHeapTupleSize)));
+				 errmsg("row is too big: size %zu, maximum size %zu",
+						len, MaxHeapTupleSize)));
 
 	/* Compute desired extra freespace due to fillfactor option */
 	saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
@@ -477,7 +476,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
 	if (len > PageGetHeapFreeSpace(page))
 	{
 		/* 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);
 	}
 
 	/*
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index deec77d..eb418d3 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -601,9 +601,8 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
 	if (len > MaxHeapTupleSize)
 		ereport(ERROR,
 				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-				 errmsg("row is too big: size %lu, maximum size %lu",
-						(unsigned long) len,
-						(unsigned long) MaxHeapTupleSize)));
+				 errmsg("row is too big: size %zu, maximum size %zu",
+						len, MaxHeapTupleSize)));
 
 	/* Compute desired extra freespace due to fillfactor option */
 	saveFreeSpace = RelationGetTargetPageFreeSpace(state->rs_new_rel,
diff --git a/src/backend/access/spgist/spgdoinsert.c b/src/backend/access/spgist/spgdoinsert.c
index 9f425ca..a739f1b 100644
--- a/src/backend/access/spgist/spgdoinsert.c
+++ b/src/backend/access/spgist/spgdoinsert.c
@@ -1885,9 +1885,9 @@ spgdoinsert(Relation index, SpGistState *state,
 	if (leafSize > SPGIST_PAGE_CAPACITY && !state->config.longValuesOK)
 		ereport(ERROR,
 				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-			errmsg("index row size %lu exceeds maximum %lu for index \"%s\"",
-				   (unsigned long) (leafSize - sizeof(ItemIdData)),
-				 (unsigned long) (SPGIST_PAGE_CAPACITY - sizeof(ItemIdData)),
+			errmsg("index row size %zu exceeds maximum %zu for index \"%s\"",
+				   leafSize - sizeof(ItemIdData),
+				   SPGIST_PAGE_CAPACITY - sizeof(ItemIdData),
 				   RelationGetRelationName(index)),
 			errhint("Values larger than a buffer page cannot be indexed.")));
 
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index b68230d..4bdbe38 100755
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -2728,9 +2728,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
 					ereport(PANIC,
 							(errcode_for_file_access(),
 							 errmsg("could not write to log file %s "
-									"at offset %u, length %lu: %m",
+									"at offset %u, length %zu: %m",
 									XLogFileNameP(ThisTimeLineID, openLogSegNo),
-									openLogOff, (unsigned long) nbytes)));
+									openLogOff, nbytes)));
 				}
 				nleft -= written;
 				from += written;
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index 2e2cfa7..955bd6a 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -1435,15 +1435,13 @@ readDatum(bool typbyval)
 
 	token = pg_strtok(&tokenLength);	/* read the '[' */
 	if (token == NULL || token[0] != '[')
-		elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu",
-			 token ? (const char *) token : "[NULL]",
-			 (unsigned long) length);
+		elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
+			 token ? (const char *) token : "[NULL]", length);
 
 	if (typbyval)
 	{
 		if (length > (Size) sizeof(Datum))
-			elog(ERROR, "byval datum but length = %lu",
-				 (unsigned long) length);
+			elog(ERROR, "byval datum but length = %zu", length);
 		res = (Datum) 0;
 		s = (char *) (&res);
 		for (i = 0; i < (Size) sizeof(Datum); i++)
@@ -1467,9 +1465,8 @@ readDatum(bool typbyval)
 
 	token = pg_strtok(&tokenLength);	/* read the ']' */
 	if (token == NULL || token[0] != ']')
-		elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu",
-			 token ? (const char *) token : "[NULL]",
-			 (unsigned long) length);
+		elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
+			 token ? (const char *) token : "[NULL]", length);
 
 	return res;
 }
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index b604407..34f211e 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -138,8 +138,8 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
 		 */
 		ereport(FATAL,
 				(errmsg("could not create shared memory segment: %m"),
-		  errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).",
-					(unsigned long) memKey, (unsigned long) size,
+		  errdetail("Failed system call was shmget(key=%lu, size=%zu, 0%o).",
+					(unsigned long) memKey, size,
 					IPC_CREAT | IPC_EXCL | IPCProtection),
 				 (errno == EINVAL) ?
 				 errhint("This error usually means that PostgreSQL's request for a shared memory "
diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c
index 0db8e8f..e456f65 100644
--- a/src/backend/port/win32_shmem.c
+++ b/src/backend/port/win32_shmem.c
@@ -166,8 +166,8 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
 		if (!hmap)
 			ereport(FATAL,
 					(errmsg("could not create shared memory segment: error code %lu", GetLastError()),
-					 errdetail("Failed system call was CreateFileMapping(size=%lu, name=%s).",
-							   (unsigned long) size, szShareMem)));
+					 errdetail("Failed system call was CreateFileMapping(size=%zu, name=%s).",
+							   size, szShareMem)));
 
 		/*
 		 * If the segment already existed, CreateFileMapping() will return a
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index de4d902..494ca9e 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -829,7 +829,7 @@ AllocateVfd(void)
 	Index		i;
 	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? */
 
diff --git a/src/backend/storage/freespace/freespace.c b/src/backend/storage/freespace/freespace.c
index b15cf8f..1e91563 100644
--- a/src/backend/storage/freespace/freespace.c
+++ b/src/backend/storage/freespace/freespace.c
@@ -379,8 +379,7 @@ fsm_space_needed_to_cat(Size needed)
 
 	/* Can't ask for more space than the highest category represents */
 	if (needed > MaxFSMRequestSize)
-		elog(ERROR, "invalid FSM request size %lu",
-			 (unsigned long) needed);
+		elog(ERROR, "invalid FSM request size %zu", needed);
 
 	if (needed == 0)
 		return 1;
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index 6df402f..7e6e1a5 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -193,8 +193,8 @@ dsm_postmaster_startup(void)
 	dsm_control = dsm_control_address;
 	on_shmem_exit(dsm_postmaster_shutdown, 0);
 	elog(DEBUG2,
-		 "created dynamic shared memory control segment %u (%lu bytes)",
-		 dsm_control_handle, (unsigned long) segsize);
+		 "created dynamic shared memory control segment %u (%zu bytes)",
+		 dsm_control_handle, segsize);
 	dsm_write_state_file(dsm_control_handle);
 
 	/* Initialize control segment. */
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index 7c346e6..5b3589a 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -329,8 +329,8 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
 
 		ereport(elevel,
 				(errcode_for_dynamic_shared_memory(),
-				 errmsg("could not resize shared memory segment %s to %lu bytes: %m",
-					name, (unsigned long) request_size)));
+				 errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+					name, request_size)));
 		return false;
 	}
 
@@ -871,8 +871,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
 
 		ereport(elevel,
 				(errcode_for_dynamic_shared_memory(),
-				 errmsg("could not resize shared memory segment %s to %lu bytes: %m",
-					name, (unsigned long) request_size)));
+				 errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+					name, request_size)));
 		return false;
 	}
 	else if (*mapped_size < request_size)
@@ -919,8 +919,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
 
 			ereport(elevel,
 					(errcode_for_dynamic_shared_memory(),
-					 errmsg("could not resize shared memory segment %s to %lu bytes: %m",
-						name, (unsigned long) request_size)));
+					 errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+						name, request_size)));
 			return false;
 		}
 	}
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 040c7aa..57e2b9d 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -141,8 +141,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
 		/* might as well round it off to a multiple of a typical page size */
 		size = add_size(size, 8192 - (size % 8192));
 
-		elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)",
-			 (unsigned long) size);
+		elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
 
 		/*
 		 * Create the shmem segment
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 18ba426..8183931 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -344,8 +344,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
 				ereport(ERROR,
 						(errcode(ERRCODE_OUT_OF_MEMORY),
 						 errmsg("not enough shared memory for data structure"
-								" \"%s\" (%lu bytes requested)",
-								name, (unsigned long) size)));
+								" \"%s\" (%zu bytes requested)",
+								name, size)));
 			shmemseghdr->index = structPtr;
 			*foundPtr = FALSE;
 		}
@@ -378,10 +378,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
 			LWLockRelease(ShmemIndexLock);
 			ereport(ERROR,
 				  (errmsg("ShmemIndex entry size is wrong for data structure"
-						  " \"%s\": expected %lu, actual %lu",
-						  name,
-						  (unsigned long) size,
-						  (unsigned long) result->size)));
+						  " \"%s\": expected %zu, actual %zu",
+						  name, size, result->size)));
 		}
 		structPtr = result->location;
 	}
@@ -397,8 +395,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
 			ereport(ERROR,
 					(errcode(ERRCODE_OUT_OF_MEMORY),
 					 errmsg("not enough shared memory for data structure"
-							" \"%s\" (%lu bytes requested)",
-							name, (unsigned long) size)));
+							" \"%s\" (%zu bytes requested)",
+							name, size)));
 		}
 		result->size = size;
 		result->location = structPtr;
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index a8a0e98..12a9e85 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -1185,8 +1185,8 @@ InitPredicateLocks(void)
 			ereport(ERROR,
 					(errcode(ERRCODE_OUT_OF_MEMORY),
 			 errmsg("not enough shared memory for elements of data structure"
-					" \"%s\" (%lu bytes requested)",
-					"PredXactList", (unsigned long) requestSize)));
+					" \"%s\" (%zu bytes requested)",
+					"PredXactList", requestSize)));
 		/* Add all elements to available list, clean. */
 		memset(PredXact->element, 0, requestSize);
 		for (i = 0; i < max_table_size; i++)
@@ -1257,8 +1257,8 @@ InitPredicateLocks(void)
 			ereport(ERROR,
 					(errcode(ERRCODE_OUT_OF_MEMORY),
 			 errmsg("not enough shared memory for elements of data structure"
-					" \"%s\" (%lu bytes requested)",
-					"RWConflictPool", (unsigned long) requestSize)));
+					" \"%s\" (%zu bytes requested)",
+					"RWConflictPool", requestSize)));
 		/* Add all elements to available list, clean. */
 		memset(RWConflictPool->element, 0, requestSize);
 		for (i = 0; i < max_table_size; i++)
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index ff04a38..b6bbc7a 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -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 &&
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 9574fd3..b97c098 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -573,8 +573,7 @@ MemoryContextAlloc(MemoryContext context, Size size)
 	AssertArg(MemoryContextIsValid(context));
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	context->isReset = false;
 
@@ -599,8 +598,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
 	AssertArg(MemoryContextIsValid(context));
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	context->isReset = false;
 
@@ -627,8 +625,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
 	AssertArg(MemoryContextIsValid(context));
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	context->isReset = false;
 
@@ -649,8 +646,7 @@ palloc(Size size)
 	AssertArg(MemoryContextIsValid(CurrentMemoryContext));
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	CurrentMemoryContext->isReset = false;
 
@@ -669,8 +665,7 @@ palloc0(Size size)
 	AssertArg(MemoryContextIsValid(CurrentMemoryContext));
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	CurrentMemoryContext->isReset = false;
 
@@ -722,8 +717,7 @@ repalloc(void *pointer, Size size)
 	void	   *ret;
 
 	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	/*
 	 * Try to detect bogus pointers handed to us, poorly though we can.
@@ -764,8 +758,7 @@ MemoryContextAllocHuge(MemoryContext context, Size size)
 	AssertArg(MemoryContextIsValid(context));
 
 	if (!AllocHugeSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	context->isReset = false;
 
@@ -787,8 +780,7 @@ repalloc_huge(void *pointer, Size size)
 	void	   *ret;
 
 	if (!AllocHugeSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %lu",
-			 (unsigned long) size);
+		elog(ERROR, "invalid memory alloc request size %zu", size);
 
 	/*
 	 * Try to detect bogus pointers handed to us, poorly though we can.
-- 
1.8.5.rc2.dirty

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to