git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: va_copy is not available on all systems.

From
MPMichael Poole <mdpoole@troilus.org>
Date
Aug 20, 2007, 13:39 UTC
Message-ID
<87y7g6wcix.fsf@graviton.dyn.troilus.org>
In-Reply-To
<46C99448.2AB33DFF@eudaptics.com>
Johannes Sixt writes:
Show 10 quoted lines
> This is just too ugly to be included...
>
> die_nicely() uses the variable argument list twice. The recent fix for
> this in 7e5dcea8311 uses va_copy. However, on older systems this function
> is not available. This fix assumes that those systems that do have
> the function actually implement it as macro, and we use it to remove
> the entire nicely() functionality.
>
> Since va_copy() must be provided by the compiler, we don't have a
> reasonable chance to provide a working definition in git_compat_util.h.

Some older (pre-C99) versions of gcc name it __va_copy() instead. Is there any guarantee that va_copy() will be a macro on systems that provide it? If neither va_copy() nor __va_copy() are available, memcpy(&(DEST), &(SRC), sizeof(DEST)) should work for any va_list type. It's what I use on one project:

#ifdef HAVE_VA_COPY #define VA_COPY(DEST, SRC) va_copy(DEST, SRC) #elif HAVE___VA_COPY #define VA_COPY(DEST, SRC) __va_copy(DEST, SRC) #else #define VA_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(DEST)) #endif

with appropriate autoconf tests, basically two copies of this:
dnl How to copy one va_list to another?
AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(
  [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],
  [ac_cv_c_va_copy="yes"],
  [ac_cv_c_va_copy="no"]
)])
if test "$ac_cv_c_va_copy" = "yes" ; then
  AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
fi

I'm not sure how to translate the tests to git's coding style most easily.

Michael Poole
Previous: Johannes SixtNext: Alex Riesen
Message 2 of 6 in “va_copy is not available on all systems.”
  1. Johannes SixtAug 20, 2007
  2. Michael PooleAug 20, 2007
  3. Alex RiesenAug 20, 2007
  4. Shawn O. PearceAug 21, 2007
  5. Junio C HamanoAug 21, 2007
  6. Alex RiesenAug 21, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.