1 # va_copy.m4 serial 1 (js-1.6.20070208)
4 dnl ## Check for C99 va_copy() implementation
5 dnl ## (and provide fallback implementation if neccessary)
8 dnl ## AC_CHECK_VA_COPY
10 dnl ## #include "config.h"
14 dnl ## This check is rather complex: first because we really have to
15 dnl ## try various possible implementations in sequence and second, we
16 dnl ## cannot define a macro in config.h with parameters directly.
19 dnl # test program for va_copy() implementation
21 m4_define(__va_copy_test, <<[
25 #define DO_VA_COPY(d, s) $1
26 void test(char *str, ...)
32 for (i = 1; i <= 9; i++) {
33 int k = (int)va_arg(ap, int);
38 for (i = 1; i <= 9; i++) {
39 int k = (int)va_arg(ap, int);
45 int main(int argc, char *argv[])
47 test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
53 dnl # test driver for va_copy() implementation
54 m4_define(__va_copy_check, [
56 [/* Predefined possible va_copy() implementation (id: $1) */
57 #define __VA_COPY_USE_$1(d, s) $2])
58 if test ".$ac_cv_va_copy" = .; then
59 AC_TRY_RUN(__va_copy_test($2), [ac_cv_va_copy="$1"])
63 dnl # Autoconf check for va_copy() implementation checking
64 AC_DEFUN([AC_CHECK_VA_COPY],[
65 dnl # provide Autoconf display check message
66 AC_MSG_CHECKING(for va_copy() function)
67 dnl # check for various implementations in priorized sequence
68 AC_CACHE_VAL(ac_cv_va_copy, [
70 dnl # 1. check for standardized C99 macro
71 __va_copy_check(C99, [va_copy((d), (s))])
72 dnl # 2. check for alternative/deprecated GCC macro
73 __va_copy_check(GCM, [VA_COPY((d), (s))])
74 dnl # 3. check for internal GCC macro (high-level define)
75 __va_copy_check(GCH, [__va_copy((d), (s))])
76 dnl # 4. check for internal GCC macro (built-in function)
77 __va_copy_check(GCB, [__builtin_va_copy((d), (s))])
78 dnl # 5. check for assignment approach (assuming va_list is a struct)
79 __va_copy_check(ASS, [do { (d) = (s); } while (0)])
80 dnl # 6. check for assignment approach (assuming va_list is a pointer)
81 __va_copy_check(ASP, [do { *(d) = *(s); } while (0)])
82 dnl # 7. check for memory copying approach (assuming va_list is a struct)
83 __va_copy_check(CPS, [memcpy((void *)&(d), (void *)&(s)), sizeof((s))])
84 dnl # 8. check for memory copying approach (assuming va_list is a pointer)
85 __va_copy_check(CPP, [memcpy((void *)(d), (void *)(s)), sizeof(*(s))])
86 if test ".$ac_cv_va_copy" = .; then
87 AC_ERROR([no working implementation found])
90 dnl # optionally activate the fallback implementation
91 if test ".$ac_cv_va_copy" = ".C99"; then
92 AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy() macro exists (and no fallback implementation is required)])
94 dnl # declare which fallback implementation to actually use
95 AC_DEFINE_UNQUOTED([__VA_COPY_USE], [__VA_COPY_USE_$ac_cv_va_copy],
96 [Define to id of used va_copy() implementation])
97 dnl # provide activation hook for fallback implementation
98 AH_VERBATIM([__VA_COPY_ACTIVATION],
99 [/* Optional va_copy() implementation activation */
101 #define va_copy(d, s) __VA_COPY_USE(d, s)
104 dnl # provide Autoconf display result message
105 if test ".$ac_cv_va_copy" = ".C99"; then
108 AC_MSG_RESULT([no (using fallback implementation)])