Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 75752 invoked from network); 25 Mar 2006 20:05:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Mar 2006 20:05:01 -0000 Received: (qmail 39357 invoked by uid 500); 25 Mar 2006 20:05:01 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 39343 invoked by uid 500); 25 Mar 2006 20:05:01 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 39332 invoked by uid 99); 25 Mar 2006 20:05:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Mar 2006 12:05:01 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 25 Mar 2006 12:05:00 -0800 Received: (qmail 75545 invoked by uid 65534); 25 Mar 2006 20:04:40 -0000 Message-ID: <20060325200440.75544.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r388810 - in /incubator/stdcxx/trunk: etc/config/src/VA_LIST.cpp include/rw/_defs.h src/exception.cpp tests/src/printf.cpp Date: Sat, 25 Mar 2006 20:04:39 -0000 To: stdcxx-commits@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 * _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 . * 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 + // 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; +} /********************************************************************/