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