Skip site navigation (1) Skip section navigation (2)

Re: %2$, %1$ gettext placeholder replacement is not working under Win32

From: Nicolai Tufar <ntufar(at)gmail(dot)com>
To: Magnus Hagander <mha(at)sollentuna(dot)net>,Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-hackers-win32(at)postgresql(dot)org,Ismail Teppeev <iteppeev(at)gmail(dot)com>
Subject: Re: %2$, %1$ gettext placeholder replacement is not working under Win32
Date: 2005-01-22 13:29:02
Message-ID: d809293905012205292a20c438@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-hackers-win32
Greetings,
for a couple of days I have been hacking on src/port/snprintf.c.
With Magnus' help I have managed to implement argument replacement
in snprintf(). The code is very crude and not quite optimised,
any suggestions will be more than welcome.

Here is what I did:

1. I renamed snprintf() to pg_snprintf(), vsnprintf() to pg_vsnprintf()
	 and introduced pg_printf() that calls pg_vsnprintf(). 

2. After running configure I manually added snprintf.o to src/Makefile.global's
   LIBOBJ declaration and -lpgport to Makefile.shlib's DLLWRAP declaration

3. To make sure these functions are used everywhere I introduced the following
   lines at the end of src/include/c.h:

#define snprintf pg_snprintf
#define vsnprintf pg_vsnprintf
#define printf pg_printf

4. I introduced a volatile static char[] variable in snprintf.c code so I can
   grep executables for this string and be sure that it is included.

5. Before running regression test I always ran make install, apparently because 
   libpq is read from /usr/local/.

During compilation the following warnings were reported:
../../../src/include/utils/elog.h:121: warning: `pg_printf' is an
unrecognized format function type

which is perfectly fine because we replace printf with pg_printf and
gcc's format() does
know anything about it.

On Linux, PostgreSQL passed regression tests with flying colours and
prints messages
with %n$ just fine. On win32: int8, timestamp, timestamptz, abstime, horology, 
constraints, vacuum, and many others failed. To check my code, I
reverted snprintf.c
to the original one from CVS and forced win32 port to use these
functions and it
fails in same places. After examining regression tests diff I came to 
conclusion that problem is in fmtnum() function when it operates with
particularly
long integers.

In snprintf() file I changed only and only dopr() function, neve touching
fmtnum(), fmtstr() or fmtfolat().

I would like to kindly ask these questions:

1. Am I on the right to implement %n$ ? Can it be accepted?
2. Why would we not just take FreeBSD's vfprintf() and use it instead?
3. What is wrong with fmtnum() on Win32?
4. What %m format string is used for? And where is it handled. Do I
need to implement it?

I am attaching my version if snprintf.c (because it is too different
from the original to
make a patch) and regression.diff of a failed Win32 regression test
produced wither with
my or with original snprintf.c.


Best regards,
Nicolai Tufar

In response to

Responses

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2005-01-22 14:31:39
Subject: Re: [HACKERS] %2$, %1$ gettext placeholder replacement is not working under Win32
Previous:From: Troels ArvinDate: 2005-01-22 13:11:45
Subject: Re: Extending System Views: proposal for 8.1/8.2

pgsql-hackers-win32 by date

Next:From: Peter EisentrautDate: 2005-01-22 14:31:39
Subject: Re: [HACKERS] %2$, %1$ gettext placeholder replacement is not working under Win32
Previous:From: Magnus HaganderDate: 2005-01-21 18:59:42
Subject: Re: Invalid username specified

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group