Re: [PATCH] Add use of asprintf()

From: Asif Naeem <anaeem(dot)it(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, David Rowley <dgrowleyml(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add use of asprintf()
Date: 2013-10-15 05:53:09
Message-ID: CAEB4t-N=p8cd3OZq+rZHNBU3WGYq=p7Vpa8AdTT_zSv-xh8z-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

+1

I think you can safely use va_list without copy on Windows. va_copy is
available in Visual Studio 2013 as part of support for C99, previous
versions don't have it.

Regards,
Muhammad Asif Naeem

On Tue, Oct 15, 2013 at 10:33 AM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>wrote:

> On Tue, Oct 15, 2013 at 2:18 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > On Mon, 2013-10-14 at 23:08 +1300, David Rowley wrote:
> >
> >>
> >> Looks like something like:
> >>
> >>
> >> #ifndef WIN32
> >> #define HAVE_VA_COPY 1
> >> #endif
> >>
> >>
> >> would need to be added to asprintf.c, but also some work needs to be
> >> done with mcxt.c as it uses va_copy unconditionally. Perhaps just
> >> defining a macro for va_copy would be better for windows. I was not
> >> quite sure the best header file for such a macro so I did not write a
> >> patch to fix it.
> >
> > Does Windows not have va_copy? What do they use instead?
>
> No, Windows doesn't have va_copy, instead they use something like below:
> #define va_copy(dest, src) (dest = src)
>
> Please refer below link for details of porting va_copy() on Windows:
> http://stackoverflow.com/questions/558223/va-copy-porting-to-visual-c
>
> I could see that there is similar handling in code of vasprintf(),
> such that if va_copy is not available then directly assign src to dst.
>
> #if defined(HAVE_VA_COPY)
> va_copy(ap2, ap);
> #define my_va_end(ap2) va_end(ap2)
> #elif defined(HAVE___BUILTIN_VA_COPY)
> __builtin_va_copy(ap2, ap);
> #define my_va_end(ap2) __builtin_va_end(ap2)
> #else
> ap2 = ap;
> #define my_va_end(ap2) do {} while (0)
> #endif
>
> I think rather than having writing code like above at places where
> va_copy is used, we can use something like:
> #ifdef WIN32
> #define va_copy(dest, src) (dest = src)
> #endif
>
> and define HAVE_VA_COPY to 1 for non-windows platform.
>
> With Regards,
> Amit Kapila.
> EnterpriseDB: http://www.enterprisedb.com
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2013-10-15 05:55:58 Re: [PATCH] Add use of asprintf()
Previous Message David Fetter 2013-10-15 05:50:04 Re: CREATE FOREIGN TABLE ( ... LIKE ... )