From b4a4a674182604c48e84052cf94b08fffab7f612 Mon Sep 17 00:00:00 2001 From: "seawood%netscape.com" Date: Sun, 23 Feb 2003 06:59:39 +0000 Subject: [PATCH] Use va_copy if available for VARARGS_ASSIGN Bug #187180 r=blizzard sr=brendan --- configure.in | 97 +++++++++++++++++++++-------- js/src/jsprf.c | 4 +- js/src/xpconnect/src/xpcconvert.cpp | 4 +- xpcom/ds/nsTextFormatter.cpp | 4 +- 4 files changed, 81 insertions(+), 28 deletions(-) diff --git a/configure.in b/configure.in index b5978844f5f..f4c89133f4d 100644 --- a/configure.in +++ b/configure.in @@ -2228,33 +2228,80 @@ esac AC_LANG_C -dnl Does this platform require array notation to assign to a va_list? -dnl If cross-compiling, we assume va_list is "normal". If this breaks -dnl you, set ac_cv_valistisarray=true and maybe define HAVE_VA_LIST_AS_ARRAY -dnl also just to be sure. -AC_MSG_CHECKING(whether va_list assignments need array notation) -AC_CACHE_VAL(ac_cv_valistisarray, - [AC_TRY_RUN([#include - #include - void foo(int i, ...) { - va_list ap1, ap2; - va_start(ap1, i); - ap2 = ap1; - if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); } - va_end(ap1); va_end(ap2); - } - int main() { foo(0, 123); return(0); }], - [ac_cv_valistisarray=false], - [ac_cv_valistisarray=true], - [ac_cv_valistisarray=false])]) - -if test "$ac_cv_valistisarray" = true ; then - AC_DEFINE(HAVE_VA_LIST_AS_ARRAY) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) +dnl ********************** +dnl *** va_copy checks *** +dnl ********************** +dnl we currently check for all three va_copy possibilities, so we get +dnl all results in config.log for bug reports. +AC_MSG_CHECKING(for an implementation of va_copy()) +AC_CACHE_VAL(ac_cv_va_copy,[ + AC_TRY_RUN([ + #include + void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { f (0, 42); return 0; }], + ac_cv_va_copy=yes, + ac_cv_va_copy=no, + ac_cv_va_copy=no + ) +]) +AC_MSG_RESULT($ac_cv_va_copy) +AC_MSG_CHECKING(for an implementation of __va_copy()) +AC_CACHE_VAL(ac_cv___va_copy,[ + AC_TRY_RUN([ + #include + void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + __va_copy (args2, args1); + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { f (0, 42); return 0; }], + ac_cv___va_copy=yes, + ac_cv___va_copy=no, + ac_cv___va_copy=no + ) +]) +AC_MSG_RESULT($ac_cv___va_copy) +AC_MSG_CHECKING(whether va_lists can be copied by value) +AC_CACHE_VAL(ac_cv_va_val_copy,[ + AC_TRY_RUN([ + #include + void f (int i, ...) { + va_list args1, args2; + va_start (args1, i); + args2 = args1; + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + va_end (args1); va_end (args2); + } + int main() { f (0, 42); return 0; }], + ac_cv_va_val_copy=yes, + ac_cv_va_val_copy=no, + ac_cv_va_val_copy=yes + ) +]) +if test "x$ac_cv_va_copy" = "xyes"; then + AC_DEFINE(VA_COPY, va_copy) + AC_DEFINE(HAVE_VA_COPY) +elif test "x$ac_cv___va_copy" = "xyes"; then + AC_DEFINE(VA_COPY, __va_copy) + AC_DEFINE(HAVE_VA_COPY) fi +if test "x$ac_cv_va_val_copy" = "xno"; then + AC_DEFINE(HAVE_VA_LIST_AS_ARRAY) +fi +AC_MSG_RESULT($ac_cv_va_val_copy) + dnl Check for dll-challenged libc's. dnl This check is apparently only needed for Linux. case "$target" in diff --git a/js/src/jsprf.c b/js/src/jsprf.c index d38c4b9a04b..994dbdf8daf 100644 --- a/js/src/jsprf.c +++ b/js/src/jsprf.c @@ -50,7 +50,9 @@ ** Note: on some platforms va_list is defined as an array, ** and requires array notation. */ -#ifdef HAVE_VA_LIST_AS_ARRAY +#ifdef HAVE_VA_COPY +#define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar) +#elif defined(HAVE_VA_LIST_AS_ARRAY) #define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0] #else #define VARARGS_ASSIGN(foo, bar) (foo) = (bar) diff --git a/js/src/xpconnect/src/xpcconvert.cpp b/js/src/xpconnect/src/xpcconvert.cpp index 9b03d34b753..1c176627da7 100644 --- a/js/src/xpconnect/src/xpcconvert.cpp +++ b/js/src/xpconnect/src/xpcconvert.cpp @@ -1441,7 +1441,9 @@ XPCConvert::JSErrorToXPCException(XPCCallContext& ccx, ** Note: on some platforms va_list is defined as an array, ** and requires array notation. */ -#ifdef HAVE_VA_LIST_AS_ARRAY +#ifdef HAVE_VA_COPY +#define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar) +#elif defined(HAVE_VA_LIST_AS_ARRAY) #define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0] #else #define VARARGS_ASSIGN(foo, bar) (foo) = (bar) diff --git a/xpcom/ds/nsTextFormatter.cpp b/xpcom/ds/nsTextFormatter.cpp index 5aa42d92572..1482b5af379 100644 --- a/xpcom/ds/nsTextFormatter.cpp +++ b/xpcom/ds/nsTextFormatter.cpp @@ -46,7 +46,9 @@ ** and requires array notation. */ -#ifdef HAVE_VA_LIST_AS_ARRAY +#ifdef HAVE_VA_COPY +#define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar) +#elif defined(HAVE_VA_LIST_AS_ARRAY) #define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0] #else #define VARARGS_ASSIGN(foo, bar) (foo) = (bar)