Re: [pgsql-hackers-win32] snprintf causes regression

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql(at)mohawksoft(dot)com, Nicolai Tufar <ntufar(at)gmail(dot)com>, Magnus Hagander <mha(at)sollentuna(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Win32 port list <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: [pgsql-hackers-win32] snprintf causes regression
Date: 2005-03-11 17:44:19
Message-ID: 200503111744.j2BHiJi08709@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > >> I'm not sure that macros can have variable number of arguments on all
> > >> supported platforms. I've been burnt by this before.
> >
> > > The actual patch is:
> >
> > > + #ifdef __GNUC__
> > > + #define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
> > > + #define snprintf(...) pg_snprintf(__VA_ARGS__)
> > > + #define printf(...) pg_printf(__VA_ARGS__)
> > > + #else
> > > + #define vsnprintf pg_vsnprintf
> > > + #define snprintf pg_snprintf
> > > + #define printf pg_printf
> > > + #endif
> >
> > Uh, why bother with the different approach for gcc?
>
> Because if we don't do that then the code above fails:
>
> extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
> /* This extension allows gcc to check the format string */
> __attribute__((format(printf, 3, 4)));
>
> The issue is that the "printf" here is interpreted specially by the
> compiler to mean "check arguments as printf". If the preprocessor
> changes that, we get a failure. The good news is that only gcc supports
> arg checking using __attribute__ and it also supports the __VA_ARGS__
> macros. What I think we do lose is argument checking for non-gcc, but
> this seems as close as we can get.

I am adding a comment explaining why those macros are used.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2005-03-11 17:58:28 Bumping libpq version number?
Previous Message Bruce Momjian 2005-03-11 17:37:24 Re: [pgsql-hackers-win32] snprintf causes regression

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Bruce Momjian 2005-03-11 21:30:59 Re: [pgsql-hackers-win32] Repleacement for src/port/snprintf.c
Previous Message Bruce Momjian 2005-03-11 17:37:24 Re: [pgsql-hackers-win32] snprintf causes regression

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-03-11 18:54:33 Re: Functions and transactions
Previous Message Bruce Momjian 2005-03-11 17:37:24 Re: [pgsql-hackers-win32] snprintf causes regression