diff --git a/ChangeLog b/ChangeLog index 6b1604ec..ade40f77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Sep 25 16:23:58 CEST 2003 Daniel Veillard + + * configure.in: preparing a beta3 solving the ABI problems + * globals.c parser.c parserInternals.c testHTML.c HTMLparser.c SAX.c + include/libxml/globals.h include/libxml/SAX.h: make sure the + global variables for the default SAX handler are V1 ones to + avoid ABI compat problems. + * xmlreader.c: cleanup of uneeded code + * hash.c: fix a comment + Thu Sep 25 14:16:51 CEST 2003 Daniel Veillard * SAX2.c hash.c parser.c include/libxml/xmlexports.h diff --git a/HTMLparser.c b/HTMLparser.c index 90e2460e..d2cba584 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -4102,10 +4102,10 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ctxt->nameMax = 10; ctxt->name = NULL; - if (sax == NULL) ctxt->sax = &htmlDefaultSAXHandler; + if (sax == NULL) ctxt->sax = (xmlSAXHandlerPtr) &htmlDefaultSAXHandler; else { ctxt->sax = sax; - memcpy(sax, &htmlDefaultSAXHandler, sizeof(htmlSAXHandler)); + memcpy(sax, &htmlDefaultSAXHandler, sizeof(xmlSAXHandlerV1)); } ctxt->userData = ctxt; ctxt->myDoc = NULL; @@ -5175,7 +5175,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data, if(enc==XML_CHAR_ENCODING_UTF8 || buf->encoder) ctxt->charset=XML_CHAR_ENCODING_UTF8; if (sax != NULL) { - if (ctxt->sax != &htmlDefaultSAXHandler) + if (ctxt->sax != (xmlSAXHandlerPtr) &htmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = (htmlSAXHandlerPtr) xmlMalloc(sizeof(htmlSAXHandler)); if (ctxt->sax == NULL) { diff --git a/SAX.c b/SAX.c index ad7d6eff..417e450a 100644 --- a/SAX.c +++ b/SAX.c @@ -620,7 +620,7 @@ cdataBlock(void *ctx, const xmlChar *value, int len) * DEPRECATED: use xmlSAX2InitDefaultSAXHandler() for the new SAX2 blocks */ void -initxmlDefaultSAXHandler(xmlSAXHandler *hdlr, int warning) +initxmlDefaultSAXHandler(xmlSAXHandlerV1 *hdlr, int warning) { if(hdlr->initialized == 1) @@ -669,7 +669,7 @@ initxmlDefaultSAXHandler(xmlSAXHandler *hdlr, int warning) * DEPRECATED: use xmlSAX2InitHtmlDefaultSAXHandler() for the new SAX2 blocks */ void -inithtmlDefaultSAXHandler(xmlSAXHandler *hdlr) +inithtmlDefaultSAXHandler(xmlSAXHandlerV1 *hdlr) { if(hdlr->initialized == 1) return; @@ -717,7 +717,7 @@ inithtmlDefaultSAXHandler(xmlSAXHandler *hdlr) * DEPRECATED: use xmlSAX2InitDocbDefaultSAXHandler() for the new SAX2 blocks */ void -initdocbDefaultSAXHandler(xmlSAXHandler *hdlr) +initdocbDefaultSAXHandler(xmlSAXHandlerV1 *hdlr) { if(hdlr->initialized == 1) return; diff --git a/SAX2.c b/SAX2.c index df1c67ec..ead3d33a 100644 --- a/SAX2.c +++ b/SAX2.c @@ -2412,17 +2412,6 @@ xmlSAXDefaultVersion(int version) if ((version != 1) && (version != 2)) return(-1); xmlSAX2DefaultVersionValue = version; - if (version == 1) { - xmlDefaultSAXHandler.startElement = xmlSAX2StartElement; - xmlDefaultSAXHandler.endElement = xmlSAX2EndElement; - xmlDefaultSAXHandler.startElementNs = NULL; - xmlDefaultSAXHandler.endElementNs = NULL; - } else if (version == 2) { - xmlDefaultSAXHandler.startElement = NULL; - xmlDefaultSAXHandler.endElement = NULL; - xmlDefaultSAXHandler.startElementNs = xmlSAX2StartElementNs; - xmlDefaultSAXHandler.endElementNs = xmlSAX2EndElementNs; - } return(ret); } @@ -2442,13 +2431,13 @@ xmlSAXVersion(xmlSAXHandler *hdlr, int version) if (version == 1) { hdlr->startElement = xmlSAX2StartElement; hdlr->endElement = xmlSAX2EndElement; - hdlr->startElementNs = NULL; - hdlr->endElementNs = NULL; + hdlr->initialized = 1; } else if (version == 2) { hdlr->startElement = NULL; hdlr->endElement = NULL; hdlr->startElementNs = xmlSAX2StartElementNs; hdlr->endElementNs = xmlSAX2EndElementNs; + hdlr->initialized = XML_SAX2_MAGIC; } else return(-1); hdlr->internalSubset = xmlSAX2InternalSubset; @@ -2477,7 +2466,6 @@ xmlSAXVersion(xmlSAXHandler *hdlr, int version) hdlr->error = xmlParserError; hdlr->fatalError = xmlParserError; - hdlr->initialized = XML_SAX2_MAGIC; return(0); } @@ -2509,8 +2497,7 @@ xmlSAX2InitDefaultSAXHandler(xmlSAXHandler *hdlr, int warning) void xmlDefaultSAXHandlerInit(void) { - xmlSAX2InitDefaultSAXHandler(&xmlDefaultSAXHandler, - xmlGetWarningsDefaultValue); + xmlSAXVersion((xmlSAXHandlerPtr) &xmlDefaultSAXHandler, 1); } #ifdef LIBXML_HTML_ENABLED @@ -2555,7 +2542,7 @@ xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr) hdlr->error = xmlParserError; hdlr->fatalError = xmlParserError; - hdlr->initialized = XML_SAX2_MAGIC; + hdlr->initialized = 1; } /** @@ -2566,7 +2553,7 @@ xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr) void htmlDefaultSAXHandlerInit(void) { - xmlSAX2InitHtmlDefaultSAXHandler(&htmlDefaultSAXHandler); + xmlSAX2InitHtmlDefaultSAXHandler((xmlSAXHandlerPtr) &htmlDefaultSAXHandler); } #endif /* LIBXML_HTML_ENABLED */ @@ -2624,7 +2611,7 @@ xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr) void docbDefaultSAXHandlerInit(void) { - xmlSAX2InitDocbDefaultSAXHandler(&docbDefaultSAXHandler); + xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler); } #endif /* LIBXML_DOCB_ENABLED */ diff --git a/configure.in b/configure.in index e8de6d06..320784de 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ AC_CANONICAL_HOST LIBXML_MAJOR_VERSION=2 LIBXML_MINOR_VERSION=6 LIBXML_MICRO_VERSION=0 -LIBXML_MICRO_VERSION_SUFFIX=beta2 +LIBXML_MICRO_VERSION_SUFFIX=beta3 LIBXML_VERSION=$LIBXML_MAJOR_VERSION.$LIBXML_MINOR_VERSION.$LIBXML_MICRO_VERSION$LIBXML_MICRO_VERSION_SUFFIX LIBXML_VERSION_INFO=`expr $LIBXML_MAJOR_VERSION + $LIBXML_MINOR_VERSION`:$LIBXML_MICRO_VERSION:$LIBXML_MINOR_VERSION diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index a2a64577..0d5779eb 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -62,6 +62,7 @@ + @@ -99,6 +100,8 @@ + + @@ -783,7 +786,6 @@ - @@ -2374,6 +2376,7 @@ + Whether the automata interfaces are compiled in Whether the Canonicalization support is configured in @@ -2408,8 +2411,10 @@ Whether ISO-8859-* support is made available in case iconv is not + Whether the regular expressions interfaces are compiled in + Whether the Schemas validation interfaces are compiled in Macro to check that the libxml version in use is compatible with the version the software has been compiled against @@ -2418,6 +2423,7 @@ Whether the thread support is configured in + Whether the Unicode related interfaces are compiled in the version number: 1.2.3 value is 1002003 @@ -2452,6 +2458,7 @@ + Macros which declare the called convention for exported functions Windows platform with MS compiler Windows platform with Borland compiler Windows platform with GNU compiler (Mingw) Cygwin platform, GNU compiler @@ -2561,8 +2568,6 @@ Macro to raise an XPath error and return 0. - - @@ -3316,9 +3321,9 @@ actually an xmlCharEncoding'/> - - - + + + @@ -3610,6 +3615,37 @@ actually an xmlCharEncoding'/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3879,12 +3915,12 @@ actually an xmlCharEncoding'/> - - + + - + @@ -4584,17 +4620,17 @@ actually an xmlCharEncoding'/> Initialize the default DocBook SAX version 1 handler DEPRECATED: use xmlSAX2InitDocbDefaultSAXHandler() for the new SAX2 blocks - + Initialize the default HTML SAX version 1 handler DEPRECATED: use xmlSAX2InitHtmlDefaultSAXHandler() for the new SAX2 blocks - + Initialize the default XML SAX version 1 handler DEPRECATED: use xmlSAX2InitDefaultSAXHandler() for the new SAX2 blocks - + @@ -6515,13 +6551,13 @@ actually an xmlCharEncoding'/> - - - - - + Find the userdata specified by the QNames tuple + + + + - + Find the userdata specified by the (@name, @name2, @name3) tuple. @@ -8941,8 +8977,8 @@ actually an xmlCharEncoding'/> - - + + @@ -9573,15 +9609,15 @@ actually an xmlCharEncoding'/> - - - - - - - - - + Takes a entity string content and process to do the adequate substitutions. [67] Reference ::= EntityRef | CharRef [69] PEReference ::= '%' Name ';' + + + + + + + + Parse the value string and build the node list associated. Should produce a flat tree with only TEXTs and ENTITY_REFs. @@ -9712,9 +9748,9 @@ actually an xmlCharEncoding'/> - - - + The xml:lang scope within which the node resides. + + Hacking interface allowing to get the xmlDocPtr correponding to the current document being accessed by the xmlTextReader. This is dangerous because the associated node may be destroyed on the next Reads. diff --git a/globals.c b/globals.c index 2d68dbf1..bdbbc376 100644 --- a/globals.c +++ b/globals.c @@ -62,7 +62,7 @@ void xmlCleanupGlobals() * Memory allocation routines */ #if defined(DEBUG_MEMORY_LOCATION) || defined(DEBUG_MEMORY) -#ifndef _DEBUG_MEMORY_ALLOC_ +#ifndef __DEBUG_MEMORY_ALLOC__ extern void xmlMemFree(void *ptr); extern void * xmlMemMalloc(size_t size); extern void * xmlMemRealloc(void *ptr,size_t size); @@ -328,9 +328,9 @@ int xmlSaveNoEmptyTagsThrDef = 0; /** * xmlDefaultSAXHandler: * - * Default handler for XML, builds the DOM tree + * Default SAX version1 handler for XML, builds the DOM tree */ -xmlSAXHandler xmlDefaultSAXHandler = { +xmlSAXHandlerV1 xmlDefaultSAXHandler = { xmlSAX2InternalSubset, xmlSAX2IsStandalone, xmlSAX2HasInternalSubset, @@ -359,9 +359,6 @@ xmlSAXHandler xmlDefaultSAXHandler = { xmlSAX2CDataBlock, xmlSAX2ExternalSubset, 0, - NULL, - NULL, - NULL }; /** @@ -381,9 +378,9 @@ xmlSAXLocator xmlDefaultSAXLocator = { /** * htmlDefaultSAXHandler: * - * Default handler for HTML, builds the DOM tree + * Default old SAX v1 handler for HTML, builds the DOM tree */ -xmlSAXHandler htmlDefaultSAXHandler = { +xmlSAXHandlerV1 htmlDefaultSAXHandler = { xmlSAX2InternalSubset, NULL, NULL, @@ -412,9 +409,6 @@ xmlSAXHandler htmlDefaultSAXHandler = { xmlSAX2CDataBlock, NULL, 0, - NULL, - NULL, - NULL }; #endif /* LIBXML_HTML_ENABLED */ @@ -422,9 +416,9 @@ xmlSAXHandler htmlDefaultSAXHandler = { /** * docbDefaultSAXHandler: * - * Default handler for SGML DocBook, builds the DOM tree + * Default old SAX v1 handler for SGML DocBook, builds the DOM tree */ -xmlSAXHandler docbDefaultSAXHandler = { +xmlSAXHandlerV1 docbDefaultSAXHandler = { xmlSAX2InternalSubset, xmlSAX2IsStandalone, xmlSAX2HasInternalSubset, @@ -453,9 +447,6 @@ xmlSAXHandler docbDefaultSAXHandler = { NULL, NULL, 0, - NULL, - NULL, - NULL }; #endif /* LIBXML_DOCB_ENABLED */ @@ -483,16 +474,16 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs) xmlMutexLock(xmlThrDefMutex); #ifdef LIBXML_DOCB_ENABLED - xmlSAX2InitDocbDefaultSAXHandler(&gs->docbDefaultSAXHandler); + initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler); #endif #ifdef LIBXML_HTML_ENABLED - xmlSAX2InitHtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler); + inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler); #endif gs->oldXMLWDcompatibility = 0; gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef; gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef; - xmlSAX2InitDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1); + initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1); gs->xmlDefaultSAXLocator.getPublicId = getPublicId; gs->xmlDefaultSAXLocator.getSystemId = getSystemId; gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber; @@ -613,7 +604,7 @@ xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func) #ifdef LIBXML_DOCB_ENABLED #undef docbDefaultSAXHandler -xmlSAXHandler * +xmlSAXHandlerV1 * __docbDefaultSAXHandler(void) { if (IS_MAIN_THREAD) return (&docbDefaultSAXHandler); @@ -624,7 +615,7 @@ __docbDefaultSAXHandler(void) { #ifdef LIBXML_HTML_ENABLED #undef htmlDefaultSAXHandler -xmlSAXHandler * +xmlSAXHandlerV1 * __htmlDefaultSAXHandler(void) { if (IS_MAIN_THREAD) return (&htmlDefaultSAXHandler); @@ -684,7 +675,7 @@ int xmlThrDefDefaultBufferSize(int v) { } #undef xmlDefaultSAXHandler -xmlSAXHandler * +xmlSAXHandlerV1 * __xmlDefaultSAXHandler(void) { if (IS_MAIN_THREAD) return (&xmlDefaultSAXHandler); diff --git a/hash.c b/hash.c index 9f1d3bbf..3fb8552d 100644 --- a/hash.c +++ b/hash.c @@ -427,7 +427,7 @@ xmlHashQLookup(xmlHashTablePtr table, const xmlChar *prefix, * @table: the hash table * @prefix: the prefix of the userdata * @name: the name of the userdata - * @prefix: the second prefix of the userdata + * @prefix2: the second prefix of the userdata * @name2: a second name of the userdata * * Find the userdata specified by the QNames tuple diff --git a/include/libxml/SAX.h b/include/libxml/SAX.h index 7e5db2ea..a9f1c451 100644 --- a/include/libxml/SAX.h +++ b/include/libxml/SAX.h @@ -1,5 +1,5 @@ /* - * SAX.h : Default SAX handler interfaces. + * SAX.h : Old SAX vewrsion1 handler interfaces. * * See Copyright for the status of this software. * @@ -19,6 +19,39 @@ #ifdef __cplusplus extern "C" { #endif +typedef struct _xmlSAXHandlerV1 xmlSAXHandlerV1; +typedef xmlSAXHandlerV1 *xmlSAXHandlerV1Ptr; +struct _xmlSAXHandlerV1 { + internalSubsetSAXFunc internalSubset; + isStandaloneSAXFunc isStandalone; + hasInternalSubsetSAXFunc hasInternalSubset; + hasExternalSubsetSAXFunc hasExternalSubset; + resolveEntitySAXFunc resolveEntity; + getEntitySAXFunc getEntity; + entityDeclSAXFunc entityDecl; + notationDeclSAXFunc notationDecl; + attributeDeclSAXFunc attributeDecl; + elementDeclSAXFunc elementDecl; + unparsedEntityDeclSAXFunc unparsedEntityDecl; + setDocumentLocatorSAXFunc setDocumentLocator; + startDocumentSAXFunc startDocument; + endDocumentSAXFunc endDocument; + startElementSAXFunc startElement; + endElementSAXFunc endElement; + referenceSAXFunc reference; + charactersSAXFunc characters; + ignorableWhitespaceSAXFunc ignorableWhitespace; + processingInstructionSAXFunc processingInstruction; + commentSAXFunc comment; + warningSAXFunc warning; + errorSAXFunc error; + fatalErrorSAXFunc fatalError; /* unused error() get all the errors */ + getParameterEntitySAXFunc getParameterEntity; + cdataBlockSAXFunc cdataBlock; + externalSubsetSAXFunc externalSubset; + unsigned int initialized; +}; + XMLPUBFUN const xmlChar * XMLCALL getPublicId (void *ctx); XMLPUBFUN const xmlChar * XMLCALL @@ -147,15 +180,15 @@ XMLPUBFUN void XMLCALL int len); XMLPUBFUN void XMLCALL - initxmlDefaultSAXHandler (xmlSAXHandler *hdlr, + initxmlDefaultSAXHandler (xmlSAXHandlerV1 *hdlr, int warning); #ifdef LIBXML_HTML_ENABLED XMLPUBFUN void XMLCALL - inithtmlDefaultSAXHandler (xmlSAXHandler *hdlr); + inithtmlDefaultSAXHandler (xmlSAXHandlerV1 *hdlr); #endif #ifdef LIBXML_DOCB_ENABLED XMLPUBFUN void XMLCALL - initdocbDefaultSAXHandler (xmlSAXHandler *hdlr); + initdocbDefaultSAXHandler (xmlSAXHandlerV1 *hdlr); #endif #ifdef __cplusplus } diff --git a/include/libxml/globals.h b/include/libxml/globals.h index 9fe77c88..6004269a 100644 --- a/include/libxml/globals.h +++ b/include/libxml/globals.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -70,9 +71,9 @@ struct _xmlGlobalState const char *xmlParserVersion; xmlSAXLocator xmlDefaultSAXLocator; - xmlSAXHandler xmlDefaultSAXHandler; - xmlSAXHandler docbDefaultSAXHandler; - xmlSAXHandler htmlDefaultSAXHandler; + xmlSAXHandlerV1 xmlDefaultSAXHandler; + xmlSAXHandlerV1 docbDefaultSAXHandler; + xmlSAXHandlerV1 htmlDefaultSAXHandler; xmlFreeFunc xmlFree; xmlMallocFunc xmlMalloc; @@ -183,22 +184,22 @@ XMLPUBVAR xmlStrdupFunc xmlMemStrdup; #endif /* LIBXML_THREAD_ALLOC_ENABLED */ #ifdef LIBXML_DOCB_ENABLED -XMLPUBFUN xmlSAXHandler * XMLCALL __docbDefaultSAXHandler(void); +XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __docbDefaultSAXHandler(void); #ifdef LIBXML_THREAD_ENABLED #define docbDefaultSAXHandler \ (*(__docbDefaultSAXHandler())) #else -XMLPUBVAR xmlSAXHandler docbDefaultSAXHandler; +XMLPUBVAR xmlSAXHandlerV1 docbDefaultSAXHandler; #endif #endif #ifdef LIBXML_HTML_ENABLED -XMLPUBFUN xmlSAXHandler * XMLCALL __htmlDefaultSAXHandler(void); +XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __htmlDefaultSAXHandler(void); #ifdef LIBXML_THREAD_ENABLED #define htmlDefaultSAXHandler \ (*(__htmlDefaultSAXHandler())) #else -XMLPUBVAR xmlSAXHandler htmlDefaultSAXHandler; +XMLPUBVAR xmlSAXHandlerV1 htmlDefaultSAXHandler; #endif #endif @@ -236,12 +237,12 @@ XMLPUBVAR int xmlDefaultBufferSize; #endif XMLPUBFUN int XMLCALL xmlThrDefDefaultBufferSize(int v); -XMLPUBFUN xmlSAXHandler * XMLCALL __xmlDefaultSAXHandler(void); +XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __xmlDefaultSAXHandler(void); #ifdef LIBXML_THREAD_ENABLED #define xmlDefaultSAXHandler \ (*(__xmlDefaultSAXHandler())) #else -XMLPUBVAR xmlSAXHandler xmlDefaultSAXHandler; +XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler; #endif XMLPUBFUN xmlSAXLocator * XMLCALL __xmlDefaultSAXLocator(void); diff --git a/parser.c b/parser.c index 30bd308f..6ebe1e58 100644 --- a/parser.c +++ b/parser.c @@ -3491,6 +3491,8 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { } COPY_BUF(l,buf,nbchar,cur); if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) { + buf[nbchar] = 0; + /* * OK the segment is to be consumed as chars. */ @@ -3515,6 +3517,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { cur = CUR_CHAR(l); } if (nbchar != 0) { + buf[nbchar] = 0; /* * OK the segment is to be consumed as chars. */ @@ -10092,7 +10095,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, return(NULL); } if (sax != NULL) { - if (ctxt->sax != &xmlDefaultSAXHandler) + if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); if (ctxt->sax == NULL) { @@ -10185,7 +10188,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, return(NULL); } if (sax != NULL) { - if (ctxt->sax != &xmlDefaultSAXHandler) + if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); if (ctxt->sax == NULL) { @@ -11506,7 +11509,7 @@ xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, ctxt = xmlCreateFileParserCtxt(filename); if (ctxt == NULL) return -1; - if (ctxt->sax != &xmlDefaultSAXHandler) + if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) xmlFree(ctxt->sax); ctxt->sax = sax; xmlDetectSAX2(ctxt); diff --git a/parserInternals.c b/parserInternals.c index 02071b7b..5a9c8e05 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -2219,7 +2219,7 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt) return(-1); } else - memcpy(ctxt->sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler)); + xmlSAXVersion(ctxt->sax, 2); ctxt->maxatts = 0; ctxt->atts = NULL; @@ -2371,7 +2371,8 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding); if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI); if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem); - if ((ctxt->sax != NULL) && (ctxt->sax != &xmlDefaultSAXHandler)) + if ((ctxt->sax != NULL) && + (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)) xmlFree(ctxt->sax); if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory); if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab); diff --git a/testHTML.c b/testHTML.c index e0e5d3d8..f48612d8 100644 --- a/testHTML.c +++ b/testHTML.c @@ -75,7 +75,10 @@ xmlSAXHandler emptySAXHandlerStruct = { NULL, /* getParameterEntity */ NULL, /* cdataBlock */ NULL, /* externalSubset */ - 1 + 1, + NULL, + NULL, + NULL }; xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; @@ -595,7 +598,10 @@ xmlSAXHandler debugSAXHandlerStruct = { getParameterEntityDebug, cdataDebug, NULL, - 1 + 1, + NULL, + NULL, + NULL }; xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; diff --git a/xmlreader.c b/xmlreader.c index 91509320..c7a576bc 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -143,348 +143,6 @@ static const char *xmlTextReaderIsEmpty = "This element is empty"; #define CONSTSTR(str) xmlDictLookup(reader->ctxt->dict, (str), -1) #define CONSTQSTR(p, str) xmlDictQLookup(reader->ctxt->dict, (p), (str)) -/************************************************************************ - * * - * Our own version of the freeing routines as we recycle nodes * - * * - ************************************************************************/ - -static void xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur); -static void xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur); - -/** - * xmlTextReaderFreeEntityWrapper: - * @entity: An entity - * @name: its name - * - * Deallocate the memory used by an entities in the hash table. - */ -static void -xmlTextReaderFreeEntityWrapper(xmlEntityPtr entity, - const xmlChar *name ATTRIBUTE_UNUSED) { - if (entity == NULL) return; - - if ((entity->children) && (entity->owner == 1) && - (entity == (xmlEntityPtr) entity->children->parent)) { - xmlDocPtr doc; - xmlTextReaderPtr reader = NULL; - doc = entity->doc; - if (doc != NULL) - reader = doc->_private; - xmlTextReaderFreeNodeList(reader, entity->children); - } - if (entity->name != NULL) - xmlFree((char *) entity->name); - if (entity->ExternalID != NULL) - xmlFree((char *) entity->ExternalID); - if (entity->SystemID != NULL) - xmlFree((char *) entity->SystemID); - if (entity->URI != NULL) - xmlFree((char *) entity->URI); - if (entity->content != NULL) - xmlFree((char *) entity->content); - if (entity->orig != NULL) - xmlFree((char *) entity->orig); - xmlFree(entity); -} - -/** - * xmlTextReaderFreeEntitiesTable: - * @table: An entity table - * - * Deallocate the memory used by an entities hash table. - */ -static void -xmlTextReaderFreeEntitiesTable(xmlEntitiesTablePtr table) { - xmlHashFree(table, (xmlHashDeallocator) xmlTextReaderFreeEntityWrapper); -} - -/** - * xmlTextReaderFreeDtd: - * @cur: the DTD structure to free up - * - * Free a DTD structure. - */ -static void -xmlTextReaderFreeDtd(xmlTextReaderPtr reader, xmlDtdPtr cur) { - if (cur == NULL) return; - - if (cur->children != NULL) { - xmlNodePtr next, c = cur->children; - - /* - * Cleanup all the DTD comments they are not in the DTD - * indexes. - */ - while (c != NULL) { - next = c->next; - if ((c->type == XML_COMMENT_NODE) || (c->type == XML_PI_NODE)) { - xmlUnlinkNode(c); - xmlTextReaderFreeNode(reader, c); - } - c = next; - } - } - - if (cur->name != NULL) xmlFree((char *) cur->name); - if (cur->SystemID != NULL) xmlFree((char *) cur->SystemID); - if (cur->ExternalID != NULL) xmlFree((char *) cur->ExternalID); - /* TODO !!! */ - if (cur->notations != NULL) - xmlFreeNotationTable((xmlNotationTablePtr) cur->notations); - - if (cur->elements != NULL) - xmlFreeElementTable((xmlElementTablePtr) cur->elements); - if (cur->attributes != NULL) - xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes); - if (cur->pentities != NULL) - xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->pentities); - - if (cur->entities != NULL) - xmlTextReaderFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities); - - xmlFree(cur); -} - -/** - * xmlTextReaderFreeProp: - * @reader: the xmlTextReaderPtr used - * @cur: the node - * - * Free a node. - */ -static void -xmlTextReaderFreeProp(xmlTextReaderPtr reader, xmlAttrPtr cur) { - if (cur == NULL) return; - - /* Check for ID removal -> leading to invalid references ! */ - if ((cur->parent != NULL) && (cur->parent->doc != NULL) && - ((cur->parent->doc->intSubset != NULL) || - (cur->parent->doc->extSubset != NULL))) { - if (xmlIsID(cur->parent->doc, cur->parent, cur)) - xmlRemoveID(cur->parent->doc, cur); - } - if (cur->children != NULL) - xmlTextReaderFreeNodeList(reader, cur->children); - - if ((reader != NULL) && (reader->ctxt != NULL) && - (xmlDictOwns(reader->ctxt->dict, cur->name) != 1) && - (cur->name != NULL)) - xmlFree((xmlChar *)cur->name); - if ((reader != NULL) && (reader->ctxt != NULL) && - (reader->ctxt->freeAttrsNr < 100)) { - cur->next = reader->ctxt->freeAttrs; - reader->ctxt->freeAttrs = cur; - reader->ctxt->freeAttrsNr++; - } else { - xmlFree(cur); - } -} - -/** - * xmlTextReaderFreePropList: - * @reader: the xmlTextReaderPtr used - * @cur: the first property in the list - * - * Free a property and all its siblings, all the children are freed too. - */ -static void -xmlTextReaderFreePropList(xmlTextReaderPtr reader, xmlAttrPtr cur) { - xmlAttrPtr next; - if (cur == NULL) return; - while (cur != NULL) { - next = cur->next; - xmlTextReaderFreeProp(reader, cur); - cur = next; - } -} - -/** - * xmlTextReaderFreeNodeList: - * @reader: the xmlTextReaderPtr used - * @cur: the first node in the list - * - * Free a node and all its siblings, this is a recursive behaviour, all - * the children are freed too. - */ -static void -xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur) { - xmlNodePtr next; - if (cur == NULL) return; - if (cur->type == XML_NAMESPACE_DECL) { - xmlFreeNsList((xmlNsPtr) cur); - return; - } - if ((cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - xmlFreeDoc((xmlDocPtr) cur); - return; - } - while (cur != NULL) { - next = cur->next; - /* unroll to speed up freeing the document */ - if (cur->type != XML_DTD_NODE) { - - if ((cur->children != NULL) && - (cur->type != XML_ENTITY_REF_NODE)) - xmlTextReaderFreeNodeList(reader, cur->children); - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_XINCLUDE_START) || - (cur->type == XML_XINCLUDE_END)) && - (cur->properties != NULL)) - xmlTextReaderFreePropList(reader, cur->properties); - if ((cur->type != XML_ELEMENT_NODE) && - (cur->type != XML_XINCLUDE_START) && - (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_ENTITY_REF_NODE)) { - if (cur->content != NULL) xmlFree(cur->content); - } - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_XINCLUDE_START) || - (cur->type == XML_XINCLUDE_END)) && - (cur->nsDef != NULL)) - xmlFreeNsList(cur->nsDef); - - /* - * we don't free element names here they are interned now - */ - if (cur->type == XML_ELEMENT_NODE) { - if ((reader != NULL) && (reader->ctxt != NULL) && - (xmlDictOwns(reader->ctxt->dict, cur->name) != 1) && - (cur->name != NULL)) - xmlFree((xmlChar *)cur->name); - } else if ((cur->type != XML_TEXT_NODE) && - (cur->type != XML_COMMENT_NODE) && - (cur->name != NULL)) - xmlFree((xmlChar *)cur->name); - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_TEXT_NODE)) && - (reader != NULL) && (reader->ctxt != NULL) && - (reader->ctxt->freeElemsNr < 100)) { - cur->next = reader->ctxt->freeElems; - reader->ctxt->freeElems = cur; - reader->ctxt->freeElemsNr++; - } else { - xmlFree(cur); - } - } - cur = next; - } -} - -/** - * xmlTextReaderFreeNode: - * @reader: the xmlTextReaderPtr used - * @cur: the node - * - * Free a node, this is a recursive behaviour, all the children are freed too. - * This doesn't unlink the child from the list, use xmlUnlinkNode() first. - */ -static void -xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur) { - if (cur->type == XML_DTD_NODE) { - xmlTextReaderFreeDtd(reader, (xmlDtdPtr) cur); - return; - } - if (cur->type == XML_NAMESPACE_DECL) { - xmlFreeNs((xmlNsPtr) cur); - return; - } - if (cur->type == XML_ATTRIBUTE_NODE) { - xmlTextReaderFreeProp(reader, (xmlAttrPtr) cur); - return; - } - - if ((cur->children != NULL) && - (cur->type != XML_ENTITY_REF_NODE)) - xmlTextReaderFreeNodeList(reader, cur->children); - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_XINCLUDE_START) || - (cur->type == XML_XINCLUDE_END)) && - (cur->properties != NULL)) - xmlTextReaderFreePropList(reader, cur->properties); - if ((cur->type != XML_ELEMENT_NODE) && - (cur->type != XML_XINCLUDE_START) && - (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_ENTITY_REF_NODE)) { - if (cur->content != NULL) xmlFree(cur->content); - } - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_XINCLUDE_START) || - (cur->type == XML_XINCLUDE_END)) && - (cur->nsDef != NULL)) - xmlFreeNsList(cur->nsDef); - - /* - * we don't free names here they are interned now - */ - if (cur->type == XML_ELEMENT_NODE) { - if ((reader != NULL) && (reader->ctxt != NULL) && - (xmlDictOwns(reader->ctxt->dict, cur->name) != 1) && - (cur->name != NULL)) - xmlFree((xmlChar *)cur->name); - } else if ((cur->type != XML_TEXT_NODE) && - (cur->type != XML_COMMENT_NODE) && - (cur->name != NULL)) - xmlFree((xmlChar *)cur->name); - if (((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_TEXT_NODE)) && - (reader != NULL) && (reader->ctxt != NULL) && - (reader->ctxt->freeElemsNr < 100)) { - cur->next = reader->ctxt->freeElems; - reader->ctxt->freeElems = cur; - reader->ctxt->freeElemsNr++; - } else { - xmlFree(cur); - } - -} - -/** - * xmlTextReaderFreeDoc: - * @reader: the xmlTextReaderPtr used - * @cur: pointer to the document - * - * Free up all the structures used by a document, tree included. - */ -static void -xmlTextReaderFreeDoc(xmlTextReaderPtr reader, xmlDocPtr cur) { - xmlDtdPtr extSubset, intSubset; - - if (cur == NULL) return; - - /* - * Do this before freeing the children list to avoid ID lookups - */ - if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids); - cur->ids = NULL; - if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs); - cur->refs = NULL; - extSubset = cur->extSubset; - intSubset = cur->intSubset; - if (intSubset == extSubset) - extSubset = NULL; - if (extSubset != NULL) { - xmlUnlinkNode((xmlNodePtr) cur->extSubset); - cur->extSubset = NULL; - xmlTextReaderFreeDtd(reader, extSubset); - } - if (intSubset != NULL) { - xmlUnlinkNode((xmlNodePtr) cur->intSubset); - cur->intSubset = NULL; - xmlTextReaderFreeDtd(reader, intSubset); - } - - if (cur->children != NULL) xmlTextReaderFreeNodeList(reader, cur->children); - - if (cur->version != NULL) xmlFree((char *) cur->version); - if (cur->name != NULL) xmlFree((char *) cur->name); - if (cur->encoding != NULL) xmlFree((char *) cur->encoding); - if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); - if (cur->URL != NULL) xmlFree((char *) cur->URL); - xmlFree(cur); -} - /************************************************************************ * * * The reader core parser *