Spring cleanup ...: - configure.in Makefile.am config.h.in

Spring cleanup ...:
- configure.in Makefile.am config.h.in xmlversion.h.in: detect if
  we need string functions
- trio.[ch] strio.[ch]: embedded the Trio-0.23 string functions
  to be able to use them where needed. Applied some changes
  to reduce name linking pollution and compile in only what's
  needed.
- HTMLtree.c debugXML.c entities.c error.c nanoftp.c valid.c
  xlink.c xmlversion.h.in xpath.c: got rid of the #ifdef
  for the string manipulation functions
- xmlmemory.[ch]: removed DEBUG_MEMORY_FREED and added it automatically
  to the free() function of xmlmemory.c
- entities.c HTMLtree.c parserInternals.c tree.c uri.c valid.c
  xinclude.c xmlIO.c xpath.c xpointer.c: removed the MEM_CLEANUP
  usage.
Daniel
This commit is contained in:
Daniel Veillard 2001-03-27 12:47:33 +00:00
parent 2be30641d1
commit 92ad210417
27 changed files with 4709 additions and 206 deletions

View File

@ -1,3 +1,21 @@
Tue Mar 27 14:32:06 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* configure.in Makefile.am config.h.in xmlversion.h.in: detect if
we need string functions
* trio.[ch] strio.[ch]: embedded the Trio-0.23 string functions
to be able to use them where needed. Applied some changes
to reduce name linking pollution and compile in only what's
needed.
* HTMLtree.c debugXML.c entities.c error.c nanoftp.c valid.c
xlink.c xmlversion.h.in xpath.c: got rid of the #ifdef
for the string manipulation functions
* xmlmemory.[ch]: removed DEBUG_MEMORY_FREED and added it automatically
to the free() function of xmlmemory.c
* entities.c HTMLtree.c parserInternals.c tree.c uri.c valid.c
xinclude.c xmlIO.c xpath.c xpointer.c: removed the MEM_CLEANUP
usage.
Tue Mar 27 02:30:23 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* error.c: applied the context output patch of the error

View File

@ -177,12 +177,8 @@ htmlSetMetaEncoding(htmlDocPtr doc, const xmlChar *encoding) {
return(-1);
if (encoding != NULL) {
#ifdef HAVE_SNPRINTF
snprintf(newcontent, sizeof(newcontent), "text/html; charset=%s",
encoding);
#else
sprintf(newcontent, "text/html; charset=%s", encoding);
#endif
newcontent[sizeof(newcontent) - 1] = 0;
}
@ -663,7 +659,6 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) {
htmlDocContentDump(buf, cur);
*mem = buf->content;
*size = buf->use;
MEM_CLEANUP(buf, sizeof(xmlBuffer));
xmlFree(buf);
}

View File

@ -15,29 +15,11 @@ libxml2_la_LIBADD = @Z_LIBS@ -lm
libxml2_la_LDFLAGS = -version-info @LIBXML_VERSION_INFO@
libxml2_la_SOURCES = \
SAX.c \
entities.c \
encoding.c \
error.c \
parserInternals.c \
parser.c \
tree.c \
hash.c \
list.c \
xmlIO.c \
xmlmemory.c \
uri.c \
valid.c \
xlink.c \
HTMLparser.c \
HTMLtree.c \
debugXML.c \
xpath.c \
xpointer.c \
xinclude.c \
nanohttp.c \
nanoftp.c
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c \
trio.c strio.c
DEPS = $(top_builddir)/libxml2.la
LDADDS = $(top_builddir)/libxml2.la @Z_LIBS@ -lm
@ -428,7 +410,8 @@ EXTRA_DIST = xml2Conf.sh.in libxml.spec.in libxml.spec libxml.m4 \
$(man_MANS) libxml-2.0.pc.in xmlversion.h.in \
win32/README.MSDev win32/Makefile.mingw \
win32/libxml2/libxml2.dsp win32/libxml2/libxml2_so.dsp \
win32/libxml2/libxml2_a.dsp vms/build_libxml.com vms/config.vms
win32/libxml2/libxml2_a.dsp vms/build_libxml.com vms/config.vms \
trio.h strio.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libxml-2.0.pc

View File

@ -31,15 +31,27 @@
/* Define if you have the fpclass function. */
#undef HAVE_FPCLASS
/* Define if you have the fprintf function. */
#undef HAVE_FPRINTF
/* Define if you have the isnand function. */
#undef HAVE_ISNAND
/* Define if you have the localtime function. */
#undef HAVE_LOCALTIME
/* Define if you have the printf function. */
#undef HAVE_PRINTF
/* Define if you have the snprintf function. */
#undef HAVE_SNPRINTF
/* Define if you have the sprintf function. */
#undef HAVE_SPRINTF
/* Define if you have the sscanf function. */
#undef HAVE_SSCANF
/* Define if you have the stat function. */
#undef HAVE_STAT
@ -55,9 +67,15 @@
/* Define if you have the strndup function. */
#undef HAVE_STRNDUP
/* Define if you have the vfprintf function. */
#undef HAVE_VFPRINTF
/* Define if you have the vsnprintf function. */
#undef HAVE_VSNPRINTF
/* Define if you have the vsprintf function. */
#undef HAVE_VSPRINTF
/* Define if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H

View File

@ -100,11 +100,15 @@ AC_SUBST(CORBA_CFLAGS)
dnl Checks for library functions.
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(strdup strndup strerror snprintf vsnprintf)
AC_CHECK_FUNCS(strdup strndup strerror)
AC_CHECK_FUNCS(finite isnand fp_class class fpclass)
AC_CHECK_FUNCS(strftime localtime)
AC_CHECK_FUNCS(stat _stat)
dnl Checking the standard string functions availability
AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,
NEED_TRIO=1)
dnl Checks for inet libraries:
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
@ -240,6 +244,19 @@ dnl fi
CFLAGS="-Wall -g -O -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline "
dnl -Wcast-qual -ansi
fi
dnl
dnl Check for trio string functions
dnl
if test "${NEED_TRIO}" = "1" ; then
echo Adding trio library for string functions
WITH_TRIO=1
else
WITH_TRIO=0
fi
AC_SUBST(WITH_TRIO)
dnl
dnl Aloow to disable various pieces
dnl

View File

@ -1512,18 +1512,10 @@ xmlShellPwd(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED, char *buffer, xmlNodePtr node
next = cur->parent;
}
if (occur == 0)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s%s", sep, name, buffer);
#else
sprintf(buf, "%c%s%s", sep, name, buffer);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "%c%s[%d]%s",
sep, name, occur, buffer);
#else
sprintf(buf, "%c%s[%d]%s", sep, name, occur, buffer);
#endif
buf[sizeof(buf) - 1] = 0;
/*
* This test prevents buffer overflow, because this routine
@ -1593,11 +1585,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
if (ctxt->node == (xmlNodePtr) ctxt->doc)
sprintf(prompt, "%s > ", "/");
else if (ctxt->node->name)
#ifdef HAVE_SNPRINTF
snprintf(prompt, sizeof(prompt), "%s > ", ctxt->node->name);
#else
sprintf(prompt, "%s > ", ctxt->node->name);
#endif
else
sprintf(prompt, "? > ");
prompt[sizeof(prompt) - 1] = 0;

View File

@ -67,7 +67,6 @@ static void xmlFreeEntity(xmlEntityPtr entity) {
xmlFree((char *) entity->content);
if (entity->orig != NULL)
xmlFree((char *) entity->orig);
MEM_CLEANUP(entity, sizeof(xmlEntity));
xmlFree(entity);
}
@ -521,11 +520,7 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
} else if ((sizeof(xmlChar) == 1) && (*cur >= 0x80)) {
char buf[10], *ptr;
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else
sprintf(buf, "&#%d;", *cur);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;
@ -533,11 +528,7 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) {
} else if (IS_CHAR(*cur)) {
char buf[10], *ptr;
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else
sprintf(buf, "&#%d;", *cur);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;
@ -679,11 +670,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
xmlGenericError(xmlGenericErrorContext,
"xmlEncodeEntitiesReentrant : input not UTF-8\n");
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else
sprintf(buf, "&#%d;", *cur);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;
@ -714,11 +701,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
xmlGenericError(xmlGenericErrorContext,
"xmlEncodeEntitiesReentrant : char out of range\n");
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else
sprintf(buf, "&#%d;", *cur);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;
@ -728,11 +711,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
/*
* We could do multiple things here. Just save as a char ref
*/
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#x%X;", val);
#else
sprintf(buf, "&#x%X;", val);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;
@ -742,11 +721,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
} else if (IS_CHAR(*cur)) {
char buf[10], *ptr;
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "&#%d;", *cur);
#else
sprintf(buf, "&#%d;", *cur);
#endif
buf[sizeof(buf) - 1] = 0;
ptr = buf;
while (*ptr != 0) *out++ = *ptr++;

View File

@ -163,21 +163,17 @@ xmlGetVarStr(const char * msg, va_list args) {
int chars, left;
char *str, *larger;
str = (char *) xmlMalloc(100);
str = (char *) xmlMalloc(150);
if (str == NULL)
return(NULL);
size = 100;
size = 150;
length = 0;
while (1) {
left = size - length;
/* Try to print in the allocated space. */
#ifdef HAVE_VSNPRINTF
chars = vsnprintf(str + length, left, msg, args);
#else
chars = vsprintf(str + length, msg, args);
#endif
/* If that worked, we're done. */
if ((chars > -1) && (chars < left ))
break;

View File

@ -26,6 +26,7 @@
#ifdef DEBUG_MEMORY_LOCATION
#define MEM_LIST /* keep a list of all the allocated memory blocks */
#define DEBUG_MEMORY_FREED
#endif
#ifdef DEBUG_MEMORY_FREED

View File

@ -23,6 +23,15 @@ extern void xmlCheckVersion(int version);
#define LIBXML_VERSION_STRING "@LIBXML_VERSION_NUMBER@"
#define LIBXML_TEST_VERSION xmlCheckVersion(@LIBXML_VERSION_NUMBER@);
/*
* Whether the trio support need to be configured in
*/
#if @WITH_TRIO@
#define WITH_TRIO
#else
#define WITHOUT_TRIO
#endif
/*
* Whether the FTP support is configured in
*/

View File

@ -761,11 +761,7 @@ xmlNanoFTPSendUser(void *ctx) {
if (ctxt->user == NULL)
sprintf(buf, "USER anonymous\r\n");
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
#else
sprintf(buf, "USER %s\r\n", ctxt->user);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -788,17 +784,9 @@ xmlNanoFTPSendPasswd(void *ctx) {
int res;
if (ctxt->passwd == NULL)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname);
#else
sprintf(buf, "PASS libxml@%s\r\n", hostname);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
#else
sprintf(buf, "PASS %s\r\n", ctxt->passwd);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -947,11 +935,7 @@ xmlNanoFTPConnect(void *ctx) {
/*
* We need proxy auth
*/
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "USER %s\r\n", proxyUser);
#else
sprintf(buf, "USER %s\r\n", proxyUser);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -970,18 +954,10 @@ xmlNanoFTPConnect(void *ctx) {
break;
case 3:
if (proxyPasswd != NULL)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd);
#else
sprintf(buf, "PASS %s\r\n", proxyPasswd);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n",
hostname);
#else
sprintf(buf, "PASS libxml@%s\r\n", hostname);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1021,11 +997,7 @@ xmlNanoFTPConnect(void *ctx) {
/* we will try in seqence */
case 1:
/* Using SITE command */
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "SITE %s\r\n", ctxt->hostname);
#else
sprintf(buf, "SITE %s\r\n", ctxt->hostname);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1051,20 +1023,11 @@ xmlNanoFTPConnect(void *ctx) {
case 2:
/* USER user@host command */
if (ctxt->user == NULL)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "USER anonymous@%s\r\n",
ctxt->hostname);
#else
sprintf(buf, "USER anonymous@%s\r\n", ctxt->hostname);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "USER %s@%s\r\n",
ctxt->user, ctxt->hostname);
#else
sprintf(buf, "USER %s@%s\r\n",
ctxt->user, ctxt->hostname);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1083,17 +1046,9 @@ xmlNanoFTPConnect(void *ctx) {
return(0);
}
if (ctxt->passwd == NULL)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS libxml@%s\r\n", hostname);
#else
sprintf(buf, "PASS libxml@%s\r\n", hostname);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
#else
sprintf(buf, "PASS %s\r\n", ctxt->passwd);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1231,11 +1186,7 @@ xmlNanoFTPCwd(void *ctx, char *directory) {
* 250
* 500, 501, 502, 421, 530, 550
*/
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "CWD %s\r\n", directory);
#else
sprintf(buf, "CWD %s\r\n", directory);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1349,15 +1300,9 @@ xmlNanoFTPGetConnection(void *ctx) {
}
adp = (unsigned char *) &dataAddr.sin_addr;
portp = (unsigned char *) &dataAddr.sin_port;
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n",
adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
portp[0] & 0xff, portp[1] & 0xff);
#else
sprintf(buf, "PORT %d,%d,%d,%d,%d,%d\r\n",
adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
portp[0] & 0xff, portp[1] & 0xff);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP
@ -1590,11 +1535,7 @@ xmlNanoFTPList(void *ctx, ftpListCallback callback, void *userData,
ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);
if (ctxt->dataFd == -1)
return(-1);
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "LIST -L %s\r\n", filename);
#else
sprintf(buf, "LIST -L %s\r\n", filename);
#endif
}
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
@ -1706,17 +1647,9 @@ xmlNanoFTPGetSocket(void *ctx, const char *filename) {
return(-res);
}
if (filename == NULL)
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
#else
sprintf(buf, "RETR %s\r\n", ctxt->path);
#endif
else
#ifdef HAVE_SNPRINTF
snprintf(buf, sizeof(buf), "RETR %s\r\n", filename);
#else
sprintf(buf, "RETR %s\r\n", filename);
#endif
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
#ifdef DEBUG_FTP

View File

@ -1877,7 +1877,6 @@ xmlFreeInputStream(xmlParserInputPtr input) {
input->free((xmlChar *) input->base);
if (input->buf != NULL)
xmlFreeParserInputBuffer(input->buf);
MEM_CLEANUP(input, sizeof(xmlParserInput));
xmlFree(input);
}

568
strio.c Normal file
View File

@ -0,0 +1,568 @@
/*************************************************************************
*
* $Id$
*
* Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
* CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
*
************************************************************************/
/* DV for libxml */
#include "xmlversion.h"
#ifdef WITH_TRIO
/* FIXME
* StrToLongDouble
*/
static const char rcsid[] = "@(#)$Id$";
#if defined(unix) || defined(__xlC__)
# define PLATFORM_UNIX
#elif defined(WIN32) || defined(_WIN32)
# define PLATFORM_WIN32
#elif defined(AMIGA) && defined(__GNUC__)
# define PLATFORM_UNIX
#endif
#if defined(__STDC__) && (__STDC_VERSION__ >= 199901L)
# define TRIO_C99
#endif
#include "strio.h"
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include <math.h>
#ifndef DEBUG
# define NDEBUG
#endif
#include <assert.h>
#ifndef NULL
# define NULL 0
#endif
#define NIL ((char)0)
#ifndef FALSE
# define FALSE (1 == 0)
# define TRUE (! FALSE)
#endif
#define VALID(x) (NULL != (x))
#define INVALID(x) (NULL == (x))
#if defined(PLATFORM_UNIX)
# define USE_STRCASECMP
# define USE_STRNCASECMP
# define USE_STRERROR
#elif defined(PLATFORM_WIN32)
# define USE_STRCMPI
#endif
/*************************************************************************
* StrAppendMax
*/
char *StrAppendMax(char *target, size_t max, const char *source)
{
assert(VALID(target));
assert(VALID(source));
assert(max > 0);
max -= StrLength(target) + 1;
return (max > 0) ? strncat(target, source, max) : target;
}
/*************************************************************************
* StrCopyMax
*/
char *StrCopyMax(char *target, size_t max, const char *source)
{
assert(VALID(target));
assert(VALID(source));
assert(max > 0); /* Includes != 0 */
target = strncpy(target, source, max - 1);
target[max - 1] = (char)0;
return target;
}
/*************************************************************************
* StrDuplicate
*/
char *StrDuplicate(const char *source)
{
char *target;
assert(VALID(source));
target = (char *)malloc(StrLength(source) + 1);
if (target)
{
StrCopy(target, source);
}
return target;
}
/*************************************************************************
* StrDuplicateMax
*/
char *StrDuplicateMax(const char *source, size_t max)
{
char *target;
size_t len;
assert(VALID(source));
assert(max > 0);
/* Make room for string plus a terminating zero */
len = StrLength(source) + 1;
if (len > max)
{
len = max;
}
target = (char *)malloc(len);
if (target)
{
StrCopyMax(target, len, source);
}
return target;
}
/*************************************************************************
* StrEqual
*/
int StrEqual(const char *first, const char *second)
{
assert(VALID(first));
assert(VALID(second));
if (VALID(first) && VALID(second))
{
#if defined(USE_STRCASECMP)
return (0 == strcasecmp(first, second));
#elif defined(USE_STRCMPI)
return (0 == strcmpi(first, second));
#else
while ((*first != NIL) && (*second != NIL))
{
if (toupper(*first) != toupper(*second))
{
break;
}
first++;
second++;
}
return ((*first == NIL) && (*second == NIL));
#endif
}
return FALSE;
}
/*************************************************************************
* StrEqualCase
*/
int StrEqualCase(const char *first, const char *second)
{
assert(VALID(first));
assert(VALID(second));
if (VALID(first) && VALID(second))
{
return (0 == strcmp(first, second));
}
return FALSE;
}
/*************************************************************************
* StrEqualCaseMax
*/
int StrEqualCaseMax(const char *first, size_t max, const char *second)
{
assert(VALID(first));
assert(VALID(second));
if (VALID(first) && VALID(second))
{
return (0 == strncmp(first, second, max));
}
return FALSE;
}
/*************************************************************************
* StrEqualMax
*/
int StrEqualMax(const char *first, size_t max, const char *second)
{
assert(VALID(first));
assert(VALID(second));
if (VALID(first) && VALID(second))
{
#if defined(USE_STRNCASECMP)
return (0 == strncasecmp(first, second, max));
#else
/* Not adequately tested yet */
size_t cnt = 0;
while ((*first != NIL) && (*second != NIL) && (cnt <= max))
{
if (toupper(*first) != toupper(*second))
{
break;
}
first++;
second++;
cnt++;
}
return ((cnt == max) || ((*first == NIL) && (*second == NIL)));
#endif
}
return FALSE;
}
/*************************************************************************
* StrError
*/
const char *StrError(int errorNumber)
{
#if defined(USE_STRERROR)
return strerror(errorNumber);
#else
return "unknown";
#endif
}
/*************************************************************************
* StrFormatDate
*/
size_t StrFormatDateMax(char *target,
size_t max,
const char *format,
const struct tm *datetime)
{
assert(VALID(target));
assert(VALID(format));
assert(VALID(datetime));
assert(max > 0);
return strftime(target, max, format, datetime);
}
/*************************************************************************
* StrHash
*/
unsigned long StrHash(const char *string, int type)
{
unsigned long value = 0L;
char ch;
assert(VALID(string));
switch (type)
{
case STRIO_HASH_PLAIN:
while ( (ch = *string++) != NIL )
{
value *= 31;
value += (unsigned long)ch;
}
break;
default:
assert(FALSE);
break;
}
return value;
}
/*************************************************************************
* StrMatch
*/
int StrMatch(char *string, char *pattern)
{
assert(VALID(string));
assert(VALID(pattern));
for (; ('*' != *pattern); ++pattern, ++string)
{
if (NIL == *string)
{
return (NIL == *pattern);
}
if ((toupper(*string) != toupper(*pattern))
&& ('?' != *pattern))
{
return FALSE;
}
}
/* two-line patch to prevent *too* much recursiveness: */
while ('*' == pattern[1])
pattern++;
do
{
if ( StrMatch(string, &pattern[1]) )
{
return TRUE;
}
}
while (*string++);
return FALSE;
}
/*************************************************************************
* StrMatchCase
*/
int StrMatchCase(char *string, char *pattern)
{
assert(VALID(string));
assert(VALID(pattern));
for (; ('*' != *pattern); ++pattern, ++string)
{
if (NIL == *string)
{
return (NIL == *pattern);
}
if ((*string != *pattern)
&& ('?' != *pattern))
{
return FALSE;
}
}
/* two-line patch to prevent *too* much recursiveness: */
while ('*' == pattern[1])
pattern++;
do
{
if ( StrMatchCase(string, &pattern[1]) )
{
return TRUE;
}
}
while (*string++);
return FALSE;
}
/*************************************************************************
* StrSpanFunction
*
* Untested
*/
size_t StrSpanFunction(char *source, int (*Function)(int))
{
size_t count = 0;
assert(VALID(source));
assert(VALID(Function));
while (*source != NIL)
{
if (Function(*source))
break; /* while */
source++;
count++;
}
return count;
}
/*************************************************************************
* StrSubstringMax
*/
char *StrSubstringMax(const char *string, size_t max, const char *find)
{
size_t count;
size_t size;
char *result = NULL;
assert(VALID(string));
assert(VALID(find));
size = StrLength(find);
if (size >= max)
{
for (count = 0; count > max - size; count++)
{
if (StrEqualMax(find, size, &string[count]))
{
result = (char *)&string[count];
break;
}
}
}
return result;
}
/*************************************************************************
* StrToDouble
*
* double ::= [ <sign> ]
* ( <number> |
* <number> <decimal_point> <number> |
* <decimal_point> <number> )
* [ <exponential> [ <sign> ] <number> ]
* number ::= 1*( <digit> )
* digit ::= ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' )
* exponential ::= ( 'e' | 'E' )
* sign ::= ( '-' | '+' )
* decimal_point ::= '.'
*/
double StrToDouble(const char *source, const char **endp)
{
#if defined(TRIO_C99)
return strtod(source, endp);
#else
/* Preliminary code */
int isNegative = FALSE;
int isExponentNegative = FALSE;
unsigned long integer = 0;
unsigned long fraction = 0;
unsigned long fracdiv = 1;
unsigned long exponent = 0;
double value = 0.0;
/* First try hex-floats */
if ((source[0] == '0') && ((source[1] == 'x') || (source[1] == 'X')))
{
source += 2;
while (isxdigit((int)*source))
{
integer *= 16;
integer += (isdigit((int)*source) ? (*source - '0') :
(isupper((int)*source) ? (*source - 'A') :
(*source - 'a')));
source++;
}
if (*source == '.')
{
source++;
while (isxdigit((int)*source))
{
fraction *= 16;
fraction += (isdigit((int)*source) ? (*source - '0') :
(isupper((int)*source) ? (*source - 'A') :
(*source - 'a')));
fracdiv *= 16;
source++;
}
if ((*source == 'p') || (*source == 'P'))
{
source++;
if ((*source == '+') || (*source == '-'))
{
isExponentNegative = (*source == '-');
source++;
}
while (isdigit((int)*source))
{
exponent *= 10;
exponent += (*source - '0');
source++;
}
}
}
}
else /* Then try normal decimal floats */
{
isNegative = (*source == '-');
/* Skip sign */
if ((*source == '+') || (*source == '-'))
source++;
/* Integer part */
while (isdigit((int)*source))
{
integer *= 10;
integer += (*source - '0');
source++;
}
if (*source == '.')
{
source++; /* skip decimal point */
while (isdigit((int)*source))
{
fraction *= 10;
fraction += (*source - '0');
fracdiv *= 10;
source++;
}
}
if ((*source == 'e') || (*source == 'E'))
{
source++; /* Skip exponential indicator */
isExponentNegative = (*source == '-');
if ((*source == '+') || (*source == '-'))
source++;
while (isdigit((int)*source))
{
exponent *= 10;
exponent += (*source - '0');
source++;
}
}
}
value = (double)integer;
if (fraction != 0)
{
value += (double)fraction / (double)fracdiv;
}
if (exponent != 0)
{
if (isExponentNegative)
value /= pow((double)10, (double)exponent);
else
value *= pow((double)10, (double)exponent);
}
if (isNegative)
value = -value;
if (endp)
*endp = source;
return value;
#endif
}
/*************************************************************************
* StrToFloat
*/
float StrToFloat(const char *source, const char **endp)
{
#if defined(TRIO_C99)
return strtof(source, endp);
#else
return (float)StrToDouble(source, endp);
#endif
}
/*************************************************************************
* StrToUpper
*/
int StrToUpper(char *target)
{
int i = 0;
assert(VALID(target));
while (NIL != *target)
{
*target = toupper(*target);
target++;
i++;
}
return i;
}
/* DV for libxml */
#endif /* WITH_TRIO */

216
strio.h Normal file
View File

@ -0,0 +1,216 @@
/*************************************************************************
*
* $Id$
*
* Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
* CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
*
************************************************************************/
#ifndef H_STRIO
#define H_STRIO
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "assert.h"
/*
* StrAppend(target, source)
* StrAppendMax(target, maxsize, source)
*
* Append 'source' to 'target'
*
* target = StrAlloc(size)
*
* Allocate a new string
*
* StrContains(target, substring)
*
* Find out if the string 'substring' is
* contained in the string 'target'
*
* StrCopy(target, source)
* StrCopyMax(target, maxsize, source)
*
* Copy 'source' to 'target'
*
* target = StrDuplicate(source)
* target = StrDuplicateMax(source, maxsize)
*
* Allocate and copy 'source' to 'target'
*
* StrEqual(first, second)
* StrEqualMax(first, maxsize, second)
*
* Compare if 'first' is equal to 'second'.
* Case-independent.
*
* StrEqualCase(first, second)
* StrEqualCaseMax(first, maxsize, second)
*
* Compare if 'first' is equal to 'second'
* Case-dependent. Please note that the use of the
* word 'case' has the opposite meaning as that of
* strcasecmp().
*
* StrFormat(target, format, ...)
* StrFormatMax(target, maxsize, format, ...)
*
* Build 'target' according to 'format' and succesive
* arguments. This is equal to the sprintf() and
* snprintf() functions.
*
* StrFormatDate(target, format, ...)
*
* StrFree(target)
*
* De-allocates a string
*
* StrHash(string, type)
*
* Calculates the hash value of 'string' based on the
* 'type'.
*
* StrIndex(target, character)
* StrIndexLast(target, character)
*
* Find the first/last occurrence of 'character' in
* 'target'
*
* StrLength(target)
*
* Return the length of 'target'
*
* StrMatch(string, pattern)
* StrMatchCase(string, pattern)
*
* Find 'pattern' within 'string'. 'pattern' may contain
* wildcards such as * (asterics) and ? (question mark)
* which matches zero or more characters and exactly
* on character respectively
*
* StrScan(source, format, ...)
*
* Equal to sscanf()
*
* StrSubstring(target, substring)
*
* Find the first occurrence of the string 'substring'
* within the string 'target'
*
* StrTokenize(target, list)
*
* Split 'target' into the first token delimited by
* one of the characters in 'list'. If 'target' is
* NULL then next token will be returned.
*
* StrToUpper(target)
*
* Convert all lower case characters in 'target' into
* upper case characters.
*/
enum {
STRIO_HASH_NONE = 0,
STRIO_HASH_PLAIN,
STRIO_HASH_TWOSIGNED
};
#if !defined(DEBUG) || defined(__DECC)
#define StrAppend(x,y) strcat((x), (y))
#define StrAlloc(n) ((char *)calloc(1, (n)))
#define StrContains(x,y) (0 != strstr((x), (y)))
#define StrCopy(x,y) strcpy((x), (y))
#define StrFree(x) free((x))
#define StrIndex(x,y) strchr((x), (y))
#define StrIndexLast(x,y) strrchr((x), (y))
#define StrLength(x) strlen((x))
#define StrSubstring(x,y) strstr((x), (y))
#define StrTokenize(x,y) strtok((x), (y))
#define StrToLong(x,y,n) strtol((x), (y), (n))
#define StrToUnsignedLong(x,y,n) strtoul((x), (y), (n))
#else /* DEBUG */
/*
* To be able to use these macros everywhere, including in
* if() sentences, the assertions are put first in a comma
* seperated list.
*
* Unfortunately the DECC compiler does not seem to like this
* so it will use the un-asserted functions above for the
* debugging case too.
*/
#define StrAppend(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
strcat((x), (y)))
#define StrAlloc(n) \
(assert((n) > 0),\
((char *)calloc(1, (n))))
#define StrContains(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
(0 != strstr((x), (y))))
#define StrCopy(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
strcpy((x), (y)))
#define StrIndex(x,c) \
(assert((x) != NULL),\
strchr((x), (c)))
#define StrIndexLast(x,c) \
(assert((x) != NULL),\
strrchr((x), (c)))
#define StrFree(x) \
(assert((x) != NULL),\
free((x)))
#define StrLength(x) \
(assert((x) != NULL),\
strlen((x)))
#define StrSubstring(x,y) \
(assert((x) != NULL),\
assert((y) != NULL),\
strstr((x), (y)))
#define StrTokenize(x,y) \
(assert((y) != NULL),\
strtok((x), (y)))
#define StrToLong(x,y,n) \
(assert((x) != NULL),\
assert((y) != NULL),\
assert((n) >= 2 && (n) <= 36),\
strtol((x), (y), (n)))
#define StrToUnsignedLong(x,y,n) \
(assert((x) != NULL),\
assert((y) != NULL),\
assert((n) >= 2 && (n) <= 36),\
strtoul((x), (y), (n)))
#endif /* DEBUG */
char *StrAppendMax(char *target, size_t max, const char *source);
char *StrCopyMax(char *target, size_t max, const char *source);
char *StrDuplicate(const char *source);
char *StrDuplicateMax(const char *source, size_t max);
int StrEqual(const char *first, const char *second);
int StrEqualCase(const char *first, const char *second);
int StrEqualCaseMax(const char *first, size_t max, const char *second);
int StrEqualMax(const char *first, size_t max, const char *second);
const char *StrError(int);
size_t StrFormatDateMax(char *target, size_t max, const char *format, const struct tm *datetime);
unsigned long StrHash(const char *string, int type);
int StrMatch(char *string, char *pattern);
int StrMatchCase(char *string, char *pattern);
size_t StrSpanFunction(char *source, int (*Function)(int));
char *StrSubstringMax(const char *string, size_t max, const char *find);
float StrToFloat(const char *source, const char **target);
double StrToDouble(const char *source, const char **target);
int StrToUpper(char *target);
#endif /* H_STRIO */

13
tree.c
View File

@ -213,7 +213,6 @@ xmlFreeNs(xmlNsPtr cur) {
}
if (cur->href != NULL) xmlFree((char *) cur->href);
if (cur->prefix != NULL) xmlFree((char *) cur->prefix);
MEM_CLEANUP(cur, sizeof(xmlNs));
xmlFree(cur);
}
@ -446,7 +445,6 @@ xmlFreeDtd(xmlDtdPtr cur) {
if (cur->pentities != NULL)
xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->pentities);
MEM_CLEANUP(cur, sizeof(xmlDtd));
xmlFree(cur);
}
@ -508,7 +506,6 @@ xmlFreeDoc(xmlDocPtr cur) {
if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids);
if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs);
if (cur->URL != NULL) xmlFree((char *) cur->URL);
MEM_CLEANUP(cur, sizeof(xmlDoc));
xmlFree(cur);
}
@ -1133,7 +1130,6 @@ xmlFreeProp(xmlAttrPtr cur) {
xmlRemoveID(cur->parent->doc, cur);
if (cur->name != NULL) xmlFree((char *) cur->name);
if (cur->children != NULL) xmlFreeNodeList(cur->children);
MEM_CLEANUP(cur, sizeof(xmlAttr));
xmlFree(cur);
}
@ -2329,7 +2325,6 @@ xmlFreeNode(xmlNodePtr cur) {
(cur->name != xmlStringComment))
xmlFree((char *) cur->name);
if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef);
MEM_CLEANUP(cur, sizeof(xmlNode));
xmlFree(cur);
}
@ -4511,14 +4506,8 @@ xmlBufferFree(xmlBufferPtr buf) {
return;
}
if (buf->content != NULL) {
#ifndef XML_USE_BUFFER_CONTENT
MEM_CLEANUP(buf->content, BASE_BUFFER_SIZE);
#else
MEM_CLEANUP(buf->content, buf->size);
#endif
xmlFree(buf->content);
}
MEM_CLEANUP(buf, sizeof(xmlBuffer));
xmlFree(buf);
}
@ -4532,7 +4521,7 @@ void
xmlBufferEmpty(xmlBufferPtr buf) {
if (buf->content == NULL) return;
buf->use = 0;
MEM_CLEANUP(buf->content, buf->size);
memset(buf->content, 0, buf->size);
}
/**

3719
trio.c Normal file

File diff suppressed because it is too large Load Diff

118
trio.h Normal file
View File

@ -0,0 +1,118 @@
/*************************************************************************
*
* $Id$
*
* Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
* CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
*
************************************************************************/
#ifndef H_TRIO
#define H_TRIO
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
/*
* Error codes.
*
* Remember to add a textual description to trio_strerror.
*/
enum {
TRIO_EOF = 1,
TRIO_EINVAL = 2,
TRIO_ETOOMANY = 3,
TRIO_EDBLREF = 4,
TRIO_EGAP = 5,
TRIO_ENOMEM = 6,
TRIO_ERANGE = 7
};
/* Error macros */
#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
#define TRIO_ERROR_NAME(x) trio_strerror(x)
/*
* trio_sprintf(target, format, ...)
* trio_snprintf(target, maxsize, format, ...)
*
* Build 'target' according to 'format' and succesive
* arguments. This is equal to the sprintf() and
* snprintf() functions.
*/
int trio_printf(const char *format, ...);
int trio_vprintf(const char *format, va_list args);
int trio_fprintf(FILE *file, const char *format, ...);
int trio_vfprintf(FILE *file, const char *format, va_list args);
int trio_dprintf(int fd, const char *format, ...);
int trio_vdprintf(int fd, const char *format, va_list args);
int trio_sprintf(char *buffer, const char *format, ...);
int trio_snprintf(char *buffer, size_t max, const char *format, ...);
int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
int trio_vsprintf(char *buffer, const char *format, va_list args);
int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
va_list args);
int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
va_list args);
char *trio_aprintf(const char *format, ...);
char *trio_vaprintf(const char *format, va_list args);
int trio_asprintf(char **ret, const char *format, ...);
int trio_vasprintf(char **ret, const char *format, va_list args);
int trio_scanf(const char *format, ...);
int trio_vscanf(const char *format, va_list args);
int trio_fscanf(FILE *file, const char *format, ...);
int trio_vfscanf(FILE *file, const char *format, va_list args);
int trio_dscanf(int fd, const char *format, ...);
int trio_vdscanf(int fd, const char *format, va_list args);
int trio_sscanf(const char *buffer, const char *format, ...);
int trio_vsscanf(const char *buffer, const char *format, va_list args);
const char *trio_strerror(int);
#ifdef TRIO_REPLACE_STDIO
/* Replace the <stdio.h> functions */
#define printf trio_printf
#define vprintf trio_vprintf
#define fprintf trio_fprintf
#define vfprintf trio_vfprintf
#define sprintf trio_sprintf
#define vsprintf trio_vsprintf
#define snprintf trio_snprintf
#define vsnprintf trio_vsnprintf
#define scanf trio_scanf
#define vscanf trio_vscanf
#define fscanf trio_fscanf
#define vfscanf trio_vfscanf
#define sscanf trio_sscanf
#define vsscanf trio_vsscanf
/* These aren't stdio functions, but we make them look similar */
#define dprintf trio_dprintf
#define vdprintf trio_vdprintf
#define aprintf trio_aprintf
#define vaprintf trio_vaprintf
#define asprintf trio_asprintf
#define vasprintf trio_vasprintf
#define dscanf trio_dscanf
#define vdscanf trio_vdscanf
#endif
/* strio compatible names */
#define StrScan sscanf /* FIXME: must be trio_sscanf */
#define StrFormat trio_sprintf
#define StrFormatMax trio_snprintf
#define StrFormatAlloc trio_aprintf
#define StrFormatAppendMax trio_snprintfcat
#endif /* H_TRIO */

1
uri.c
View File

@ -596,7 +596,6 @@ xmlFreeURI(xmlURIPtr uri) {
if (uri->opaque != NULL) xmlFree(uri->opaque);
if (uri->authority != NULL) xmlFree(uri->authority);
if (uri->query != NULL) xmlFree(uri->query);
MEM_CLEANUP(uri, sizeof(xmlURI));
xmlFree(uri);
}

24
valid.c
View File

@ -321,7 +321,6 @@ xmlFreeElementContent(xmlElementContentPtr cur) {
if (cur->c1 != NULL) xmlFreeElementContent(cur->c1);
if (cur->c2 != NULL) xmlFreeElementContent(cur->c2);
if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
MEM_CLEANUP(cur, sizeof(xmlElementContent));
xmlFree(cur);
}
@ -486,7 +485,6 @@ xmlFreeElement(xmlElementPtr elem) {
xmlFree((xmlChar *) elem->name);
if (elem->prefix != NULL)
xmlFree((xmlChar *) elem->prefix);
MEM_CLEANUP(elem, sizeof(xmlElement));
xmlFree(elem);
}
@ -781,7 +779,6 @@ xmlFreeEnumeration(xmlEnumerationPtr cur) {
if (cur->next != NULL) xmlFreeEnumeration(cur->next);
if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
MEM_CLEANUP(cur, sizeof(xmlEnumeration));
xmlFree(cur);
}
@ -941,7 +938,6 @@ xmlFreeAttribute(xmlAttributePtr attr) {
xmlFree((xmlChar *) attr->defaultValue);
if (attr->prefix != NULL)
xmlFree((xmlChar *) attr->prefix);
MEM_CLEANUP(attr, sizeof(xmlAttribute));
xmlFree(attr);
}
@ -1289,7 +1285,6 @@ xmlFreeNotation(xmlNotationPtr nota) {
xmlFree((xmlChar *) nota->PublicID);
if (nota->SystemID != NULL)
xmlFree((xmlChar *) nota->SystemID);
MEM_CLEANUP(nota, sizeof(xmlNotation));
xmlFree(nota);
}
@ -1494,7 +1489,6 @@ xmlFreeID(xmlIDPtr id) {
if (id == NULL) return;
if (id->value != NULL)
xmlFree((xmlChar *) id->value);
MEM_CLEANUP(id, sizeof(xmlID));
xmlFree(id);
}
@ -1732,7 +1726,6 @@ xmlFreeRef(xmlLinkPtr lk) {
if (ref == NULL) return;
if (ref->value != NULL)
xmlFree((xmlChar *)ref->value);
MEM_CLEANUP(ref, sizeof(xmlRef));
xmlFree(ref);
}
@ -2580,12 +2573,8 @@ xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem,
if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) {
xmlChar qname[500];
#ifdef HAVE_SNPRINTF
snprintf((char *) qname, sizeof(qname), "%s:%s",
elem->ns->prefix, elem->name);
#else
sprintf((char *) qname, "%s:%s", elem->ns->prefix, elem->name);
#endif
qname[sizeof(qname) - 1] = 0;
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, qname, name);
if ((attrDecl == NULL) && (doc->extSubset != NULL))
@ -2857,12 +2846,8 @@ xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) {
xmlChar qname[500];
#ifdef HAVE_SNPRINTF
snprintf((char *) qname, sizeof(qname), "%s:%s",
elem->ns->prefix, elem->name);
#else
sprintf((char *) qname, "%s:%s", elem->ns->prefix, elem->name);
#endif
qname[sizeof(qname) - 1] = 0;
if (attr->ns != NULL) {
attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, qname,
@ -3460,13 +3445,8 @@ xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
name = child->name;
if ((child->ns != NULL) && (child->ns->prefix != NULL)) {
xmlChar qname[500];
#ifdef HAVE_SNPRINTF
snprintf((char *) qname, sizeof(qname), "%s:%s",
child->ns->prefix, child->name);
#else
sprintf((char *) qname, "%s:%s",
child->ns->prefix, child->name);
#endif
qname[sizeof(qname) - 1] = 0;
cont = elemDecl->content;
while (cont != NULL) {
@ -3649,12 +3629,8 @@ xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
if (!xmlStrEqual(doc->intSubset->name, root->name)) {
if ((root->ns != NULL) && (root->ns->prefix != NULL)) {
xmlChar qname[500];
#ifdef HAVE_SNPRINTF
snprintf((char *) qname, sizeof(qname), "%s:%s",
root->ns->prefix, root->name);
#else
sprintf((char *) qname, "%s:%s", root->ns->prefix, root->name);
#endif
qname[sizeof(qname) - 1] = 0;
if (xmlStrEqual(doc->intSubset->name, qname))
goto name_ok;

View File

@ -281,7 +281,6 @@ xmlXIncludeFreeContext(xmlXIncludeCtxtPtr ctxt) {
xmlFree(ctxt->txtTab);
if (ctxt->txturlTab != NULL)
xmlFree(ctxt->txturlTab);
MEM_CLEANUP(ctxt, sizeof(xmlXIncludeCtxt));
xmlFree(ctxt);
}

View File

@ -163,13 +163,8 @@ xlinkIsLink (xmlDocPtr doc, xmlNodePtr node) {
ret = XLINK_TYPE_EXTENDED_SET;
} else {
xmlChar buf[200];
#ifdef HAVE_SNPRINTF
snprintf((char *) buf, sizeof(buf), "%s:external-linkset",
(char *) xlink->prefix);
#else
sprintf((char *) buf, "%s:external-linkset",
(char *) xlink->prefix);
#endif
buf[sizeof(buf) - 1] = 0;
if (xmlStrEqual(role, buf))
ret = XLINK_TYPE_EXTENDED_SET;

View File

@ -825,7 +825,6 @@ xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) {
in->buffer = NULL;
}
MEM_CLEANUP(in, (size_t) sizeof(xmlParserInputBuffer));
xmlFree(in);
}
@ -862,7 +861,6 @@ xmlOutputBufferClose(xmlOutputBufferPtr out) {
out->buffer = NULL;
}
MEM_CLEANUP(out, (size_t) sizeof(xmlOutputBuffer));
xmlFree(out);
return(written);
}

View File

@ -283,9 +283,12 @@ void
xmlMemFree(void *ptr)
{
MEMHDR *p;
char *target;
TEST_POINT
target = (char *) ptr;
p = CLIENT_2_HDR(ptr);
if (p->mh_tag != MEMTAG) {
Mem_Tag_Err(p);
@ -293,6 +296,7 @@ xmlMemFree(void *ptr)
}
p->mh_tag = ~MEMTAG;
debugMemSize -= p->mh_size;
memset(target, -1, p->mh_size);
#ifdef MEM_LIST
debugmem_list_delete(p);

View File

@ -26,6 +26,7 @@
#ifdef DEBUG_MEMORY_LOCATION
#define MEM_LIST /* keep a list of all the allocated memory blocks */
#define DEBUG_MEMORY_FREED
#endif
#ifdef DEBUG_MEMORY_FREED

View File

@ -23,6 +23,15 @@ extern void xmlCheckVersion(int version);
#define LIBXML_VERSION_STRING "@LIBXML_VERSION_NUMBER@"
#define LIBXML_TEST_VERSION xmlCheckVersion(@LIBXML_VERSION_NUMBER@);
/*
* Whether the trio support need to be configured in
*/
#if @WITH_TRIO@
#define WITH_TRIO
#else
#define WITHOUT_TRIO
#endif
/*
* Whether the FTP support is configured in
*/

17
xpath.c
View File

@ -327,10 +327,8 @@ xmlXPathFreeCompExpr(xmlXPathCompExprPtr comp) {
xmlFree(op->value5);
}
if (comp->steps != NULL) {
MEM_CLEANUP(comp->steps, sizeof(xmlXPathStepOp));
xmlFree(comp->steps);
}
MEM_CLEANUP(comp, sizeof(xmlXPathCompExpr));
xmlFree(comp);
}
@ -1488,10 +1486,8 @@ void
xmlXPathFreeNodeSet(xmlNodeSetPtr obj) {
if (obj == NULL) return;
if (obj->nodeTab != NULL) {
MEM_CLEANUP(obj->nodeTab, (size_t) sizeof(xmlNodePtr) * obj->nodeMax);
xmlFree(obj->nodeTab);
}
MEM_CLEANUP(obj, (size_t) sizeof(xmlNodeSet));
xmlFree(obj);
}
@ -1512,10 +1508,8 @@ xmlXPathFreeValueTree(xmlNodeSetPtr obj) {
xmlFreeNodeList(obj->nodeTab[i]);
if (obj->nodeTab != NULL) {
MEM_CLEANUP(obj->nodeTab, (size_t) sizeof(xmlNodePtr) * obj->nodeMax);
xmlFree(obj->nodeTab);
}
MEM_CLEANUP(obj, (size_t) sizeof(xmlNodeSet));
xmlFree(obj);
}
@ -1673,7 +1667,6 @@ xmlXPathWrapNodeSet(xmlNodeSetPtr val) {
void
xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj) {
if (obj == NULL) return;
MEM_CLEANUP(obj, (size_t) sizeof(xmlXPathObject));
xmlFree(obj);
}
@ -2190,7 +2183,6 @@ xmlXPathFreeObject(xmlXPathObjectPtr obj) {
xmlXPathFreeValueTree(obj->nodesetval);
}
MEM_CLEANUP(obj, (size_t) sizeof(xmlXPathObject));
xmlFree(obj);
}
@ -2256,7 +2248,6 @@ xmlXPathFreeContext(xmlXPathContextPtr ctxt) {
xmlXPathRegisteredNsCleanup(ctxt);
xmlXPathRegisteredFuncsCleanup(ctxt);
xmlXPathRegisteredVariablesCleanup(ctxt);
MEM_CLEANUP(ctxt, (size_t) sizeof(xmlXPathContext));
xmlFree(ctxt);
}
@ -2374,12 +2365,10 @@ xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctxt) {
void
xmlXPathFreeParserContext(xmlXPathParserContextPtr ctxt) {
if (ctxt->valueTab != NULL) {
MEM_CLEANUP(ctxt->valueTab, 10 * (size_t) sizeof(xmlXPathObjectPtr));
xmlFree(ctxt->valueTab);
}
if (ctxt->comp)
xmlXPathFreeCompExpr(ctxt->comp);
MEM_CLEANUP(ctxt, (size_t) sizeof(xmlXPathParserContext));
xmlFree(ctxt);
}
@ -4430,15 +4419,9 @@ xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) {
else {
char name[2000];
#ifdef HAVE_SNPRINTF
snprintf(name, sizeof(name), "%s:%s",
(char *) cur->nodesetval->nodeTab[i]->ns->prefix,
(char *) cur->nodesetval->nodeTab[i]->name);
#else
sprintf(name, "%s:%s",
(char *) cur->nodesetval->nodeTab[i]->ns->prefix,
(char *) cur->nodesetval->nodeTab[i]->name);
#endif
name[sizeof(name) - 1] = 0;
valuePush(ctxt, xmlXPathNewCString(name));
}

View File

@ -715,11 +715,8 @@ xmlXPtrFreeLocationSet(xmlLocationSetPtr obj) {
for (i = 0;i < obj->locNr; i++) {
xmlXPathFreeObject(obj->locTab[i]);
}
MEM_CLEANUP(obj->locTab,
(size_t) sizeof(xmlXPathObjectPtr) * obj->locMax);
xmlFree(obj->locTab);
}
MEM_CLEANUP(obj, (size_t) sizeof(xmlLocationSet));
xmlFree(obj);
}