diff --git a/configure.ac b/configure.ac index db13857..be7e793 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,39 @@ AX_VALGRIND_CHECK AC_SEARCH_LIBS([socket], [network socket]) AC_CHECK_FUNCS([snprintf vsnprintf], [], [have_snprintf=no]) -AC_CHECK_DECLS([va_copy], [], [], [#include ]) + +dnl Checking for va_copy availability +AC_MSG_CHECKING([for va_copy]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include +va_list ap1,ap2;]], [[va_copy(ap1,ap2);]])], +have_va_copy=yes, +have_va_copy=no) +AC_MSG_RESULT($have_va_copy) +if test x"$have_va_copy" = x"yes"; then + AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) +else + AC_MSG_CHECKING([for __va_copy]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include + va_list ap1,ap2;]], [[__va_copy(ap1,ap2);]])], + have___va_copy=yes, + have___va_copy=no) + AC_MSG_RESULT($have___va_copy) + if test x"$have___va_copy" = x"yes"; then + AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available]) + fi +fi + +if test x"$have_va_copy$have___va_copy" = x"nono"; then + dnl Checking whether va_list is an array type + AC_MSG_CHECKING([whether va_list is an array type]) + AC_TRY_COMPILE2([ + #include + void a(va_list * ap) {}],[ + va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1],[ + AC_MSG_RESULT(no)],[ + AC_MSG_RESULT(yes) + AC_DEFINE([VA_LIST_IS_ARRAY], [1],[Define if va_list is an array type])]) +fi if test "x$enable_tls" != xno -a "x$with_gnutls" == xyes; then PKG_CHECK_MODULES([gnutls], [gnutls], diff --git a/m4/ac_try_compile2.m4 b/m4/ac_try_compile2.m4 new file mode 100644 index 0000000..7ad8630 --- /dev/null +++ b/m4/ac_try_compile2.m4 @@ -0,0 +1,28 @@ +dnl Like AC_TRY_EVAL but also errors out if the compiler generates +dnl _any_ output. Some compilers might issue warnings which we want +dnl to catch. +AC_DEFUN([AC_TRY_EVAL2], +[{ (eval echo configure:__oline__: \"[$]$1\") 1>&AS_MESSAGE_LOG_FD; dnl +(eval [$]$1) 2>&AS_MESSAGE_LOG_FD; _out=`eval [$]$1 2>&1` && test "x$_out" = x; }]) + +dnl Like AC_TRY_COMPILE but calls AC_TRY_EVAL2 instead of AC_TRY_EVAL +AC_DEFUN([AC_TRY_COMPILE2], +[cat > conftest.$ac_ext <&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD +ifelse([$4], , , [ rm -rf conftest* + $4 +])dnl +fi +rm -f conftest*]) diff --git a/src/ctx.c b/src/ctx.c index 4bcc926..861788d 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -50,10 +50,22 @@ #include "resolver.h" #include "util.h" -/* Workaround for systems without va_copy support. */ -#if defined(_MSC_VER) && _MSC_VER < 1800 || \ - !defined(_MSC_VER) && !defined(HAVE_DECL_VA_COPY) -#define va_copy(d, s) (memcpy(&d, &s, sizeof(va_list))) +#ifndef va_copy +#ifdef HAVE_VA_COPY +#define va_copy(dest, src) va_copy(dest, src) +#else +#ifdef HAVE___VA_COPY +#define va_copy(dest, src) __va_copy(dest, src) +#else +#ifndef VA_LIST_IS_ARRAY +#define va_copy(dest, src) (dest) = (src) +#else +#include +#define va_copy(dest, src) \ + memcpy((char *)(dest), (char *)(src), sizeof(va_list)) +#endif +#endif +#endif #endif /** Initialize the Strophe library.