Boost logo

Boost :

Subject: Re: [boost] [test] va_copy
From: Bjørn Roald (bjorn_at_[hidden])
Date: 2010-01-03 20:32:55


On Monday 04 January 2010 01:36:45 am Gennadiy Rozental wrote:
> Bjørn Roald wrote:
> > On Friday 01 January 2010 10:15:29 pm Steven Watanabe wrote:
> >> AMDG
> >>
> >> Boost.Test is still failing on some compilers that don't support
> >> va_copy. Is va_copy always a macro? Would it be possible
> >> to use #ifdef va_copy?
> >
> > If it helps, that is what is done here:
> > http://svn.apache.org/repos/asf/stdcxx/branches/4.1.3/src/exception.cpp
>
> I'd rather stay away from ifdef va_copy. Does it required by standard
> for the va_copy to be a macro?

Latest C++0x drafts say:

        Other runtime support [support.runtime]

        Table 21 — Header <cstdarg> synopsis
        Type Name(s)
        Macros: va_arg va_end va_start va_copy
        Type: va_list

And state that <cstdarg> provide same features as C99 stdarg.h with some C++
adjustments.

> > The commit in trunk adding va_copy is also missing the va_end call and
> > possibly one more call of va_copy to be correct according to the manpage.
>
> You mean I need va_end after va_copy?

Yes - the Linux manual page says.

   va_copy()
       An obvious implementation would have a va_list be a pointer to the
stack frame of the variadic func‐
       tion. In such a setup (by far the most common) there seems nothing
against an assignment

           va_list aq = ap;

       Unfortunately, there are also systems that make it an array of
pointers (of length 1), and there one
       needs

           va_list aq;
           *aq = *ap;

       Finally, on systems where arguments are passed in registers, it may be
necessary for va_start() to
       allocate memory, store the arguments there, and also an indication of
which argument is next, so that
       va_arg() can step through the list. Now va_end() can free the
allocated memory again. To accommodate
       this situation, C99 adds a macro va_copy(), so that the above
assignment can be replaced by

           va_list aq;
           va_copy(aq, ap);
           ...
           va_end(aq);

       Each invocation of va_copy() must be matched by a corresponding
invocation of va_end() in the same
       function. Some systems that do not supply va_copy() have __va_copy
instead, since that was the name
       used in the draft proposal.

=== end manual quote

> Where is another va_copy?

A bit further down the same function:

        if( tl != PASS ) {
            args = args_copy; <=====

Looks a lot like a va_list assignment. But I have no clear understanding of
the code, or va_list HOWTOs for that sake.

-- 
Bjørn

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk