OSSP CVS Repository

ossp - Check-in [4983]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4983
Date: 2005-Jan-24 16:30:04 (local)
2005-Jan-24 15:30:04 (UTC)
User:rse
Branch:
Comment: Add Autoconf detection for va_copy() existence and fallbacks.
Tickets:
Inspections:
Files:
ossp-pkg/str/ChangeLog      1.48 -> 1.49     3 inserted, 0 deleted
ossp-pkg/str/aclocal.m4      1.7 -> 1.8     110 inserted, 0 deleted
ossp-pkg/str/configure.ac      1.14 -> 1.15     2 inserted, 0 deleted
ossp-pkg/str/str_basic.c      1.13 -> 1.14     2 inserted, 2 deleted
ossp-pkg/str/ts.c      1.2 -> 1.3     1 inserted, 1 deleted

ossp-pkg/str/ChangeLog 1.48 -> 1.49

--- ChangeLog    2005/01/24 15:22:18     1.48
+++ ChangeLog    2005/01/24 15:30:04     1.49
@@ -11,6 +11,9 @@
 
  Changes between 0.9.9 and 0.9.10 (23-Apr-2004 to 24-Jan-2004):
 
+   *) Add Autoconf detection for va_copy() existence and fallbacks.
+      [Ralf S. Engelschall <rse@engelschall.com>]
+
    *) Adjusted copyright messages for new year 2004/2005.
       [Ralf S. Engelschall <rse@engelschall.com>]
 


ossp-pkg/str/aclocal.m4 1.7 -> 1.8

--- aclocal.m4   2003/01/06 19:13:47     1.7
+++ aclocal.m4   2005/01/24 15:30:04     1.8
@@ -297,3 +297,113 @@
 fi
 AC_MSG_RESULT([$with_$2])
 ])dnl
+
+dnl ##
+dnl ##  Check for C99 va_copy() implementation
+dnl ##  (and provide fallback implementation if neccessary)
+dnl ##
+dnl ##  configure.in:
+dnl ##    AC_CHECK_VA_COPY
+dnl ##  foo.c:
+dnl ##    #include "config.h"
+dnl ##    [...]
+dnl ##    va_copy(d,s)
+dnl ##
+dnl ##  This check is rather complex: first because we really have to
+dnl ##  try various possible implementations in sequence and second, we
+dnl ##  cannot define a macro in config.h with parameters directly.
+dnl ##
+
+dnl #   test program for va_copy() implementation
+changequote(<<,>>)
+m4_define(__va_copy_test, <<[
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#define DO_VA_COPY(d, s) $1
+void test(char *str, ...)
+{
+    va_list ap, ap2;
+    int i;
+    va_start(ap, str);
+    DO_VA_COPY(ap2, ap);
+    for (i = 1; i <= 9; i++) {
+        int k = (int)va_arg(ap, int);
+        if (k != i)
+            abort();
+    }
+    DO_VA_COPY(ap, ap2);
+    for (i = 1; i <= 9; i++) {
+        int k = (int)va_arg(ap, int);
+        if (k != i)
+            abort();
+    }
+    va_end(ap);
+}
+int main(int argc, char *argv[])
+{
+    test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
+    exit(0);
+}
+]>>)
+changequote([,])
+
+dnl #   test driver for va_copy() implementation
+m4_define(__va_copy_check, [
+    AH_VERBATIM($1,
+[/* Predefined possible va_copy() implementation (id: $1) */
+#define __VA_COPY_USE_$1(d, s) $2])
+    if test ".$ac_cv_va_copy" = .; then
+        AC_TRY_RUN(__va_copy_test($2), [ac_cv_va_copy="$1"])
+    fi
+])
+
+dnl #   Autoconf check for va_copy() implementation checking
+AC_DEFUN(AC_CHECK_VA_COPY,[
+  dnl #   provide Autoconf display check message
+  AC_MSG_CHECKING(for va_copy() function)
+  dnl #   check for various implementations in priorized sequence   
+  AC_CACHE_VAL(ac_cv_va_copy, [
+    ac_cv_va_copy=""
+    dnl #   1. check for standardized C99 macro
+    __va_copy_check(C99, [va_copy((d), (s))])
+    dnl #   2. check for alternative/deprecated GCC macro
+    __va_copy_check(GCM, [VA_COPY((d), (s))])
+    dnl #   3. check for internal GCC macro (high-level define)
+    __va_copy_check(GCH, [__va_copy((d), (s))])
+    dnl #   4. check for internal GCC macro (built-in function)
+    __va_copy_check(GCB, [__builtin_va_copy((d), (s))])
+    dnl #   5. check for assignment approach (assuming va_list is a struct)
+    __va_copy_check(ASS, [do { (d) = (s); } while (0)])
+    dnl #   6. check for assignment approach (assuming va_list is a pointer)
+    __va_copy_check(ASP, [do { *(d) = *(s); } while (0)])
+    dnl #   7. check for memory copying approach (assuming va_list is a struct)
+    __va_copy_check(CPS, [memcpy((void *)&(d), (void *)&(s)), sizeof((s))])
+    dnl #   8. check for memory copying approach (assuming va_list is a pointer)
+    __va_copy_check(CPP, [memcpy((void *)(d), (void *)(s)), sizeof(*(s))])
+    if test ".$ac_cv_va_copy" = .; then
+        AC_ERROR([no working implementation found])
+    fi
+  ])
+  dnl #   optionally activate the fallback implementation
+  if test ".$ac_cv_va_copy" = ".C99"; then
+      AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy() macro exists (and no fallback implementation is required)])
+  fi
+  dnl #   declare which fallback implementation to actually use
+  AC_DEFINE_UNQUOTED([__VA_COPY_USE], [__VA_COPY_USE_$ac_cv_va_copy],
+      [Define to id of used va_copy() implementation])
+  dnl #   provide activation hook for fallback implementation
+  AH_VERBATIM([__VA_COPY_ACTIVATION],
+[/* Optional va_copy() implementation activation */
+#ifndef HAVE_VA_COPY
+#define va_copy(d, s) __VA_COPY_USE(d, s)
+#endif
+])
+  dnl #   provide Autoconf display result message
+  if test ".$ac_cv_va_copy" = ".C99"; then
+      AC_MSG_RESULT([yes])
+  else
+      AC_MSG_RESULT([no (using fallback implementation)])
+  fi
+])
+


ossp-pkg/str/configure.ac 1.14 -> 1.15

--- configure.ac 2005/01/24 15:22:19     1.14
+++ configure.ac 2005/01/24 15:30:04     1.15
@@ -26,6 +26,8 @@
 AC_CHECK_SIZEOF(long long, 8)
 AC_CHECK_SIZEOF(void *, 4)
 
+AC_CHECK_VA_COPY
+
 AC_HAVE_FUNCS(memmove memset memcmp memchr)
 AC_HAVE_FUNCS(isnan isinf)
 


ossp-pkg/str/str_basic.c 1.13 -> 1.14

--- str_basic.c  2005/01/24 15:22:19     1.13
+++ str_basic.c  2005/01/24 15:30:04     1.14
@@ -133,11 +133,11 @@
         return NULL;
 
     /* determine required target string length */
-    ap_safe = ap;
+    va_copy(ap_safe, ap);
     n = str_len(s);
     while ((cp = va_arg(ap, char *)) != NULL)
         n += str_len(cp);
-    ap = ap_safe;
+    va_copy(ap, ap_safe);
 
     /* allocate target string */
     if ((rv = str_mem_alloc(n+1)) == NULL)


ossp-pkg/str/ts.c 1.2 -> 1.3

--- ts.c 2003/02/11 08:39:47     1.2
+++ ts.c 2005/01/24 15:30:04     1.3
@@ -206,7 +206,7 @@
 
     if (format == NULL)
         return NULL;
-    ap2 = ap;
+    va_copy(ap2, ap);
     if ((n = ts_suite_mvxprintf(NULL, 0, format, ap)) == -1)
         return NULL;
     if ((buffer = (char *)malloc(n+1)) == NULL)

CVSTrac 2.0.1