You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2006/03/25 21:04:39 UTC

svn commit: r388810 - in /incubator/stdcxx/trunk: etc/config/src/VA_LIST.cpp include/rw/_defs.h src/exception.cpp tests/src/printf.cpp

Author: sebor
Date: Sat Mar 25 12:04:37 2006
New Revision: 388810

URL: http://svn.apache.org/viewcvs?rev=388810&view=rev
Log:
2006-03-25  Martin Sebor  <se...@roguewave.com>

	* _defs.h (_RWSTD_VA_COPY): New helper macro.
	* VA_LIST.cpp(_RWSTD_NO_VA_COPY): New macro #defined in response
	to the C99 va_copy() macro not being #defined in <stdarg.h>.
	* exception.cpp (__rw_vfmtwhat): Unconditionally used _RWSTD_VA_COPY().
	* printf.cpp (rw_vasnprintf): Used _RWSTD_VA_COPY.
	(rw_sprintf, rw_snprintf): Provided definitions.

Modified:
    incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp
    incubator/stdcxx/trunk/include/rw/_defs.h
    incubator/stdcxx/trunk/src/exception.cpp
    incubator/stdcxx/trunk/tests/src/printf.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp?rev=388810&r1=388809&r2=388810&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/VA_LIST.cpp Sat Mar 25 12:04:37 2006
@@ -123,6 +123,15 @@
 
 #endif   // _RWSTD_USE_CONFIG
 
+#if defined (va_copy)
+
+    // comment out the macro #defined below when va_copy() exists
+    printf ("%s ", "//");
+
+#endif   // va_copy
+
+    printf ("#define _RWSTD_NO_VA_COPY\n");
+
     va_list va;
     memset (&va, 0, sizeof va);
 

Modified: incubator/stdcxx/trunk/include/rw/_defs.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/rw/_defs.h?rev=388810&r1=388809&r2=388810&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/rw/_defs.h (original)
+++ incubator/stdcxx/trunk/include/rw/_defs.h Sat Mar 25 12:04:37 2006
@@ -1587,4 +1587,24 @@
           __rw_insert_range (this, it, first, last, tag)
 #endif   // _RWSTD_NO_MEMBER_TEMPLATES
 
+
+#if defined (va_copy) || !defined _RWSTD_NO_VA_COPY
+   // either va_copy() is already #defined (because <stdarg.h>
+   // is already #included), or it was detected at configuration
+#  define _RWSTD_VA_COPY(va_dst, va_src) \
+          va_copy (va_dst, va_src)
+#elif 2 < __GNUG__
+   // no va_copy() macro detected, use gcc builtin
+#  define _RWSTD_VA_COPY(va_dst, va_src) \
+          __builtin_va_copy (va_dst, va_src)
+#elif defined (_RWSTD_NO_VA_LIST_ARRAY)
+   // va_list is not an array, use ordinary assignment to copy
+#  define _RWSTD_VA_COPY(va_dst, va_src) \
+          va_dst = va_src
+#else   // if defined (_RWSTD_NO_VA_LIST_ARRAY)
+   // va_list is an array, use memcpy()
+#  define _RWSTD_VA_COPY(va_dst, va_src) \
+          memcpy (va_dst, va_src, sizeof (va_list))
+#endif   // _RWSTD_NO_VA_LIST_ARRAY
+
 #endif   // _RWSTD_RW_DEFS_H_INCLUDED

Modified: incubator/stdcxx/trunk/src/exception.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/src/exception.cpp?rev=388810&r1=388809&r2=388810&view=diff
==============================================================================
--- incubator/stdcxx/trunk/src/exception.cpp (original)
+++ incubator/stdcxx/trunk/src/exception.cpp Sat Mar 25 12:04:37 2006
@@ -494,26 +494,16 @@
 
         int nwrote;
 
-#ifdef va_copy
-
         // copy va to a temporary and use it in each iteration
         // of the loop since it may be modified by the call to
         // vsnprintf() (e.g., on PowerPC/Linux)
 
         va_list tmp_va;
-        va_copy (tmp_va, va);
+        _RWSTD_VA_COPY (tmp_va, va);
 
         nwrote = _RWSTD_VSNPRINTF (buf, size, fmat, tmp_va);
 
         va_end (tmp_va);
-
-#else   // if !defined (va_copy)
-
-        // va_copy not defined, use va directly and hope for the best
-
-        nwrote = _RWSTD_VSNPRINTF (buf, size, fmat, va);
-
-#endif   // va_copy
 
         if (0 > nwrote) {
 

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/printf.cpp?rev=388810&r1=388809&r2=388810&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Sat Mar 25 12:04:37 2006
@@ -808,36 +808,11 @@
 {
     va_list *pva;
 
-#ifdef va_copy
-    // create a copy of va whose address can be passed to a function
-    // taking a va_list* so that it can modify the original; note that
-    // passing &va is not portable since when declared as a function
-    // argument, va_list that is an array type decays into a pointer
-    // and the address of the pointer will not match va_list* (as is
-    // the case on EM64T)
     va_list vacpy;
-    va_copy (vacpy, varg);
-    pva = &vacpy;
-
-#else   // if !defined (va_copy)
-
-#  if 2 < __GNUG__
+    _RWSTD_VA_COPY (vacpy, varg);
 
-    // use the gcc 3.x builtin when the va_copy macro is not defined
-    // (e.g., with gcc -ansi or Intel C++ icc -ansi or -strict_ansi)
-    va_list vacpy;
-    __builtin_va_copy (vacpy, varg);
     pva = &vacpy;
 
-#  else   // if !defined (__GNUG__)
-
-    // use varg (in)directly and assume it's safe (e.g., HP aCC on PA)
-    pva = &varg;
-
-#  endif   // 2 < __GNUG__
-
-#endif   // va_copy
-
 // do not use varg of vacpy below this point -- use *pva instead
 #define varg  DONT_TOUCH_ME
 #define vacpy DONT_TOUCH_ME
@@ -4102,6 +4077,54 @@
     return buf;
 }
 
+
+/********************************************************************/
+
+_TEST_EXPORT int
+rw_sprintf (char *buf, const char *fmt, ...)
+{
+    char *tmpbuf = 0;
+    size_t tmpsize = 0;
+
+    va_list va;
+    va_start (va, fmt);
+
+    // FIXME: format directly into buf to avoid dynamic allocation
+    const int nchars = rw_vasnprintf (&tmpbuf, &tmpsize, fmt, va);
+
+    va_end (va);
+
+    if (-1 < nchars)
+        memcpy (buf, tmpbuf, size_t (nchars));
+
+    free (tmpbuf);
+
+    return nchars;
+}
+
+/********************************************************************/
+
+_TEST_EXPORT int
+rw_snprintf (char *buf, size_t bufsize, const char *fmt, ...)
+{
+    char *tmpbuf = 0;
+    size_t tmpsize = 0;
+
+    va_list va;
+    va_start (va, fmt);
+
+    // FIXME: format directly into buf to avoid dynamic allocation
+    const int nchars = rw_vasnprintf (&tmpbuf, &tmpsize, fmt, va);
+
+    va_end (va);
+
+    if (size_t (nchars) <= bufsize)
+        memcpy (buf, tmpbuf, size_t (nchars));
+
+    free (tmpbuf);
+
+    return nchars;
+}
 
 /********************************************************************/