Boost logo

Boost :

Subject: Re: [boost] [test] trunk breakage
From: Bjørn Roald (bjorn_at_[hidden])
Date: 2009-12-28 15:27:53


On Monday 28 December 2009 03:45:02 pm Gennadiy Rozental wrote:
> Eric Niebler <eric <at> boostpro.com> writes:
> > On 12/28/2009 7:03 AM, Gennadiy Rozental wrote:
> > > What is the proper (portable) way to copy va_list? Or at least what is
> > > the workaround for this compiler?
> >
> > There isn't a portable way to copy a va_list. va_copy is not standard.

It is a C99 macro

> > On some systems it's __va_copy, and other systems (e.g. msvc) don't have
> > it at all. Can the code in question be rewritten to not need it?
>
> I essentially need to do double pas through va_list. I can't reinitialize
> it cause I am doing this in a function which takes va_list as argument.
>
> Can I use va_copy with gcc 4?

I think so. I am no expert on this but just had a quick look. va_copy exist
on my Ubuntu system. The GCC compiler seems to have had it ac part of C99
support since 4.0.

http://gcc.gnu.org/gcc-4.0/c99status.html

I just updated my boost trunk working directory and hit a va_list problem in
test_tools.ipp . Seems related to this thread, so I replaced the problem
assignment expression with a most likely and very naive call to va_copy, and
the build at least continued.

@@ -198,8 +198,8 @@ format_report( OutStream& os, predicate_result const& pr,
unit_test::lazy_ostrea
     }
 
     case CHECK_PRED_WITH_ARGS: {
- va_list args_copy = args;
-
+ va_list args_copy;
+ va_copy(args_copy, args);
         os << prefix << assertion_descr;
 
         // print predicate call description

In addition, from the man page: http://man-wiki.net/index.php/3:va_arg

It looks like you need to match each va_copy with a va_end to clean up the
copy.

The implementation code in apache c++ standard library have some attempt to
prevent portability issues related to need for va_copy on some platforms.
Some useful comments as well:

http://svn.apache.org/repos/asf/stdcxx/branches/4.1.3/src/exception.cpp

maybe we need macro support for this, could it possibly help with something
like:

BOOST_VA_COPY(dest, src); // assignment or va_copy
use_va_copy(dest);
BOOST_VA_COPY_END(dest); // va_end on platforms with va_copy

-- 
Bjørn 

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