From bc50b59d362f76dda6ef69c872c38ab0d60312e7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 1 Mar 1999 12:28:53 +0000 Subject: [PATCH] Memory leak hunting, export more interfaces, updated the doc, Daniel. --- ChangeLog | 6 + doc/html/gnome-xml-parserinternals.html | 484 +++++++++++++++++++++--- doc/html/index.sgml | 4 + error.c | 16 +- include/libxml/parserInternals.h | 20 +- parser.c | 8 +- parserInternals.h | 20 +- 7 files changed, 487 insertions(+), 71 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58a38513..4986372d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Mar 1 13:27:17 CET 1999 Daniel Veillard + + * parser.c, parser.h, parserInternals.h: memory leak hunting, + exported the inputStream routines. + * doc/html/* : updated accordingly + Sun Feb 28 22:51:33 CET 1999 Daniel Veillard * parser.c, parser.h, parserInternals.h: added a few extra diff --git a/doc/html/gnome-xml-parserinternals.html b/doc/html/gnome-xml-parserinternals.html index df0e2faa..83c48027 100644 --- a/doc/html/gnome-xml-parserinternals.html +++ b/doc/html/gnome-xml-parserinternals.html @@ -126,6 +126,48 @@ HREF="gnome-xml-entities.html#XMLENTITYPTR" >xmlEntityPtr entity); xmlParserInputPtr xmlNewEntityInputStream (xmlParserCtxtPtr ctxt, + xmlEntityPtr entity); +void xmlPushInput (xmlParserCtxtPtr ctxt, + xmlParserInputPtr input); +CHAR xmlPopInput (xmlParserCtxtPtr ctxt); +void xmlFreeInputStream (xmlParserInputPtr input); +CHAR*

Description

Details







xmlNewEntityInputStream()

xmlParserInputPtr xmlNewEntityInputStream   (xmlParserCtxtPtr ctxt,
+                                             xmlEntityPtr entity);

Create a new input stream based on a memory buffer.

ctxt : 
entity : 
Returns : 


xmlPushInput()

void        xmlPushInput                    (xmlParserCtxtPtr ctxt,
+                                             xmlParserInputPtr input);

xmlPushInput: switch to a new input stream which is stacked on top +of the previous one(s).

ctxt : an XML parser context
input : an XML parser input fragment (entity, XML fragment ...).


xmlPopInput()

CHAR        xmlPopInput                     (xmlParserCtxtPtr ctxt);

xmlPopInput: the current input pointed by ctxt->input came to an end +pop it and return the next char.

TODO A deallocation of the popped Input structure is needed

ctxt : an XML parser context
Returns :the current CHAR in the parser context


xmlFreeInputStream()

void        xmlFreeInputStream              (xmlParserInputPtr input);

Free up an input stream.

input : an xmlParserInputPtr
















































+ + + + diff --git a/error.c b/error.c index 3a479ea1..a00c2a4b 100644 --- a/error.c +++ b/error.c @@ -40,10 +40,9 @@ xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) base = ctxt->input->base; while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { cur--; - base--; } n = 0; - while ((n++ < 60) && (cur > base) && (*cur != '\n') && (*cur != '\r')) + while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) cur--; if ((*cur == '\n') || (*cur == '\r')) cur++; base = cur; @@ -57,7 +56,7 @@ xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) while ((*cur == '\n') || (*cur == '\r')) cur--; n = 0; - while ((cur != base) && (n++ < 60)) { + while ((cur != base) && (n++ < 80)) { fprintf(stderr, " "); base++; } @@ -92,10 +91,13 @@ xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...) va_end(ap); cur = ctxt->input->cur; base = ctxt->input->base; + while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { + cur--; + } n = 0; - while ((n++ < 60) && (cur > base) && (*cur != '\n') && (*cur != '\r')) + while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) cur--; - if ((*cur != '\n') || (*cur != '\r')) cur++; + if ((*cur == '\n') || (*cur == '\r')) cur++; base = cur; n = 0; while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { @@ -104,8 +106,10 @@ xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...) } fprintf(stderr, "\n"); cur = ctxt->input->cur; + while ((*cur == '\n') || (*cur == '\r')) + cur--; n = 0; - while ((cur != base) && (n++ < 60)) { + while ((cur != base) && (n++ < 80)) { fprintf(stderr, " "); base++; } diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h index d28da73a..33d8a810 100644 --- a/include/libxml/parserInternals.h +++ b/include/libxml/parserInternals.h @@ -15,7 +15,7 @@ extern "C" { #endif -/* +/** * Parser context */ xmlParserCtxtPtr @@ -27,13 +27,25 @@ xmlCreateMemoryParserCtxt(char *buffer, int size); void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt); -/* +/** * Entities */ void xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); -/* +/** + * Input Streams + */ +xmlParserInputPtr +xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); +void +xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input); +CHAR +xmlPopInput(xmlParserCtxtPtr ctxt); +void +xmlFreeInputStream(xmlParserInputPtr input); + +/** * Namespaces. */ CHAR * @@ -47,7 +59,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt); void xmlParseNamespace(xmlParserCtxtPtr ctxt); -/* +/** * Generic production rules */ CHAR * diff --git a/parser.c b/parser.c index 4e10aa73..18051183 100644 --- a/parser.c +++ b/parser.c @@ -132,7 +132,7 @@ PUSH_AND_POP(xmlNodePtr, node) CHAR xmlPopInput(xmlParserCtxtPtr ctxt) { if (ctxt->inputNr == 1) return(0); /* End of main Input */ - inputPop(ctxt); + xmlFreeInputStream(inputPop(ctxt)); return(CUR); } @@ -160,7 +160,7 @@ void xmlFreeInputStream(xmlParserInputPtr input) { if (input == NULL) return; - if (input->filename != NULL) return; + if (input->filename != NULL) free((char *) input->filename); if ((input->free != NULL) && (input->base != NULL)) input->free((char *) input->base); memset(input, -1, sizeof(xmlParserInput)); @@ -3773,6 +3773,7 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { */ ret = xmlNewReference(ctxt->doc, val); xmlAddChild(ctxt->node, ret); + ret = NULL; } free(val); } @@ -3787,7 +3788,8 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { /* * Pop-up of finished entities. */ - while ((CUR == 0) && (ctxt->inputNr > 1)) xmlPopInput(ctxt); + while ((CUR == 0) && (ctxt->inputNr > 1)) + xmlPopInput(ctxt); if (test == CUR_PTR) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) diff --git a/parserInternals.h b/parserInternals.h index d28da73a..33d8a810 100644 --- a/parserInternals.h +++ b/parserInternals.h @@ -15,7 +15,7 @@ extern "C" { #endif -/* +/** * Parser context */ xmlParserCtxtPtr @@ -27,13 +27,25 @@ xmlCreateMemoryParserCtxt(char *buffer, int size); void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt); -/* +/** * Entities */ void xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); -/* +/** + * Input Streams + */ +xmlParserInputPtr +xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); +void +xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input); +CHAR +xmlPopInput(xmlParserCtxtPtr ctxt); +void +xmlFreeInputStream(xmlParserInputPtr input); + +/** * Namespaces. */ CHAR * @@ -47,7 +59,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt); void xmlParseNamespace(xmlParserCtxtPtr ctxt); -/* +/** * Generic production rules */ CHAR *