Commit ce244ad5 authored by Daniel Veillard's avatar Daniel Veillard

fixed the way the generator works, extended the testing, especially with

* gentest.py testapi.c: fixed the way the generator works,
  extended the testing, especially with more real trees and nodes.
* HTMLtree.c tree.c valid.c xinclude.c xmlIO.c xmlsave.c: a bunch
  of real problems found and fixed.
* entities.c: fix error reporting to go through the new handlers
Daniel
parent 38936066
Fri Nov 5 11:02:28 CET 2004 Daniel Veillard <daniel@veillard.com>
* gentest.py testapi.c: fixed the way the generator works,
extended the testing, especially with more real trees and nodes.
* HTMLtree.c tree.c valid.c xinclude.c xmlIO.c xmlsave.c: a bunch
of real problems found and fixed.
* entities.c: fix error reporting to go through the new handlers
Thu Nov 4 18:44:56 CET 2004 Daniel Veillard <daniel@veillard.com>
* parser.c: dohh ... stupid change killing xmlParseDoc()
......
......@@ -745,7 +745,7 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc,
xmlInitParser();
if (cur == NULL) {
if ((cur == NULL) || (buf == NULL)) {
return;
}
/*
......@@ -753,7 +753,8 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc,
*/
if (cur->type == XML_DTD_NODE)
return;
if (cur->type == XML_HTML_DOCUMENT_NODE) {
if ((cur->type == XML_HTML_DOCUMENT_NODE) ||
(cur->type == XML_DOCUMENT_NODE)){
htmlDocContentDumpOutput(buf, (xmlDocPtr) cur, encoding);
return;
}
......
......@@ -61,6 +61,33 @@ static xmlEntity xmlEntityApos = {
NULL, NULL, NULL, NULL, 0
};
/**
* xmlEntitiesErrMemory:
* @extra: extra informations
*
* Handle an out of memory condition
*/
static void
xmlEntitiesErrMemory(const char *extra)
{
__xmlSimpleError(XML_FROM_TREE, XML_ERR_NO_MEMORY, NULL, NULL, extra);
}
/**
* xmlEntitiesErr:
* @code: the error code
* @msg: the message
*
* Handle an out of memory condition
*/
static void
xmlEntitiesErr(xmlParserErrors code, const char *msg)
{
const char *msg = NULL;
__xmlSimpleError(XML_FROM_TREE, code, NULL, msg, NULL);
}
/*
* xmlFreeEntity : clean-up an entity record.
*/
......@@ -118,8 +145,7 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
return(NULL);
ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddEntity: out of memory\n");
xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
return(NULL);
}
memset(ret, 0, sizeof(xmlEntity));
......@@ -213,13 +239,13 @@ xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type,
xmlDtdPtr dtd;
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddDtdEntity: doc == NULL !\n");
xmlEntitiesErr(XML_DTD_NO_DOC,
"xmlAddDtdEntity: document is NULL");
return(NULL);
}
if (doc->extSubset == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddDtdEntity: document without external subset !\n");
xmlEntitiesErr(XML_DTD_NO_DTD,
"xmlAddDtdEntity: document without external subset");
return(NULL);
}
dtd = doc->extSubset;
......@@ -262,13 +288,13 @@ xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
xmlDtdPtr dtd;
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddDocEntity: document is NULL !\n");
xmlEntitiesErr(XML_DTD_NO_DOC,
"xmlAddDocEntity: document is NULL");
return(NULL);
}
if (doc->intSubset == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddDocEntity: document without internal subset !\n");
xmlEntitiesErr(XML_DTD_NO_DTD,
"xmlAddDocEntity: document without internal subset");
return(NULL);
}
dtd = doc->intSubset;
......@@ -404,7 +430,7 @@ xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) {
buffer = (xmlChar *) \
xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \
if (buffer == NULL) { \
xmlGenericError(xmlGenericErrorContext, "realloc failed\n"); \
xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");\
return(NULL); \
} \
}
......@@ -440,7 +466,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
buffer_size = 1000;
buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
if (buffer == NULL) {
xmlGenericError(xmlGenericErrorContext, "malloc failed\n");
xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: malloc failed");
return(NULL);
}
out = buffer;
......@@ -498,8 +524,8 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
int val = 0, l = 1;
if (*cur < 0xC0) {
xmlGenericError(xmlGenericErrorContext,
"xmlEncodeEntitiesReentrant : input not UTF-8\n");
xmlEntitiesErr(XML_CHECK_NOT_UTF8,
"xmlEncodeEntitiesReentrant : input not UTF-8");
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
snprintf(buf, sizeof(buf), "&#%d;", *cur);
......@@ -531,7 +557,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
l = 4;
}
if ((l == 1) || (!IS_CHAR(val))) {
xmlGenericError(xmlGenericErrorContext,
xmlEntitiesErr(XML_ERR_INVALID_CHAR,
"xmlEncodeEntitiesReentrant : char out of range\n");
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
......@@ -593,7 +619,7 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
buffer_size = 1000;
buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
if (buffer == NULL) {
xmlGenericError(xmlGenericErrorContext, "malloc failed\n");
xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed");
return(NULL);
}
out = buffer;
......@@ -703,8 +729,7 @@ xmlCopyEntity(xmlEntityPtr ent) {
cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
if (cur == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlCopyEntity: out of memory !\n");
xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed");
return(NULL);
}
memset(cur, 0, sizeof(xmlEntity));
......@@ -863,9 +888,8 @@ xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) {
xmlBufferWriteChar(buf, ">\n");
break;
default:
xmlGenericError(xmlGenericErrorContext,
"xmlDumpEntitiesDecl: internal: unknown type %d\n",
ent->etype);
xmlEntitiesErr(XML_DTD_UNKNOWN_ENTITY,
"xmlDumpEntitiesDecl: internal: unknown type entity type");
}
}
......
......@@ -33,10 +33,11 @@ skipped_functions = [
"xmlReaderNewFd", "xmlReaderForFd",
"xmlIORead", "xmlReadIO", "xmlCtxtReadIO",
"htmlIORead", "htmlReadIO", "htmlCtxtReadIO",
"xmlReaderNewIO",
"xmlReaderNewIO", "xmlBufferDump",
# library state cleanup, generate false leak informations and other
# troubles, heavillyb tested otherwise.
"xmlCleanupParser", "xmlRelaxNGCleanupTypes",
"xmlCleanupParser", "xmlRelaxNGCleanupTypes", "xmlSetListDoc",
"xmlSetTreeDoc", "xmlUnlinkNode",
# hard to avoid leaks in the tests
"xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal",
# unimplemented
......@@ -67,9 +68,9 @@ skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias",
#
extra_pre_call = {
"xmlSAXUserParseFile":
"if (sax == &xmlDefaultSAXHandler) user_data = NULL;",
"if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
"xmlSAXUserParseMemory":
"if (sax == &xmlDefaultSAXHandler) user_data = NULL;",
"if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL;",
}
extra_post_call = {
"xmlAddChild":
......@@ -85,10 +86,16 @@ extra_post_call = {
"xmlDocSetRootElement":
"if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; }",
"xmlReplaceNode":
"""if ((old == NULL) || (old->parent == NULL)) {
xmlFreeNode(cur) ; cur = NULL ; }""",
"""if (cur != NULL) {
xmlUnlinkNode(cur);
xmlFreeNode(cur) ; cur = NULL ; }
if (old != NULL) {
xmlUnlinkNode(old);
xmlFreeNode(old) ; old = NULL ; }
ret_val = NULL;""",
"xmlTextMerge":
"""if ((first != NULL) && (first->type != XML_TEXT_NODE)) {
xmlUnlinkNode(second);
xmlFreeNode(second) ; second = NULL ; }""",
"xmlBuildQName":
"""if ((ret_val != NULL) && (ret_val != ncname) &&
......@@ -103,6 +110,7 @@ extra_post_call = {
"xmlSaveFileTo": """buf = NULL;""",
"xmlSaveFormatFileTo": """buf = NULL;""",
"xmlIOParseDTD": "input = NULL;",
"xmlRemoveProp": "cur = NULL;",
}
modules = []
......@@ -565,6 +573,19 @@ test_%s(void) {
}
""" % (module))
#
# Generate direct module caller
#
test.write("""static int
test_module(const char *module) {
""");
for module in modules:
test.write(""" if (!strcmp(module, "%s")) return(test_%s());\n""" % (
module, module))
test.write(""" return(0);
}
""");
print "Generated test for %d modules and %d functions" %(len(modules), nb_tests)
compare_and_save()
......
This diff is collapsed.
......@@ -3526,6 +3526,7 @@ xmlUnlinkNode(xmlNodePtr cur) {
*/
xmlNodePtr
xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) {
if (old == cur) return(NULL);
if ((old == NULL) || (old->parent == NULL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
......@@ -4677,6 +4678,9 @@ xmlNodeGetSpacePreserve(xmlNodePtr cur) {
*/
void
xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
xmlDocPtr doc;
xmlDictPtr dict;
if (cur == NULL) return;
if (name == NULL) return;
switch(cur->type) {
......@@ -4706,8 +4710,19 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
case XML_ENTITY_DECL:
break;
}
if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
cur->name = xmlStrdup(name);
doc = cur->doc;
if (doc != NULL)
dict = doc->dict;
else
dict = NULL;
if (dict != NULL) {
if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name)))
xmlFree((xmlChar *) cur->name);
cur->name = xmlDictLookup(dict, name, -1);
} else {
if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
cur->name = xmlStrdup(name);
}
}
#endif
......@@ -5690,7 +5705,7 @@ xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
#endif
return(NULL);
}
if (ns == NULL) {
if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
#ifdef DEBUG_TREE
xmlGenericError(xmlGenericErrorContext,
"xmlNewReconciliedNs : ns == NULL\n");
......@@ -5758,6 +5773,9 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
xmlAttrPtr attr;
int ret = 0, i;
if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(-1);
if ((doc == NULL) || (doc->type != XML_DOCUMENT_NODE)) return(-1);
if (node->doc != doc) return(-1);
while (node != NULL) {
/*
* Reconciliate the node namespace
......
......@@ -2880,6 +2880,13 @@ xmlFreeRefTable(xmlRefTablePtr table) {
*/
int
xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
if (attr == NULL)
return(0);
if (doc == NULL) {
doc = attr->doc;
if (doc == NULL) return(0);
}
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
return(0);
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
......@@ -2888,6 +2895,7 @@ xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
} else {
xmlAttributePtr attrDecl;
if (elem == NULL) return(0);
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);
if ((attrDecl == NULL) && (doc->extSubset != NULL))
attrDecl = xmlGetDtdAttrDesc(doc->extSubset,
......
......@@ -398,6 +398,9 @@ xmlXIncludeFreeContext(xmlXIncludeCtxtPtr ctxt) {
xmlFree(ctxt->txtTab);
if (ctxt->txturlTab != NULL)
xmlFree(ctxt->txturlTab);
if (ctxt->base != NULL) {
xmlFree(ctxt->base);
}
xmlFree(ctxt);
}
......@@ -681,7 +684,7 @@ xmlXIncludeRecurseDoc(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc,
/*
* Inherit the existing base
*/
newctxt->base = ctxt->base;
newctxt->base = xmlStrdup(ctxt->base);
/*
* Inherit the documents already in use by other includes
......@@ -1863,7 +1866,7 @@ xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
newctxt = xmlXIncludeNewContext(ctxt->doc);
if (newctxt == NULL)
return (-1);
newctxt->base = ctxt->base; /* Inherit the base from the existing context */
newctxt->base = xmlStrdup(ctxt->base); /* Inherit the base from the existing context */
xmlXIncludeSetFlags(newctxt, ctxt->parseFlags);
ret = xmlXIncludeDoProcess(newctxt, ctxt->doc, fallback->children);
if (ctxt->nbErrors > 0)
......@@ -2372,7 +2375,7 @@ xmlXIncludeProcessFlags(xmlDocPtr doc, int flags) {
ctxt = xmlXIncludeNewContext(doc);
if (ctxt == NULL)
return(-1);
ctxt->base = (xmlChar *)doc->URL;
ctxt->base = xmlStrdup((xmlChar *)doc->URL);
xmlXIncludeSetFlags(ctxt, flags);
ret = xmlXIncludeDoProcess(ctxt, doc, tree);
if ((ret >= 0) && (ctxt->nbErrors > 0))
......
......@@ -3048,7 +3048,9 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str,
int len; /* number of bytes in str */
int cons; /* byte from str consumed */
if ((out == NULL) || (out->error) || (str == NULL)) return(-1);
if ((out == NULL) || (out->error) || (str == NULL) ||
(out->buffer == NULL) ||
(out->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) return(-1);
len = strlen((const char *)str);
if (len < 0) return(0);
if (out->error) return(-1);
......
......@@ -445,6 +445,7 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur);
static void xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur);
/**
* xmlNsDumpOutput:
......@@ -456,7 +457,7 @@ void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur);
*/
static void
xmlNsDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) {
if (cur == NULL) return;
if ((cur == NULL) || (buf == NULL)) return;
if ((cur->type == XML_LOCAL_NAMESPACE) && (cur->href != NULL)) {
if (xmlStrEqual(cur->prefix, BAD_CAST "xml"))
return;
......@@ -557,6 +558,7 @@ xmlAttrDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) {
if (cur == NULL) return;
buf = ctxt->buf;
if (buf == NULL) return;
xmlOutputBufferWrite(buf, 1, " ");
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix);
......@@ -634,6 +636,11 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
return;
if (cur->type == XML_XINCLUDE_END)
return;
if ((cur->type == XML_DOCUMENT_NODE) ||
(cur->type == XML_HTML_DOCUMENT_NODE)) {
xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur);
return;
}
if (cur->type == XML_DTD_NODE) {
xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur);
return;
......@@ -1790,6 +1797,8 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
xmlInitParser();
if ((buf == NULL) || (cur == NULL)) return;
memset(&ctxt, 0, sizeof(ctxt));
ctxt.doc = doc;
ctxt.buf = buf;
......@@ -2083,7 +2092,9 @@ xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur,
int ret;
if (buf == NULL) return(-1);
if (cur == NULL) {
if ((cur == NULL) ||
((cur->type != XML_DOCUMENT_NODE) &&
(cur->type != XML_HTML_DOCUMENT_NODE))) {
xmlOutputBufferClose(buf);
return(-1);
}
......
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