From f88d8cf9f1c9538dba187290ad5add003dc22bc7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 8 Dec 2003 10:25:02 +0000 Subject: [PATCH] tried to fix the problems reported in bug #126735 fixed again some problem * python/libxml.py: tried to fix the problems reported in bug #126735 * xpath.c SAX2.c error.c parser.c valid.c include/libxml/xmlerror.h: fixed again some problem trying to use the structured error handlers, c.f. bug #126735 * result/VC/ElementValid: tiny change due to the fix Daniel --- ChangeLog | 9 +++++++ SAX2.c | 53 +++++++++++++++++++++++++++------------ error.c | 4 +-- include/libxml/xmlerror.h | 1 + parser.c | 2 +- python/libxml.py | 34 ++++++++++++++----------- result/VC/ElementValid | 2 +- valid.c | 2 +- xpath.c | 15 ++++++++--- 9 files changed, 83 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03bd7374..eb68d6bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Dec 8 11:08:45 CET 2003 Daniel Veillard + + * python/libxml.py: tried to fix the problems reported in + bug #126735 + * xpath.c SAX2.c error.c parser.c valid.c include/libxml/xmlerror.h: + fixed again some problem trying to use the structured error + handlers, c.f. bug #126735 + * result/VC/ElementValid: tiny change due to the fix + Sun Dec 7 22:27:31 CET 2003 Daniel Veillard * error.c: fixed __xmlRaiseError to use structured error handlers diff --git a/SAX2.c b/SAX2.c index 1841e50b..1971aba0 100644 --- a/SAX2.c +++ b/SAX2.c @@ -44,6 +44,37 @@ "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__); +/** + * xmlValidError: + * @ctxt: an XML validation parser context + * @error: the error number + * @msg: the error message + * @str1: extra data + * @str2: extra data + * + * Handle a validation error + */ +static void +xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const char *str1, const char *str2) +{ + xmlStructuredErrorFunc schannel = NULL; + + if ((ctxt != NULL) && (ctxt->disableSAX != 0) && + (ctxt->instate == XML_PARSER_EOF)) + return; + ctxt->errNo = error; + if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) + schannel = ctxt->sax->serror; + __xmlRaiseError(schannel, + ctxt->vctxt.error, ctxt->vctxt.userData, + ctxt, NULL, XML_FROM_DTD, error, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + (const char *) str2, NULL, 0, 0, + msg, (const char *) str1, (const char *) str2); + ctxt->valid = 0; +} + /** * xmlSAX2GetPublicId: * @ctx: the user data (XML parser context) @@ -1244,11 +1275,9 @@ process_external_subset: } } if (att == NULL) { - if (ctxt->vctxt.error != NULL) - ctxt->vctxt.error(ctxt->vctxt.userData, + xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED, "standalone: attribute %s on %s defaulted from external subset\n", - fulln, attr->elem); - ctxt->valid = 0; + fulln, attr->elem); } } attr = attr->nexth; @@ -1370,13 +1399,9 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) (ctxt->myDoc->intSubset->elements == NULL) && (ctxt->myDoc->intSubset->attributes == NULL) && (ctxt->myDoc->intSubset->entities == NULL)))) { - if (ctxt->vctxt.error != NULL) { - ctxt->vctxt.error(ctxt->vctxt.userData, - "Validation failed: no DTD found !\n"); - } + xmlErrValid(ctxt, XML_ERR_NO_DTD, + "Validation failed: no DTD found !", NULL, NULL); ctxt->validate = 0; - ctxt->valid = 0; - ctxt->errNo = XML_ERR_NO_DTD; } @@ -1947,13 +1972,9 @@ xmlSAX2StartElementNs(void *ctx, (ctxt->myDoc->intSubset->elements == NULL) && (ctxt->myDoc->intSubset->attributes == NULL) && (ctxt->myDoc->intSubset->entities == NULL)))) { - if (ctxt->vctxt.error != NULL) { - ctxt->vctxt.error(ctxt->vctxt.userData, - "Validation failed: no DTD found !\n"); - } + xmlErrValid(ctxt, XML_ERR_NO_DTD, + "Validation failed: no DTD found !", NULL, NULL); ctxt->validate = 0; - ctxt->valid = 0; - ctxt->errNo = XML_ERR_NO_DTD; } /* diff --git a/error.c b/error.c index 1e81b432..fb3c5a7f 100644 --- a/error.c +++ b/error.c @@ -454,9 +454,9 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) schannel = ctxt->sax->serror; - if (schannel == NULL) - schannel = xmlStructuredError; } + if (schannel == NULL) + schannel = xmlStructuredError; if ((domain == XML_FROM_VALID) && ((channel == xmlParserValidityError) || (channel == xmlParserValidityWarning))) { diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h index b32b5eb0..f1559f83 100644 --- a/include/libxml/xmlerror.h +++ b/include/libxml/xmlerror.h @@ -234,6 +234,7 @@ typedef enum { XML_DTD_UNKNOWN_ENTITY, /* 535 */ XML_DTD_UNKNOWN_ID, /* 536 */ XML_DTD_UNKNOWN_NOTATION, /* 537 */ + XML_DTD_STANDALONE_DEFAULTED, /* 538 */ XML_HTML_STRUCURE_ERROR = 800, XML_HTML_UNKNOWN_TAG, /* 801 */ XML_RNGP_ANYNAME_ATTR_ANCESTOR = 1000, diff --git a/parser.c b/parser.c index 5a970360..fde9bdfb 100644 --- a/parser.c +++ b/parser.c @@ -426,7 +426,7 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, * @msg: the error message * @str1: extra data * - * Handle a warning. + * Handle a validity error. */ static void xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error, diff --git a/python/libxml.py b/python/libxml.py index 41103c66..92c4c3cf 100644 --- a/python/libxml.py +++ b/python/libxml.py @@ -362,21 +362,25 @@ class xmlCore: ctxt.xpathFreeContext() return res - # - # Selecting nodes using XPath, faster because the context - # is allocated just once per xmlDoc. - # +# # +# # Selecting nodes using XPath, faster because the context +# # is allocated just once per xmlDoc. +# # +# # Removed: DV memleaks c.f. #126735 +# # +# def xpathEval2(self, expr): +# doc = self.doc +# if doc == None: +# return None +# try: +# doc._ctxt.setContextNode(self) +# except: +# doc._ctxt = doc.xpathNewContext() +# doc._ctxt.setContextNode(self) +# res = doc._ctxt.xpathEval(expr) +# return res def xpathEval2(self, expr): - doc = self.doc - if doc == None: - return None - try: - doc._ctxt.setContextNode(self) - except: - doc._ctxt = doc.xpathNewContext() - doc._ctxt.setContextNode(self) - res = doc._ctxt.xpathEval(expr) - return res + return self.xpathEval(expr) # support for python2 iterators def walk_depth_first(self): @@ -390,7 +394,7 @@ class xmlCore: self.doc._ctxt.xpathFreeContext() except: pass - libxml2mod.freeDoc(self._o) + libxml2mod.xmlFreeDoc(self._o) # diff --git a/result/VC/ElementValid b/result/VC/ElementValid index f9372b39..d6b50a76 100644 --- a/result/VC/ElementValid +++ b/result/VC/ElementValid @@ -1,3 +1,3 @@ -./test/VC/ElementValid:3: validity error: Validation failed: no DTD found ! +./test/VC/ElementValid:3: validity error : Validation failed: no DTD found ! ^ diff --git a/valid.c b/valid.c index 9fb9b693..3c518d64 100644 --- a/valid.c +++ b/valid.c @@ -81,7 +81,7 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra) * Handle a validation error */ static void -xmlErrValid(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlParserErrors error, +xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error, const char *msg, const char *extra) { xmlGenericErrorFunc channel = NULL; diff --git a/xpath.c b/xpath.c index fd974981..9d7187d8 100644 --- a/xpath.c +++ b/xpath.c @@ -271,9 +271,7 @@ xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra) void xmlXPathErr(xmlXPathParserContextPtr ctxt, int error) { - if (ctxt != NULL) - ctxt->error = error; - if ((ctxt == NULL) || (ctxt->context == NULL)) { + if (ctxt == NULL) { __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_XPATH, error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, @@ -282,6 +280,17 @@ xmlXPathErr(xmlXPathParserContextPtr ctxt, int error) xmlXPathErrorMessages[error]); return; } + ctxt->error = error; + if (ctxt->context == NULL) { + __xmlRaiseError(NULL, NULL, NULL, + NULL, NULL, XML_FROM_XPATH, + error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, + XML_ERR_ERROR, NULL, 0, + (const char *) ctxt->base, NULL, NULL, + ctxt->cur - ctxt->base, 0, + xmlXPathErrorMessages[error]); + return; + } ctxt->context->lastError.domain = XML_FROM_XPATH; ctxt->context->lastError.code = error + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK;