1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

Rework va_copy fallback

va_copy is a macro, so it can be detected without a feature test.
Fallback to __va_copy or memcpy.
This commit is contained in:
Nick Wellnhofer 2023-11-28 15:34:28 +01:00
parent 8707838e69
commit 5cffba8381
5 changed files with 12 additions and 93 deletions

View File

@ -157,19 +157,7 @@ if (NOT MSVC)
check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_symbol_exists(va_copy stdarg.h HAVE_VA_COPY)
check_symbol_exists(__va_copy stdarg.h HAVE___VA_COPY)
set(LT_OBJDIR ".libs/")
check_c_source_compiles("
#include <stdarg.h>
void a(va_list* ap) {};
int main() { va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1; return 0; }
" VA_LIST_IS_ARRAY_TEST)
if(VA_LIST_IS_ARRAY_TEST)
set(VA_LIST_IS_ARRAY FALSE)
else()
set(VA_LIST_IS_ARRAY TRUE)
endif()
check_c_source_compiles("
#include <stddef.h>
#include <sys/socket.h>

View File

@ -90,15 +90,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Whether va_copy() is available */
#cmakedefine HAVE_VA_COPY 1
/* Define to 1 if you have the <zlib.h> header file. */
#cmakedefine HAVE_ZLIB_H 1
/* Whether __va_copy() is available */
#cmakedefine HAVE___VA_COPY 1
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#cmakedefine LT_OBJDIR "@LT_OBJDIR@"
@ -126,9 +120,6 @@
/* Support for IPv6 */
#cmakedefine SUPPORT_IP6 1
/* Define if va_list is an array type */
#cmakedefine VA_LIST_IS_ARRAY 1
/* Version number of package */
#cmakedefine VERSION "@VERSION@"

View File

@ -317,37 +317,6 @@ AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */
# undef /**/ HAVE_MMAP
#endif])
dnl Checking for va_copy availability
AC_MSG_CHECKING([for va_copy])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
va_list ap1,ap2;]], [[va_copy(ap1,ap2);]])],
have_va_copy=yes,
have_va_copy=no)
AC_MSG_RESULT($have_va_copy)
if test x"$have_va_copy" = x"yes"; then
AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
else
AC_MSG_CHECKING([for __va_copy])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
va_list ap1,ap2;]], [[__va_copy(ap1,ap2);]])],
have___va_copy=yes,
have___va_copy=no)
AC_MSG_RESULT($have___va_copy)
if test x"$have___va_copy" = x"yes"; then
AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
fi
fi
dnl Checking whether va_list is an array type
AC_MSG_CHECKING([whether va_list is an array type])
AC_TRY_COMPILE2([
#include <stdarg.h>
void a(va_list * ap) {}],[
va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1],[
AC_MSG_RESULT(no)],[
AC_MSG_RESULT(yes)
AC_DEFINE([VA_LIST_IS_ARRAY], [1],[Define if va_list is an array type])])
dnl
dnl Checks for inet libraries
dnl

View File

@ -54,26 +54,11 @@
#define MAX_FREE_NODES 100
#endif
/*
* The following VA_COPY was coded following an example in
* the Samba project. It may not be sufficient for some
* esoteric implementations of va_list but (hopefully) will
* be sufficient for libxml2.
*/
#ifndef VA_COPY
#ifdef HAVE_VA_COPY
#define VA_COPY(dest, src) va_copy(dest, src)
#ifndef va_copy
#ifdef __va_copy
#define va_copy(dest, src) __va_copy(dest, src)
#else
#ifdef HAVE___VA_COPY
#define VA_COPY(dest,src) __va_copy(dest, src)
#else
#ifndef VA_LIST_IS_ARRAY
#define VA_COPY(dest,src) (dest) = (src)
#else
#include <string.h>
#define VA_COPY(dest,src) memcpy((char *)(dest),(char *)(src),sizeof(va_list))
#endif
#endif
#define va_copy(dest, src) memcpy(dest, src, sizeof(va_list))
#endif
#endif
@ -4590,7 +4575,7 @@ xmlTextReaderBuildMessage(const char *msg, va_list ap) {
va_list aq;
while (1) {
VA_COPY(aq, ap);
va_copy(aq, ap);
chars = vsnprintf(str, size, msg, aq);
va_end(aq);
if (chars < 0) {

View File

@ -11,6 +11,7 @@
#define IN_LIBXML
#include "libxml.h"
#include <string.h>
#include <stdarg.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
@ -30,26 +31,11 @@
#define B64LINELEN 72
#define B64CRLF "\r\n"
/*
* The following VA_COPY was coded following an example in
* the Samba project. It may not be sufficient for some
* esoteric implementations of va_list but (hopefully) will
* be sufficient for libxml2.
*/
#ifndef VA_COPY
#ifdef HAVE_VA_COPY
#define VA_COPY(dest, src) va_copy(dest, src)
#ifndef va_copy
#ifdef __va_copy
#define va_copy(dest, src) __va_copy(dest, src)
#else
#ifdef HAVE___VA_COPY
#define VA_COPY(dest,src) __va_copy(dest, src)
#else
#ifndef VA_LIST_IS_ARRAY
#define VA_COPY(dest,src) (dest) = (src)
#else
#include <string.h>
#define VA_COPY(dest,src) memcpy((char *)(dest),(char *)(src),sizeof(va_list))
#endif
#endif
#define va_copy(dest, src) memcpy(dest, src, sizeof(va_list))
#endif
#endif
@ -4486,7 +4472,7 @@ xmlTextWriterVSprintf(const char *format, va_list argptr)
return NULL;
}
VA_COPY(locarg, argptr);
va_copy(locarg, argptr);
while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0)
|| (count == size - 1) || (count == size) || (count > size)) {
va_end(locarg);
@ -4498,7 +4484,7 @@ xmlTextWriterVSprintf(const char *format, va_list argptr)
"xmlTextWriterVSprintf : out of memory!\n");
return NULL;
}
VA_COPY(locarg, argptr);
va_copy(locarg, argptr);
}
va_end(locarg);