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

final touch running DTD validation on the XmlTextReader added a specific

* valid.c xmlreader.c: final touch running DTD validation
  on the XmlTextReader
* python/tests/Makefile.am python/tests/reader2.py: added a
  specific run based on the examples from test/valid/*.xml
Daniel
This commit is contained in:
Daniel Veillard 2002-12-27 19:37:04 +00:00
parent f25b4cab44
commit 336fc7d3c9
5 changed files with 103 additions and 2 deletions

View File

@ -1,3 +1,10 @@
Fri Dec 27 20:35:15 CET 2002 Daniel Veillard <daniel@veillard.com>
* valid.c xmlreader.c: final touch running DTD validation
on the XmlTextReader
* python/tests/Makefile.am python/tests/reader2.py: added a
specific run based on the examples from test/valid/*.xml
Fri Dec 27 15:17:20 CET 2002 Daniel Veillard <daniel@veillard.com> Fri Dec 27 15:17:20 CET 2002 Daniel Veillard <daniel@veillard.com>
* python/libxml.py: added a few predefined xmlTextReader parser * python/libxml.py: added a few predefined xmlTextReader parser

View File

@ -20,7 +20,8 @@ PYTESTS= \
inbuf.py \ inbuf.py \
resolver.py \ resolver.py \
regexp.py \ regexp.py \
reader.py reader.py \
reader2.py
XMLS= \ XMLS= \
tst.xml \ tst.xml \

54
python/tests/reader2.py Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/python -u
#
# this tests the validation with the XmlTextReader interface
#
import sys
import glob
import string
import libxml2
# Memory debug specific
libxml2.debugMemory(1)
err=""
expect="""../../test/valid/xlink.xml:450: validity error: ID dt-arc already defined
<p><termdef id="dt-arc" term="Arc">
^
../../test/valid/xlink.xml:529: validity error: attribute def line 199 references an unknown ID "dt-xlg"
<?Pub *0000052575?>
^
../../test/valid/rss.xml:172: validity error: Element rss does not carry attribute version
</rss>
^
"""
def callback(ctx, str):
global err
err = err + "%s" % (str)
libxml2.registerErrorHandler(callback, "")
valid_files = files = glob.glob("../../test/valid/*.x*")
for file in valid_files:
if string.find(file, "t8") != -1:
continue
reader = libxml2.newTextReaderFilename(file)
#print "%s:" % (file)
reader.setParserProp(libxml2.PARSER_VALIDATE, 1)
ret = reader.read()
while ret == 1:
ret = reader.read()
if ret != 0:
print "Error parsing and validating %s" % (file)
#sys.exit(1)
if err != expect:
print err
del reader
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()

35
valid.c
View File

@ -100,7 +100,7 @@ static int
vstateVPop(xmlValidCtxtPtr ctxt) { vstateVPop(xmlValidCtxtPtr ctxt) {
xmlElementPtr elemDecl; xmlElementPtr elemDecl;
if (ctxt->vstateNr <= 1) return(-1); if (ctxt->vstateNr < 1) return(-1);
ctxt->vstateNr--; ctxt->vstateNr--;
elemDecl = ctxt->vstateTab[ctxt->vstateNr].elemDecl; elemDecl = ctxt->vstateTab[ctxt->vstateNr].elemDecl;
ctxt->vstateTab[ctxt->vstateNr].elemDecl = NULL; ctxt->vstateTab[ctxt->vstateNr].elemDecl = NULL;
@ -250,6 +250,39 @@ nodeVPop(xmlValidCtxtPtr ctxt)
return (ret); return (ret);
} }
#if 0
/**
* xmlFreeValidCtxt:
* @ctxt: a validation context
*
* Free the memory allocated for a validation context
*/
void
xmlFreeValidCtxt(xmlValidCtxtPtr ctxt) {
if (ctxt == NULL)
return;
#ifdef LIBXML_REGEXP_ENABLED
while (ctxt->vstateNr >= 0)
vstateVPop(ctxt);
if (ctxt->vstateNr <= 1) return(-1);
ctxt->vstateNr--;
elemDecl = ctxt->vstateTab[ctxt->vstateNr].elemDecl;
ctxt->vstateTab[ctxt->vstateNr].elemDecl = NULL;
ctxt->vstateTab[ctxt->vstateNr].node = NULL;
if ((elemDecl != NULL) && (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT)) {
xmlRegFreeExecCtxt(ctxt->vstateTab[ctxt->vstateNr].exec);
}
ctxt->vstateTab[ctxt->vstateNr].exec = NULL;
if (ctxt->vstateNr >= 1)
ctxt->vstate = &ctxt->vstateTab[ctxt->vstateNr - 1];
else
ctxt->vstate = NULL;
return(ctxt->vstateNr);
#else /* ! LIBXML_REGEXP_ENABLED */
#endif /* LIBXML_REGEXP_ENABLED */
}
#endif
#ifdef DEBUG_VALID_ALGO #ifdef DEBUG_VALID_ALGO
static void static void
xmlValidPrintNode(xmlNodePtr cur) { xmlValidPrintNode(xmlNodePtr cur) {

View File

@ -696,6 +696,12 @@ xmlFreeTextReader(xmlTextReaderPtr reader) {
xmlFreeDoc(reader->ctxt->myDoc); xmlFreeDoc(reader->ctxt->myDoc);
reader->ctxt->myDoc = NULL; reader->ctxt->myDoc = NULL;
} }
if ((reader->ctxt->vctxt.vstateTab != NULL) &&
(reader->ctxt->vctxt.vstateMax > 0)){
xmlFree(reader->ctxt->vctxt.vstateTab);
reader->ctxt->vctxt.vstateTab = 0;
reader->ctxt->vctxt.vstateMax = 0;
}
if (reader->allocs & XML_TEXTREADER_CTXT) if (reader->allocs & XML_TEXTREADER_CTXT)
xmlFreeParserCtxt(reader->ctxt); xmlFreeParserCtxt(reader->ctxt);
} }