Commit 1a380b89 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

fixed a memory bug added test from Graham Bennett and regenerated the

* xmlschemas.c: fixed a memory bug
* doc/examples/reader4.c doc/examples/*: added test from Graham Bennett
  and regenerated the directory
Daniel
parent e2811270
Thu Oct 21 18:03:21 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c: fixed a memory bug
* doc/examples/reader4.c doc/examples/*: added test from Graham Bennett
and regenerated the directory
Tue Oct 19 11:06:39 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
* include/libxml/xmlreader.h xmlreader.c: applied patch from
......
......@@ -15,3 +15,4 @@ parse3
parse4
io2
xpath2
reader4
......@@ -17,7 +17,7 @@ install-data-local:
EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml tst.xml reader1.res reader3.res tree1.res tree2.res io1.res io2.res xpath1.res xpath2.res
noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4 io2 xpath2
noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1 parse3 parse4 io2 xpath2 reader4
xpath1_SOURCES=xpath1.c
xpath1_LDFLAGS=
......@@ -89,6 +89,11 @@ xpath2_LDFLAGS=
xpath2_DEPENDENCIES= $(DEPS)
xpath2_LDADD= @RDL_LIBS@ $(LDADDS)
reader4_SOURCES=reader4.c
reader4_LDFLAGS=
reader4_DEPENDENCIES= $(DEPS)
reader4_LDADD= @RDL_LIBS@ $(LDADDS)
valgrind:
$(MAKE) CHECKER='valgrind -q' tests
......@@ -123,5 +128,7 @@ tests: $(noinst_PROGRAMS)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@($(CHECKER) ./xpath2 test3.xml '//discarded' discarded > xpath2.tmp ; diff xpath2.tmp xpath2.res ; rm xpath2.tmp)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
@($(CHECKER) ./reader4 test1.xml test2.xml test3.xml > reader4.tmp ; diff reader4.tmp reader4.res ; rm reader4.tmp)
@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
......@@ -364,6 +364,26 @@
<function line='94' file='parser' name='xmlParseFile'/>
</uses>
</example>
<example filename='reader4.c'>
<synopsis>Parse multiple XML files reusing an xmlReader</synopsis>
<purpose>Demonstrate the use of xmlReaderForFile() and xmlReaderNewFile to parse XML files while reusing the reader object and parser context. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
<usage>reader4 &lt;filename&gt; [ filename ... ]</usage>
<test>reader4 test1.xml test2.xml test3.xml &gt; reader4.tmp ; diff reader4.tmp reader4.res ; rm reader4.tmp</test>
<author>Graham Bennett</author>
<copy>see Copyright for the status of this software. </copy>
<section>xmlReader</section>
<includes>
<include>&lt;libxml/xmlreader.h&gt;</include>
</includes>
<uses>
<function line='104' file='xmlreader' name='xmlFreeTextReader'/>
<typedef line='54' file='xmlreader' name='xmlTextReaderPtr'/>
<function line='83' file='xmlreader' name='xmlReaderNewFile'/>
<function line='26' file='xmlreader' name='xmlTextReaderRead'/>
<function line='97' file='xmlreader' name='xmlTextReaderCurrentDoc'/>
<function line='72' file='xmlreader' name='xmlReaderForFile'/>
</uses>
</example>
<symbols>
<symbol name='LIBXML_TEST_VERSION'>
<ref filename='xpath1.c'/>
......@@ -474,6 +494,7 @@
<ref filename='reader1.c'/>
<ref filename='reader2.c'/>
<ref filename='reader3.c'/>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlFreeTextWriter'>
<ref filename='testWriter.c'/>
......@@ -564,6 +585,10 @@
<ref filename='reader1.c'/>
<ref filename='reader2.c'/>
<ref filename='reader3.c'/>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlReaderNewFile'>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlRealloc'>
<ref filename='testWriter.c'/>
......@@ -597,6 +622,7 @@
</symbol>
<symbol name='xmlTextReaderCurrentDoc'>
<ref filename='reader3.c'/>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlTextReaderDepth'>
<ref filename='reader1.c'/>
......@@ -624,11 +650,13 @@
<ref filename='reader1.c'/>
<ref filename='reader2.c'/>
<ref filename='reader3.c'/>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlTextReaderRead'>
<ref filename='reader1.c'/>
<ref filename='reader2.c'/>
<ref filename='reader3.c'/>
<ref filename='reader4.c'/>
</symbol>
<symbol name='xmlTextWriterEndDocument'>
<ref filename='testWriter.c'/>
......@@ -714,6 +742,7 @@
<example filename='reader1.c'/>
<example filename='reader2.c'/>
<example filename='reader3.c'/>
<example filename='reader4.c'/>
</section>
<section name='xmlWriter'>
<example filename='testWriter.c'/>
......
This diff is collapsed.
/**
* section: xmlReader
* synopsis: Parse multiple XML files reusing an xmlReader
* purpose: Demonstrate the use of xmlReaderForFile() and
* xmlReaderNewFile to parse XML files while reusing the reader object
* and parser context. (Note that the XMLReader functions require
* libxml2 version later than 2.6.)
* usage: reader4 <filename> [ filename ... ]
* test: reader4 test1.xml test2.xml test3.xml > reader4.tmp ; diff reader4.tmp reader4.res ; rm reader4.tmp
* author: Graham Bennett
* copy: see Copyright for the status of this software.
*/
#include <stdio.h>
#include <libxml/xmlreader.h>
#ifdef LIBXML_READER_ENABLED
static void processDoc(xmlTextReaderPtr readerPtr) {
int ret;
xmlDocPtr docPtr;
const xmlChar *URL;
ret = xmlTextReaderRead(readerPtr);
while (ret == 1) {
ret = xmlTextReaderRead(readerPtr);
}
/*
* One can obtain the document pointer to get insteresting
* information about the document like the URL, but one must also
* be sure to clean it up at the end (see below).
*/
docPtr = xmlTextReaderCurrentDoc(readerPtr);
if (NULL == docPtr) {
fprintf(stderr, "failed to obtain document\n");
return;
}
URL = docPtr->URL;
if (NULL == URL) {
fprintf(stderr, "Failed to obtain URL\n");
}
if (ret != 0) {
fprintf(stderr, "%s: Failed to parse\n", URL);
return;
}
printf("%s: Processed ok\n", (const char *)URL);
}
int main(int argc, char **argv) {
xmlTextReaderPtr readerPtr;
int i;
xmlDocPtr docPtr;
if (argc < 2)
return(1);
/*
* this initialises the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
/*
* Create a new reader for the first file and process the
* document.
*/
readerPtr = xmlReaderForFile(argv[1], NULL, 0);
if (NULL == readerPtr) {
fprintf(stderr, "%s: failed to create reader\n", argv[1]);
return(1);
}
processDoc(readerPtr);
/*
* The reader can be reused for subsequent files.
*/
for (i=2; i < argc; ++i) {
xmlReaderNewFile(readerPtr, argv[i], NULL, 0);
if (NULL == readerPtr) {
fprintf(stderr, "%s: failed to create reader\n", argv[i]);
return(1);
}
processDoc(readerPtr);
}
/*
* Since we've called xmlTextReaderCurrentDoc, we now have to
* clean up after ourselves. We only have to do this the last
* time, because xmlReaderNewFile calls xmlCtxtReset which takes
* care of it.
*/
docPtr = xmlTextReaderCurrentDoc(readerPtr);
if (docPtr != NULL)
xmlFreeDoc(docPtr);
/*
* Clean up the reader.
*/
xmlFreeTextReader(readerPtr);
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
return(0);
}
#else
int main(void) {
fprintf(stderr, "xmlReader support not compiled in\n");
exit(1);
}
#endif
......@@ -7748,6 +7748,8 @@ xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
xmlAttrPtr attr;
const xmlChar *attrValue;
xmlChar *des = NULL; /* The reported designation. */
char buf[40];
if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
return (NULL);
......@@ -7770,8 +7772,6 @@ xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
}
if (topLevel == 0) {
char buf[40];
/*
* Parse as local complex type definition.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment