Comments about libintl and *printf - Mailing list pgsql-patches

From Bruce Momjian
Subject Comments about libintl and *printf
Date
Msg-id 200512061840.jB6Ie1o27807@candle.pha.pa.us
Whole thread Raw
Responses Re: Comments about libintl and *printf
List pgsql-patches
I have added the following comments about the interaction of libintl and
*printf macros so we will not get confused in the future.  Autoconf run,
backpatched to 8.1.X.

One question I have is why ecpglib didn't need to use our snprintf.c in
the past.  Didn't our macros spill in to ecpglib before?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql/configure.in,v
retrieving revision 1.435
diff -c -c -r1.435 configure.in
*** configure.in    6 Dec 2005 04:53:02 -0000    1.435
--- configure.in    6 Dec 2005 18:33:26 -0000
***************
*** 858,868 ****
  # have all the features we need --- see below.

  if test "$PORTNAME" = "win32"; then
!   # Win32 gets this built unconditionally
!   # libintl versions prior to 0.13 use the native *printf functions.
!   # Win32 *printf does not understand %$, so on Win32 using pre-0.13 libintl
!   # it is necessary to use the pg versions of *printf to properly process
!   # NLS strings that use the %$ format.
    pgac_need_repl_snprintf=yes
  else
    pgac_need_repl_snprintf=no
--- 858,888 ----
  # have all the features we need --- see below.

  if test "$PORTNAME" = "win32"; then
!   # Win32 gets snprintf.c built unconditionally.
!   #
!   # To properly translate all NLS languages strings, we must support the
!   # *printf() %$ format, which allows *printf() arguments to be selected
!   # by position in the translated string.
!   #
!   # libintl versions < 0.13 use the native *printf() functions, and Win32
!   # *printf() doesn't understand %$, so we must use our /port versions,
!   # which do understand %$. libintl versions >= 0.13 include their own
!   # *printf versions on Win32.  The libintl 0.13 release note text is:
!   #
!   #   C format strings with positions, as they arise when a translator
!   #   needs to reorder a sentence, are now supported on all platforms.
!   #   On those few platforms (NetBSD and Woe32) for which the native
!   #   printf()/fprintf()/... functions don't support such format
!   #   strings, replacements are provided through <libintl.h>.
!   #
!   # We could use libintl >= 0.13's *printf() if we were sure that we had
!   # a litint >= 0.13 at runtime, but seeing that there is no clean way
!   # to guarantee that, it is best to just use our own, so we are sure to
!   # get %$ support. In include/port.h we disable the *printf() macros
!   # that might have been defined by libintl.
!   #
!   # We do this unconditionally whether NLS is used or not so we are sure
!   # that all Win32 libraries and binaries behave the same.
    pgac_need_repl_snprintf=yes
  else
    pgac_need_repl_snprintf=no
***************
*** 1059,1067 ****
  *** for the exact reason.]])],
  [AC_MSG_RESULT([cross-compiling])])


  # Force use of our snprintf if system's doesn't do arg control
! # This feature is needed by NLS
  if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
    PGAC_FUNC_PRINTF_ARG_CONTROL
    if test $pgac_cv_printf_arg_control != yes ; then
--- 1079,1090 ----
  *** for the exact reason.]])],
  [AC_MSG_RESULT([cross-compiling])])

+ # --------------------
+ # Run tests below here
+ # --------------------

  # Force use of our snprintf if system's doesn't do arg control
! # See comment above at snprintf test for details.
  if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then
    PGAC_FUNC_PRINTF_ARG_CONTROL
    if test $pgac_cv_printf_arg_control != yes ; then
Index: src/include/port.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/port.h,v
retrieving revision 1.86
diff -c -c -r1.86 port.h
*** src/include/port.h    6 Dec 2005 05:13:46 -0000    1.86
--- src/include/port.h    6 Dec 2005 18:33:30 -0000
***************
*** 115,122 ****
  #ifdef USE_REPL_SNPRINTF

  /*
!  * Some versions of libintl try to replace printf and friends with macros;
!  * if we are doing likewise, make sure our versions win.
   */
  #ifdef vsnprintf
  #undef vsnprintf
--- 115,123 ----
  #ifdef USE_REPL_SNPRINTF

  /*
!  * Versions of libintl >= 0.13 try to replace printf() and friends with
!  * macros to their own versions that understand the %$ format.  We do the
!  * same, so disable their macros, if they exist.
   */
  #ifdef vsnprintf
  #undef vsnprintf

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: mvcc.sgml make up
Next
From: Bruce Momjian
Date:
Subject: Re: I have a non-ascii name.