bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

va_copy, new module 'stdarg'


From: Bruno Haible
Subject: va_copy, new module 'stdarg'
Date: Tue, 2 May 2006 16:31:59 +0200
User-agent: KMail/1.5

Hi Jim et al.,

I think the code in version-etc.c is not C99 compliant:

#ifdef __va_copy
    __va_copy (tmp_authors, authors);
#else
    tmp_authors = authors;
#endif

If a compiler other than GCC defines va_copy, it should be used, rather than
performing an assignment.

I propose this fix, using a va_copy detection macro that I wrote for gettext.
(I heard that you don't like #ifdefs inside functions?)

Bruno


2006-05-01  Bruno Haible  <address@hidden>

        * modules/stdarg: New file.
        * m4/stdarg.m4: New file.
        * modules/version-etc: Depend on stdarg.
        * lib/version-etc.c (version_etc_va): Use va_copy.

*** gnulib-20060430/lib/version-etc.c   2006-01-10 00:13:57.000000000 +0100
--- gnulib-20060430-modified/lib/version-etc.c  2006-04-30 20:22:13.000000000 
+0200
***************
*** 50,60 ****
    {
      va_list tmp_authors;
  
! #ifdef __va_copy
!     __va_copy (tmp_authors, authors);
! #else
!     tmp_authors = authors;
! #endif
  
      n_authors = 0;
      while (va_arg (tmp_authors, const char *) != NULL)
--- 50,56 ----
    {
      va_list tmp_authors;
  
!     va_copy (tmp_authors, authors);
  
      n_authors = 0;
      while (va_arg (tmp_authors, const char *) != NULL)
*** gnulib-20060430/modules/version-etc 2005-07-06 17:58:47.000000000 +0200
--- gnulib-20060430-modified/modules/version-etc        2006-05-01 
15:25:31.000000000 +0200
***************
*** 7,12 ****
--- 7,13 ----
  
  Depends-on:
  gettext-h
+ stdarg
  
  configure.ac:
  

========================== modules/stdarg ================================
Description:
An <stdarg.h> that conforms to C99.

Files:
m4/stdarg.m4

Depends-on:

configure.ac:
gl_STDARG_H

Makefile.am:

Include:
#include <stdarg.h>

License:
LGPL

Maintainer:
Bruno Haible
================================ m4/stdarg.m4 ============================
# stdarg.m4 serial 1
dnl Copyright (C) 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl From Bruno Haible.
dnl Provide a working va_copy in combination with <stdarg.h>.

AC_DEFUN([gl_STDARG_H],
[
  AC_MSG_CHECKING([for va_copy])
  AC_CACHE_VAL([gl_cv_func_va_copy], [
    AC_TRY_COMPILE([#include <stdarg.h>], [
#ifndef va_copy
void (*func) (va_list, va_list) = va_copy;
#endif
],
      [gl_cv_func_va_copy=yes], [gl_cv_func_va_copy=no])])
  AC_MSG_RESULT([$gl_cv_func_va_copy])
  if test $gl_cv_func_va_copy = no; then
    # Provide a substitute, either __va_copy or as a simple assignment.
    AC_CACHE_VAL([gl_cv_func___va_copy], [
      AC_TRY_COMPILE([#include <stdarg.h>], [
#ifndef __va_copy
error, bail out
#endif
],
        [gl_cv_func___va_copy=yes], [gl_cv_func___va_copy=no])])
    if test $gl_cv_func___va_copy = yes; then
      AC_DEFINE([va_copy], [__va_copy],
        [Define as a macro for copying va_list variables.])
    else
      AH_VERBATIM([#define gl_va_copy(a,b) (a) = (b)])
      AC_DEFINE([va_copy], [gl_va_copy],
        [Define as a macro for copying va_list variables.])
    fi
  fi
])
===========================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]