From b8f37a543cb5c22d6992b67da4d100b27f784320 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Oct 2022 14:48:26 +0100 Subject: [PATCH] glib: Always implement G_VA_COPY as va_copy() C99 guarantees that va_copy() exists, so use it, instead of probing for __va_copy(), va_copy(), or a reimplementation from first principles. Signed-off-by: Simon McVittie --- glib/glibconfig.h.in | 1 + glib/gutils.h | 13 ------------- meson.build | 35 ++++------------------------------- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/glib/glibconfig.h.in b/glib/glibconfig.h.in index e93a7c866..100d42741 100644 --- a/glib/glibconfig.h.in +++ b/glib/glibconfig.h.in @@ -118,6 +118,7 @@ typedef unsigned @glib_intptr_type_define@ guintptr; @glib_os@ +#define G_VA_COPY va_copy @glib_vacopy@ #define G_HAVE_ISO_VARARGS 1 diff --git a/glib/gutils.h b/glib/gutils.h index d50ef709e..36e2b50f5 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -36,19 +36,6 @@ G_BEGIN_DECLS -/* Define G_VA_COPY() to do the right thing for copying va_list variables. - * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy. - */ -#if !defined (G_VA_COPY) -# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) -# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) -# elif defined (G_VA_COPY_AS_ARRAY) -# define G_VA_COPY(ap1, ap2) memmove ((ap1), (ap2), sizeof (va_list)) -# else /* va_list is a pointer */ -# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2)) -# endif /* va_list is a pointer */ -#endif /* !G_VA_COPY */ - GLIB_AVAILABLE_IN_ALL const gchar * g_get_user_name (void); GLIB_AVAILABLE_IN_ALL diff --git a/meson.build b/meson.build index e93ed2c8d..c49815a9c 100644 --- a/meson.build +++ b/meson.build @@ -1646,38 +1646,11 @@ else endif # === va_copy checks === -# we currently check for all three va_copy possibilities, so we get -# all results in config.log for bug reports. -va_copy_func = '' -foreach try_func : [ '__va_copy', 'va_copy' ] - if cc.compiles('''#include - #include - #ifdef _MSC_VER - # include "msvc_recommended_pragmas.h" - #endif - void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - @0@ (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; - }'''.format(try_func), - name : try_func + ' check') - va_copy_func = try_func - endif -endforeach -if va_copy_func != '' - glib_conf.set('G_VA_COPY', va_copy_func) - glib_vacopy = '#define G_VA_COPY ' + va_copy_func -else - glib_vacopy = '/* #undef G_VA_COPY */' -endif +glib_vacopy = '' + +# We check for G_VA_COPY_AS_ARRAY for historical reasons, but we no longer +# use it: use Standard C va_copy() instead. va_list_val_copy_prog = ''' #include