1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

- error.c: attempt to fix the xmlGetVarStr breakage once and for

good. Use a macro and based on the solution provided in
  vsnprintf manual page from GNU.
Daniel
This commit is contained in:
Daniel Veillard
2001-06-05 17:12:52 +00:00
parent 9974872663
commit 1c43dbf065
3 changed files with 67 additions and 46 deletions

View File

@ -1,3 +1,9 @@
Tue Jun 5 19:11:02 CEST 2001 Bjorn Reese <breese@users.sourceforge.net>
* error.c: attempt to fix the xmlGetVarStr breakage once and for
good. Use a macro and based on the solution provided in
vsnprintf manual page from GNU.
Tue Jun 5 14:46:10 CEST 2001 Bjorn Reese <breese@users.sourceforge.net> Tue Jun 5 14:46:10 CEST 2001 Bjorn Reese <breese@users.sourceforge.net>
* error.c: Workaround for non-preserving variadic list. * error.c: Workaround for non-preserving variadic list.

40
aclocal.m4 vendored
View File

@ -620,31 +620,35 @@ esac
]) ])
# AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for # AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for
# the libltdl convenience library, adds --enable-ltdl-convenience to # the libltdl convenience library and INCLTDL to the include flags for
# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor # the libltdl header and adds --enable-ltdl-convenience to the
# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed # configure arguments. Note that LIBLTDL and INCLTDL are not
# to be `${top_builddir}/libltdl'. Make sure you start DIR with # AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If DIR is not
# '${top_builddir}/' (note the single quotes!) if your package is not # provided, it is assumed to be `libltdl'. LIBLTDL will be prefixed
# flat, and, if you're not using automake, define top_builddir as # with '${top_builddir}/' and INCLTDL will be prefixed with
# appropriate in the Makefiles. # '${top_srcdir}/' (note the single quotes!). If your package is not
# flat and you're not using automake, define top_builddir and
# top_srcdir appropriately in the Makefiles.
AC_DEFUN(AC_LIBLTDL_CONVENIENCE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl AC_DEFUN(AC_LIBLTDL_CONVENIENCE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
case "$enable_ltdl_convenience" in case "$enable_ltdl_convenience" in
no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;; no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
"") enable_ltdl_convenience=yes "") enable_ltdl_convenience=yes
ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;; ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
esac esac
LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdlc.la LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl']) INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
]) ])
# AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for # AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for
# the libltdl installable library, and adds --enable-ltdl-install to # the libltdl installable library and INCLTDL to the include flags for
# the configure arguments. Note that LIBLTDL is not AC_SUBSTed, nor # the libltdl header and adds --enable-ltdl-install to the configure
# is AC_CONFIG_SUBDIRS called. If DIR is not provided, it is assumed # arguments. Note that LIBLTDL and INCLTDL are not AC_SUBSTed, nor is
# to be `${top_builddir}/libltdl'. Make sure you start DIR with # AC_CONFIG_SUBDIRS called. If DIR is not provided and an installed
# '${top_builddir}/' (note the single quotes!) if your package is not # libltdl is not found, it is assumed to be `libltdl'. LIBLTDL will
# flat, and, if you're not using automake, define top_builddir as # be prefixed with '${top_builddir}/' and INCLTDL will be prefixed
# appropriate in the Makefiles. # with '${top_srcdir}/' (note the single quotes!). If your package is
# not flat and you're not using automake, define top_builddir and
# top_srcdir appropriately in the Makefiles.
# In the future, this macro may have to be called after AC_PROG_LIBTOOL. # In the future, this macro may have to be called after AC_PROG_LIBTOOL.
AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
AC_CHECK_LIB(ltdl, main, AC_CHECK_LIB(ltdl, main,
@ -657,8 +661,8 @@ AC_DEFUN(AC_LIBLTDL_INSTALLABLE, [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
]) ])
if test x"$enable_ltdl_install" = x"yes"; then if test x"$enable_ltdl_install" = x"yes"; then
ac_configure_args="$ac_configure_args --enable-ltdl-install" ac_configure_args="$ac_configure_args --enable-ltdl-install"
LIBLTDL=ifelse($#,1,$1,['${top_builddir}/libltdl'])/libltdl.la LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
INCLTDL=ifelse($#,1,-I$1,['-I${top_builddir}/libltdl']) INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
else else
ac_configure_args="$ac_configure_args --enable-ltdl-install=no" ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
LIBLTDL="-lltdl" LIBLTDL="-lltdl"

67
error.c
View File

@ -13,15 +13,35 @@
#include <libxml/xmlerror.h> #include <libxml/xmlerror.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#if defined(__STDC__) && defined(__STDC_VERSION__) #define XML_GET_VAR_STR(msg, str) { \
# if (__STDC_VERSION__ >= 199901L) int size; \
# define HAVE_VA_COPY int chars; \
# endif char *larger; \
#endif va_list ap; \
#if !defined(HAVE_VA_COPY) \
# include <string.h> str = (char *) xmlMalloc(150); \
# define va_copy(x,y) memcpy((x),(y),sizeof(va_list)) if (str == NULL) \
#endif return; \
\
size = 150; \
\
while (1) { \
va_start(ap, msg); \
chars = vsnprintf(str, size, msg, ap); \
va_end(ap); \
if ((chars > -1) && (chars < size)) \
break; \
if (chars > -1) \
size += chars + 1; \
else \
size += 100; \
if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\
xmlFree(str); \
return; \
} \
str = larger; \
} \
}
/************************************************************************ /************************************************************************
* * * *
@ -157,6 +177,7 @@ xmlParserPrintFileContext(xmlParserInputPtr input) {
xmlGenericError(xmlGenericErrorContext,"%s\n", content); xmlGenericError(xmlGenericErrorContext,"%s\n", content);
} }
#if 0
/** /**
* xmlGetVarStr: * xmlGetVarStr:
* @msg: the message format * @msg: the message format
@ -172,7 +193,7 @@ xmlGetVarStr(const char * msg, va_list args) {
int length; int length;
int chars, left; int chars, left;
char *str, *larger; char *str, *larger;
va_list argscopy; va_list ap;
str = (char *) xmlMalloc(150); str = (char *) xmlMalloc(150);
if (str == NULL) if (str == NULL)
@ -184,8 +205,9 @@ xmlGetVarStr(const char * msg, va_list args) {
while (1) { while (1) {
left = size - length; left = size - length;
/* Try to print in the allocated space. */ /* Try to print in the allocated space. */
va_copy(argscopy, args); va_start(msg, ap);
chars = vsnprintf(str + length, left, msg, argscopy); chars = vsnprintf(str + length, left, msg, ap);
va_end(ap);
/* If that worked, we're done. */ /* If that worked, we're done. */
if ((chars > -1) && (chars < left )) if ((chars > -1) && (chars < left ))
break; break;
@ -202,6 +224,7 @@ xmlGetVarStr(const char * msg, va_list args) {
} }
return(str); return(str);
} }
#endif
/** /**
* xmlParserError: * xmlParserError:
@ -219,7 +242,6 @@ xmlParserError(void *ctx, const char *msg, ...)
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
xmlParserInputPtr cur = NULL; xmlParserInputPtr cur = NULL;
char * str; char * str;
va_list args;
if (ctxt != NULL) { if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
@ -232,9 +254,7 @@ xmlParserError(void *ctx, const char *msg, ...)
} }
xmlGenericError(xmlGenericErrorContext, "error: "); xmlGenericError(xmlGenericErrorContext, "error: ");
va_start(args, msg); XML_GET_VAR_STR(msg, str);
str = xmlGetVarStr(msg, args);
va_end(args);
xmlGenericError(xmlGenericErrorContext, str); xmlGenericError(xmlGenericErrorContext, str);
if (str != NULL) if (str != NULL)
xmlFree(str); xmlFree(str);
@ -265,7 +285,6 @@ xmlParserWarning(void *ctx, const char *msg, ...)
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
xmlParserInputPtr cur = NULL; xmlParserInputPtr cur = NULL;
char * str; char * str;
va_list args;
if (ctxt != NULL) { if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
@ -278,9 +297,7 @@ xmlParserWarning(void *ctx, const char *msg, ...)
} }
xmlGenericError(xmlGenericErrorContext, "warning: "); xmlGenericError(xmlGenericErrorContext, "warning: ");
va_start(args, msg); XML_GET_VAR_STR(msg, str);
str = xmlGetVarStr(msg, args);
va_end(args);
xmlGenericError(xmlGenericErrorContext, str); xmlGenericError(xmlGenericErrorContext, str);
if (str != NULL) if (str != NULL)
xmlFree(str); xmlFree(str);
@ -316,7 +333,6 @@ xmlParserValidityError(void *ctx, const char *msg, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
char * str; char * str;
va_list args;
if (ctxt != NULL) { if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
@ -327,9 +343,7 @@ xmlParserValidityError(void *ctx, const char *msg, ...)
} }
xmlGenericError(xmlGenericErrorContext, "validity error: "); xmlGenericError(xmlGenericErrorContext, "validity error: ");
va_start(args, msg); XML_GET_VAR_STR(msg, str);
str = xmlGetVarStr(msg, args);
va_end(args);
xmlGenericError(xmlGenericErrorContext, str); xmlGenericError(xmlGenericErrorContext, str);
if (str != NULL) if (str != NULL)
xmlFree(str); xmlFree(str);
@ -354,7 +368,6 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input = NULL; xmlParserInputPtr input = NULL;
char * str; char * str;
va_list args;
if (ctxt != NULL) { if (ctxt != NULL) {
input = ctxt->input; input = ctxt->input;
@ -365,9 +378,7 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
} }
xmlGenericError(xmlGenericErrorContext, "validity warning: "); xmlGenericError(xmlGenericErrorContext, "validity warning: ");
va_start(args, msg); XML_GET_VAR_STR(msg, str);
str = xmlGetVarStr(msg, args);
va_end(args);
xmlGenericError(xmlGenericErrorContext, str); xmlGenericError(xmlGenericErrorContext, str);
if (str != NULL) if (str != NULL)
xmlFree(str); xmlFree(str);