OSSP CVS Repository

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

Check-in Number: 4608
Date: 2004-Jun-26 13:38:20 (local)
2004-Jun-26 11:38:20 (UTC)
User:rse
Branch:
Comment: o Provide Autoconf check (AC_CHECK_VA_COPY) for va_copy(d,s) macro and fallback implementations and now that we can be sure that va_copy() exists for us, use it in var_formatv() and ts.c instead of the direct assignments (which are not sufficiently portable).

o Remove "#undef socklen_t" from sa.h because the socklen_t fallback is a "typedef" since a longer time.

Tickets:
Inspections:
Files:
ossp-pkg/sa/ChangeLog      1.38 -> 1.39     10 inserted, 0 deleted
ossp-pkg/sa/aclocal.m4      1.10 -> 1.11     109 inserted, 0 deleted
ossp-pkg/sa/configure.ac      1.14 -> 1.15     2 inserted, 0 deleted
ossp-pkg/sa/sa.c      1.84 -> 1.85     3 inserted, 2 deleted
ossp-pkg/sa/sa.h      1.39 -> 1.40     0 inserted, 5 deleted
ossp-pkg/sa/ts.c      1.10 -> 1.11     5 inserted, 5 deleted

ossp-pkg/sa/ChangeLog 1.38 -> 1.39

--- ChangeLog    2004/06/26 11:16:02     1.38
+++ ChangeLog    2004/06/26 11:38:20     1.39
@@ -18,6 +18,16 @@
      based connection termination is performed on close(2).
      [Alexandre Balaban <abalaban@free.fr>]
 
+   o Provide Autoconf check (AC_CHECK_VA_COPY) for va_copy(d,s) macro
+     and fallback implementations and now that we can be sure that
+     va_copy() exists for us, use it in var_formatv() and ts.c instead
+     of the direct assignments (which are not sufficiently portable).
+     [Ralf S. Engelschall <rse@engelschall.com>]
+
+   o Remove "#undef socklen_t" from sa.h because the socklen_t
+     fallback is a "typedef" since a longer time.
+     [Ralf S. Engelschall <rse@engelschall.com>]
+
   Changes between 1.2.0 and 1.2.1 (02-Apr-2003 to 11-Jun-2004)
 
    o Fix timeout implementation related to SO_RCVTIMEO/SO_SNDTIMEO.


ossp-pkg/sa/aclocal.m4 1.10 -> 1.11

--- aclocal.m4   2004/04/02 18:22:46     1.10
+++ aclocal.m4   2004/06/26 11:38:20     1.11
@@ -237,3 +237,112 @@
 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/sa/configure.ac 1.14 -> 1.15

--- configure.ac 2004/04/02 18:21:07     1.14
+++ configure.ac 2004/06/26 11:38:20     1.15
@@ -44,6 +44,8 @@
 sinclude(sa.ac)
 SA_CHECK_ALL
 
+AC_CHECK_VA_COPY
+
 AC_CHECK_EXTLIB([OSSP ex], ex, __ex_ctx, ex.h,
                 [AC_DEFINE(WITH_EX, 1, [Define to 1 if building with OSSP ex])])
 


ossp-pkg/sa/sa.c 1.84 -> 1.85

--- sa.c 2004/06/26 11:16:02     1.84
+++ sa.c 2004/06/26 11:38:20     1.85
@@ -2273,6 +2273,7 @@
 sa_rc_t sa_sendf(sa_t *sa, sa_addr_t *raddr, const char *cpFmt, ...)
 {
     va_list ap;
+    va_list apbak;
     int nBuf;
     char *cpBuf;
     sa_rc_t rv;
@@ -2284,9 +2285,10 @@
 
     /* format string into temporary buffer */
     va_start(ap, cpFmt);
+    va_copy(apbak, ap);
     if ((nBuf = sa_mvsnprintf(NULL, 0, cpFmt, ap)) == -1)
         return SA_RC(SA_ERR_FMT);
-    va_end(ap);
+    va_copy(ap, apbak);
     if ((nBuf+1) > (int)sizeof(caBuf)) {
         /* requires a larger buffer, so allocate dynamically */
         if ((cpBuf = (char *)malloc((size_t)(nBuf+1))) == NULL)
@@ -2296,7 +2298,6 @@
         /* fits into small buffer, so allocate statically */
         cpBuf = caBuf;
     }
-    va_start(ap, cpFmt);
     rv = SA_OK;
     if (sa_mvsnprintf(cpBuf, (size_t)(nBuf+1), cpFmt, ap) == -1)
         rv = SA_ERR_FMT;


ossp-pkg/sa/sa.h 1.39 -> 1.40

--- sa.h 2004/04/02 18:21:07     1.39
+++ sa.h 2004/06/26 11:38:20     1.40
@@ -209,10 +209,5 @@
 /* error handling operations */
 extern char   *sa_error        (sa_rc_t __rv);
 
-/* cleanup */
-#if defined(HAVE_CONFIG_H) && !defined(HAVE_SOCKLEN_T)
-#undef socklen_t
-#endif
-
 #endif /* __SA_H__ */
 


ossp-pkg/sa/ts.c 1.10 -> 1.11

--- ts.c 2004/04/02 18:21:07     1.10
+++ ts.c 2004/06/26 11:38:20     1.11
@@ -1,11 +1,11 @@
 /*
-**  TS - OSSP Test Suite Library
+**  OSSP ts - Test Suite Library
 **  Copyright (c) 2001-2004 Ralf S. Engelschall <rse@engelschall.com>
 **  Copyright (c) 2001-2004 The OSSP Project <http://www.ossp.org/>
 **  Copyright (c) 2001-2004 Cable & Wireless <http://www.cw.com/>
 **
-**  This file is part of OSSP TS, a small test suite library which
-**  can be found at http://www.ossp.org/pkg/ts/.
+**  This file is part of OSSP ts, a small test suite library which
+**  can be found at http://www.ossp.org/pkg/lib/ts/.
 **
 **  Permission to use, copy, modify, and distribute this software for
 **  any purpose with or without fee is hereby granted, provided that
@@ -127,7 +127,7 @@
     char *cp;
     char c;
     int d;
-    size_t n;
+    int n;
     int bytes;
 
     if (format == NULL)
@@ -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