1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-26 10:03:34 +03:00

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
This commit is contained in:
Daniel Veillard 2003-12-08 10:25:02 +00:00
parent fded7bf91b
commit f88d8cf9f1
9 changed files with 83 additions and 39 deletions

View File

@ -1,3 +1,12 @@
Mon Dec 8 11:08:45 CET 2003 Daniel Veillard <daniel@veillard.com>
* 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 <daniel@veillard.com>
* error.c: fixed __xmlRaiseError to use structured error handlers

53
SAX2.c
View File

@ -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;
}
/*

View File

@ -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))) {

View File

@ -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,

View File

@ -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,

View File

@ -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)
#

View File

@ -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 !
<doc/>
^

View File

@ -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;

15
xpath.c
View File

@ -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;