summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2018-11-15 17:40:33 +0000
committerSimon McVittie <smcv@collabora.com>2018-11-19 11:27:25 +0000
commit6278951f6deb4a2a3b2177dfaaa64bd64fa13701 (patch)
tree6257fe7384ffce9e9811cdc79bcb7dc61d486d65
parentc018e0b1b28107cac6d243295b7afa8939fdbdcd (diff)
downloaddbus-6278951f6deb4a2a3b2177dfaaa64bd64fa13701.tar.gz
Don't check how to copy a va_list if we already have va_copy()
If we already have ISO C va_copy() or its non-standard counterpart __va_copy(), then there's no need to do an AC_RUN_IFELSE or its CMake equivalent to detect whether "args2 = args1" or "*args2 = *args1" works. AC_RUN_IFELSE is problematic during cross-compilation, where the program cannot be run (you have to know in advance that the test program will be run and what its result will be), so we want to avoid it whenever possible. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--cmake/ConfigureChecks.cmake38
-rw-r--r--configure.ac70
2 files changed, 53 insertions, 55 deletions
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index 310b1bbb..04180322 100644
--- a/cmake/ConfigureChecks.cmake
+++ b/cmake/ConfigureChecks.cmake
@@ -120,26 +120,26 @@ elseif(HAVE___VA_COPY)
else()
# this is used for msvc < 2013
set(DBUS_VA_COPY _DBUS_VA_COPY_ASSIGN)
-endif()
-CHECK_C_SOURCE_RUNS("
-#include <stdarg.h>
-#include <stdlib.h>
-static 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;
-}
-" VA_COPY_AS_ARRAY)
-if (NOT VA_COPY_AS_ARRAY)
- set(DBUS_VA_COPY_AS_ARRAY 1 CACHE STRING "Set to 1 if va_list cannot be copied as a value")
+ CHECK_C_SOURCE_RUNS("
+ #include <stdarg.h>
+ #include <stdlib.h>
+ static 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;
+ }
+ " VA_COPY_AS_ARRAY)
+ if (NOT VA_COPY_AS_ARRAY)
+ set(DBUS_VA_COPY_AS_ARRAY 1 CACHE STRING "Set to 1 if va_list cannot be copied as a value")
+ endif()
endif()
CHECK_C_SOURCE_COMPILES("
diff --git a/configure.ac b/configure.ac
index 89337836..fa542290 100644
--- a/configure.ac
+++ b/configure.ac
@@ -563,42 +563,40 @@ else if test "x$dbus_cv___va_copy" = "xyes"; then
fi
fi
-if test -n "$dbus_va_copy_func"; then
- AC_DEFINE_UNQUOTED(DBUS_VA_COPY,$dbus_va_copy_func,[A 'va_copy' style function])
-fi
-
-AC_LANG_PUSH(C)
-AC_CACHE_CHECK([whether va_lists can be copied by value],
- dbus_cv_va_val_copy,
- [AC_RUN_IFELSE([AC_LANG_PROGRAM(
-[[
- #include <stdarg.h>
- #include <stdlib.h>
-]],
-[[
- static 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;
- }
-]])],
- [dbus_cv_va_val_copy=yes],
- [dbus_cv_va_val_copy=no],
- [dbus_cv_va_val_copy=yes])
-])
-AC_LANG_POP(C)
-
-if test "x$dbus_cv_va_val_copy" = "xno"; then
- AC_DEFINE(DBUS_VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values])
-fi
-
+AS_IF([test -n "$dbus_va_copy_func"],
+ [AC_DEFINE_UNQUOTED([DBUS_VA_COPY], [$dbus_va_copy_func], [A 'va_copy' style function])],
+ [
+ AC_LANG_PUSH([C])
+ AC_CACHE_CHECK([whether va_lists can be copied by value],
+ [dbus_cv_va_val_copy],
+ [AC_RUN_IFELSE([
+ AC_LANG_PROGRAM([[
+ #include <stdarg.h>
+ #include <stdlib.h>
+ ]],
+ [[
+ static 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;
+ }
+ ]])
+ ],
+ [dbus_cv_va_val_copy=yes],
+ [dbus_cv_va_val_copy=no],
+ [dbus_cv_va_val_copy=yes])
+ ])
+ AC_LANG_POP([C])
+ AS_IF([test "x$dbus_cv_va_val_copy" = "xno"],
+ [AC_DEFINE([DBUS_VA_COPY_AS_ARRAY], 1, [Define if 'va_list' cannot be copied as a value])])
+ ])
#### Atomic integers