mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-19 14:50:07 +03:00
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
This commit is contained in:
parent
e2811270e8
commit
1a380b8924
@ -1,3 +1,9 @@
|
||||
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 <filename> [ filename ... ]</usage>
|
||||
<test>reader4 test1.xml test2.xml test3.xml > 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><libxml/xmlreader.h></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'/>
|
||||
|
File diff suppressed because one or more lines are too long
122
doc/examples/reader4.c
Normal file
122
doc/examples/reader4.c
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user