adding repeated parsing and validating tests make the new DOM tree
* Makefile.am: adding repeated parsing and validating tests
* SAX2.c parser.c tree.c include/libxml/parser.h: make the new
DOM tree building interfaces use the dictionary from the
parsing context to build the element and attributes names
as well as formatting spaces and short text nodes
* include/libxml/dict.h dict.c: added some reference counting
for xmlDictPtr because they can be shared by documents and
a parser context.
* xmlreader.c: a bit of cleanup, remove the specific tree freeing
functions and use the standard ones now.
* xmllint.c: add --nodict
* python/libxml.c: fix a stupid bug so that ns() works on
attribute nodes.
Daniel
diff --git a/parser.c b/parser.c
index deace02..eb3a8a0 100644
--- a/parser.c
+++ b/parser.c
@@ -11926,6 +11926,18 @@
************************************************************************/
/**
+ * DICT_FREE:
+ * @str: a string
+ *
+ * Free a string if it is not owned by the "dict" dictionnary in the
+ * current scope
+ */
+#define DICT_FREE(str) \
+ if ((str) && ((!dict) || \
+ (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
+ xmlFree((char *)(str));
+
+/**
* xmlCtxtReset:
* @ctxt: an XML parser context
*
@@ -11935,6 +11947,7 @@
xmlCtxtReset(xmlParserCtxtPtr ctxt)
{
xmlParserInputPtr input;
+ xmlDictPtr dict = ctxt->dict;
while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
xmlFreeInputStream(input);
@@ -11953,8 +11966,20 @@
ctxt->nameNr = 0;
ctxt->name = NULL;
+ DICT_FREE(ctxt->version);
ctxt->version = NULL;
+ DICT_FREE(ctxt->encoding);
ctxt->encoding = NULL;
+ DICT_FREE(ctxt->directory);
+ ctxt->directory = NULL;
+ DICT_FREE(ctxt->extSubURI);
+ ctxt->extSubURI = NULL;
+ DICT_FREE(ctxt->extSubSystem);
+ ctxt->extSubSystem = NULL;
+ if (ctxt->myDoc != NULL)
+ xmlFreeDoc(ctxt->myDoc);
+ ctxt->myDoc = NULL;
+
ctxt->standalone = -1;
ctxt->hasExternalSubset = 0;
ctxt->hasPErefs = 0;
@@ -11962,9 +11987,7 @@
ctxt->external = 0;
ctxt->instate = XML_PARSER_START;
ctxt->token = 0;
- ctxt->directory = NULL;
- ctxt->myDoc = NULL;
ctxt->wellFormed = 1;
ctxt->nsWellFormed = 1;
ctxt->valid = 1;
@@ -12064,6 +12087,12 @@
ctxt->sax->initialized = 1;
options -= XML_PARSE_SAX1;
}
+ if (options & XML_PARSE_NODICT) {
+ ctxt->dictNames = 0;
+ options -= XML_PARSE_NODICT;
+ } else {
+ ctxt->dictNames = 1;
+ }
return (options);
}
@@ -12096,11 +12125,25 @@
ret = ctxt->myDoc;
else {
ret = NULL;
- xmlFreeDoc(ctxt->myDoc);
- ctxt->myDoc = NULL;
+ if (ctxt->myDoc != NULL) {
+ ctxt->myDoc->dict = NULL;
+ xmlFreeDoc(ctxt->myDoc);
+ }
}
- if (!reuse)
+ ctxt->myDoc = NULL;
+ if (!reuse) {
+ if ((ctxt->dictNames) &&
+ (ret != NULL) &&
+ (ret->dict == ctxt->dict))
+ ctxt->dict = NULL;
xmlFreeParserCtxt(ctxt);
+ } else {
+ /* Must duplicate the reference to the dictionary */
+ if ((ctxt->dictNames) &&
+ (ret != NULL) &&
+ (ret->dict == ctxt->dict))
+ xmlDictReference(ctxt->dict);
+ }
return (ret);
}