Clean up usage of va_copy.

AC_TYPE_VA_LIST is no longer necessary, and the code is easier to read.
This commit is contained in:
Bill Currie 2016-01-03 21:16:23 +09:00
parent 2cbb7cb0c8
commit 735fcf68d5
5 changed files with 19 additions and 37 deletions

View file

@ -7,8 +7,6 @@ AC_FUNC_MEMCMP
AC_FUNC_MMAP AC_FUNC_MMAP
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
AC_FUNC_VPRINTF AC_FUNC_VPRINTF
AC_FUNC_VA_COPY
AC_FUNC__VA_COPY
AC_CHECK_FUNCS( AC_CHECK_FUNCS(
access _access connect dlopen execvp fcntl ftime _ftime getaddrinfo \ access _access connect dlopen execvp fcntl ftime _ftime getaddrinfo \
gethostbyname gethostname getnameinfo getpagesize gettimeofday getuid \ gethostbyname gethostname getnameinfo getpagesize gettimeofday getuid \
@ -17,6 +15,17 @@ AC_CHECK_FUNCS(
_vsnprintf wait _vsnprintf wait
) )
AC_FUNC_VA_COPY
AC_FUNC__VA_COPY
AH_VERBATIM([DEFINE_VA_COPY],
[#ifndef HAVE_VA_COPY
# ifdef HAVE__VA_COPY
# define va_copy(d,s) __va_copy ((d), (s))
# else
# define va_copy(d,s) memcpy (&(d), &(s), sizeof (va_list))
# endif
#endif])
DL_LIBS="" DL_LIBS=""
if test "x$ac_cv_func_dlopen" != "xyes"; then if test "x$ac_cv_func_dlopen" != "xyes"; then
AC_CHECK_LIB(dl, dlopen, AC_CHECK_LIB(dl, dlopen,

View file

@ -88,8 +88,6 @@ AH_VERBATIM([HAVE___BUILTIN_EXPECT],
# define __builtin_expect(x,c) x # define __builtin_expect(x,c) x
#endif]) #endif])
AC_TYPE_VA_LIST
AC_MSG_CHECKING(for type of fpos_t) AC_MSG_CHECKING(for type of fpos_t)
AC_TRY_COMPILE( AC_TRY_COMPILE(
[#include <stdio.h>], [#include <stdio.h>],

View file

@ -299,23 +299,13 @@ dstring_clearstr (dstring_t *dstr)
dstr->str[0] = 0; dstr->str[0] = 0;
} }
#if defined (HAVE_VA_COPY)
# define VA_COPY(a,b) va_copy (a, b)
#elif defined (HAVE__VA_COPY)
# define VA_COPY(a,b) __va_copy (a, b)
#else
# define VA_COPY(a,b) memcpy (a, b, sizeof (a))
#endif
static int static int
_dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args) _dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args)
{ {
int size; int size;
#ifdef VA_LIST_IS_ARRAY
va_list tmp_args; va_list tmp_args;
VA_COPY (tmp_args, args); va_copy (tmp_args, args);
#endif
if (!dstr->truesize) if (!dstr->truesize)
dstring_clearstr (dstr); // Make it a string dstring_clearstr (dstr); // Make it a string
@ -324,17 +314,13 @@ _dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args)
args)) == -1) { args)) == -1) {
dstr->size = (dstr->truesize & ~1023) + 1024; dstr->size = (dstr->truesize & ~1023) + 1024;
dstring_adjust (dstr); dstring_adjust (dstr);
#ifdef VA_LIST_IS_ARRAY va_copy (args, tmp_args);
VA_COPY (args, tmp_args);
#endif
} }
dstr->size = size + offs + 2; dstr->size = size + offs + 2;
// "Proper" implementations return the required size // "Proper" implementations return the required size
if (dstr->size > dstr->truesize) { if (dstr->size > dstr->truesize) {
dstring_adjust (dstr); dstring_adjust (dstr);
#ifdef VA_LIST_IS_ARRAY va_copy (args, tmp_args);
VA_COPY (args, tmp_args);
#endif
vsnprintf (dstr->str + offs, dstr->truesize - offs - 1, fmt, args); vsnprintf (dstr->str + offs, dstr->truesize - offs - 1, fmt, args);
} }
dstr->size = size + offs + 1; dstr->size = size + offs + 1;

View file

@ -493,21 +493,11 @@ Sys_Quit (void)
exit (0); exit (0);
} }
#if defined (HAVE_VA_COPY)
# define VA_COPY(a,b) va_copy (a, b)
#elif defined (HAVE__VA_COPY)
# define VA_COPY(a,b) __va_copy (a, b)
#else
# define VA_COPY(a,b) memcpy (a, b, sizeof (a))
#endif
VISIBLE void VISIBLE void
Sys_Error (const char *error, ...) Sys_Error (const char *error, ...)
{ {
va_list args; va_list args;
#ifdef VA_LIST_IS_ARRAY
va_list tmp_args; va_list tmp_args;
#endif
static int in_sys_error = 0; static int in_sys_error = 0;
if (in_sys_error) { if (in_sys_error) {
@ -521,9 +511,7 @@ Sys_Error (const char *error, ...)
in_sys_error = 1; in_sys_error = 1;
va_start (args, error); va_start (args, error);
#ifdef VA_LIST_IS_ARRAY va_copy (tmp_args, args);
VA_COPY (tmp_args, args);
#endif
sys_err_printf_function (error, args); sys_err_printf_function (error, args);
va_end (args); va_end (args);
@ -532,9 +520,7 @@ Sys_Error (const char *error, ...)
if (sys_err_printf_function != Sys_ErrPrintf) { if (sys_err_printf_function != Sys_ErrPrintf) {
// print the message again using the default error printer to increase // print the message again using the default error printer to increase
// the chances of the error being seen. // the chances of the error being seen.
#ifdef VA_LIST_IS_ARRAY va_copy (args, tmp_args);
VA_COPY (args, tmp_args);
#endif
Sys_ErrPrintf (error, args); Sys_ErrPrintf (error, args);
} }

View file

@ -31,6 +31,9 @@
width * height bytes width * height bytes
no attached palette no attached palette
*/ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
# define _GNU_SOURCE # define _GNU_SOURCE