From 8be01dd72f1f8dd106c16c5193c84b051e2c5e25 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 24 Jun 2023 07:43:44 +0300 Subject: [PATCH 22/22] Make va_copy hard requirement See osdn #45980 Signed-off-by: Marko Lindqvist --- doc/README.packaging | 1 + gen_headers/meson_fc_config.h.in | 3 --- m4/c99.m4 | 6 ++---- meson.build | 1 - utility/astring.c | 26 +++++--------------------- 5 files changed, 8 insertions(+), 29 deletions(-) diff --git a/doc/README.packaging b/doc/README.packaging index 7d1bed587f..31d42e1ec5 100644 --- a/doc/README.packaging +++ b/doc/README.packaging @@ -26,6 +26,7 @@ Updating from 3.2 to 3.3 against relatively new gtk4 versions * Build with meson supports building gtk4x modpack installer that is linked against relatively new gtk4 versions +* va_copy support is now mandatory ---------------------------------------------------------------------- Compatibility of modified versions diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in index 018ccde1d1..a83c969868 100644 --- a/gen_headers/meson_fc_config.h.in +++ b/gen_headers/meson_fc_config.h.in @@ -362,9 +362,6 @@ /* usleep() available */ #mesondefine HAVE_USLEEP -/* Have C99 va_copy() */ -#mesondefine HAVE_VA_COPY - /* vprintf() available */ #mesondefine HAVE_VPRINTF diff --git a/m4/c99.m4 b/m4/c99.m4 index 9b679c7bda..4389c6f98d 100644 --- a/m4/c99.m4 +++ b/m4/c99.m4 @@ -134,9 +134,7 @@ AC_CACHE_CHECK([for C99 va_copy], va_list copy; va_copy(copy, orig);]])], [ac_cv_c99_va_copy=yes], [ac_cv_c99_va_copy=no])]) - if test "x${ac_cv_c99_va_copy}" = "xyes" ; then - AC_DEFINE([HAVE_VA_COPY], [1], [va_copy() available]) - else - AC_MSG_WARN([va_copy() support is going to be mandatory soon]) + if test "x${ac_cv_c99_va_copy}" != "xyes" ; then + AC_MSG_WARN([va_copy() support is required]) fi ]) diff --git a/meson.build b/meson.build index eab378bd4a..d24a3711da 100644 --- a/meson.build +++ b/meson.build @@ -382,7 +382,6 @@ priv_functions = [ 'fcntl', 'ioctl', 'vsnprintf', - 'va_copy', 'localtime_r' ] diff --git a/utility/astring.c b/utility/astring.c index 9932c443fa..02d775d3bd 100644 --- a/utility/astring.c +++ b/utility/astring.c @@ -78,7 +78,7 @@ #define n_alloc _private_n_alloc_ static const struct astring zero_astr = ASTRING_INIT; -static char *astr_buffer = NULL; +static char *astr_buffer = nullptr; static size_t astr_buffer_alloc = 0; static fc_mutex astr_mutex; @@ -92,19 +92,14 @@ static void astr_buffer_free(void); ****************************************************************************/ static inline char *astr_buffer_get(size_t *alloc) { - if (!astr_buffer) { -#ifndef HAVE_VA_COPY - /* This buffer will never be grown, so it should be big enough - * from the beginning. */ - astr_buffer_alloc = 65536; -#else + if (astr_buffer == nullptr) { astr_buffer_alloc = 4096; -#endif astr_buffer = fc_malloc(astr_buffer_alloc); atexit(astr_buffer_free); } *alloc = astr_buffer_alloc; + return astr_buffer; } @@ -156,6 +151,7 @@ void astr_free(struct astring *astr) fc_assert_ret(NULL != astr->str); free(astr->str); } + *astr = zero_astr; } @@ -223,12 +219,10 @@ static inline void astr_vadd_at(struct astring *astr, size_t at, char *buffer; size_t buffer_size; size_t req_len; + va_list copy; fc_mutex_allocate(&astr_mutex); -#ifdef HAVE_VA_COPY - va_list copy; - buffer = astr_buffer_get(&buffer_size); va_copy(copy, ap); @@ -244,16 +238,6 @@ static inline void astr_vadd_at(struct astring *astr, size_t at, } } va_end(copy); -#else /* HAVE_VA_COPY */ - buffer = astr_buffer_get(&buffer_size); - - req_len = fc_vsnprintf(buffer, buffer_size, format, ap); - - if (req_len > buffer_size) { - /* What we actually got */ - req_len = buffer_size; - } -#endif /* HAVE_VA_COPY */ req_len += at + 1; -- 2.40.1