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

applied patch from Aswin to fix tree skipping fixed a comment and added a

* xmlreader.c: applied patch from Aswin to fix tree skipping
* include/libxml/entities.h entities.c: fixed a comment and
  added a new xmlNewEntity() entry point
* runtest.c: be less verbose
* tree.c: space and tabs cleanups
daniel

svn path=/trunk/; revision=3774
This commit is contained in:
Daniel Veillard
2008-08-25 14:53:31 +00:00
parent f4f4e4853a
commit aa6de47ebf
7 changed files with 484 additions and 397 deletions

View File

@@ -1,3 +1,11 @@
Mon Aug 25 16:52:53 CEST 2008 Daniel Veillard <daniel@veillard.com>
* xmlreader.c: applied patch from Aswin to fix tree skipping
* include/libxml/entities.h entities.c: fixed a comment and
added a new xmlNewEntity() entry point
* runtest.c: be less verbose
* tree.c: space and tabs cleanups
Mon Aug 25 10:56:30 CEST 2008 Daniel Veillard <daniel@veillard.com>
* include/libxml/entities.h entities.c SAX2.c parser.c: rework

View File

@@ -139,45 +139,19 @@ xmlFreeEntity(xmlEntityPtr entity)
}
/*
* xmlAddEntity : register a new entity for an entities table.
* xmlCreateEntity:
*
* internal routine doing the entity node strutures allocations
*/
static xmlEntityPtr
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
const xmlChar *ExternalID, const xmlChar *SystemID,
const xmlChar *content) {
xmlDictPtr dict = NULL;
xmlEntitiesTablePtr table = NULL;
xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type,
const xmlChar *ExternalID, const xmlChar *SystemID,
const xmlChar *content) {
xmlEntityPtr ret;
if (name == NULL)
return(NULL);
if (dtd == NULL)
return(NULL);
if (dtd->doc != NULL)
dict = dtd->doc->dict;
switch (type) {
case XML_INTERNAL_GENERAL_ENTITY:
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
if (dtd->entities == NULL)
dtd->entities = xmlHashCreateDict(0, dict);
table = dtd->entities;
break;
case XML_INTERNAL_PARAMETER_ENTITY:
case XML_EXTERNAL_PARAMETER_ENTITY:
if (dtd->pentities == NULL)
dtd->pentities = xmlHashCreateDict(0, dict);
table = dtd->pentities;
break;
case XML_INTERNAL_PREDEFINED_ENTITY:
return(NULL);
}
if (table == NULL)
return(NULL);
ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
if (ret == NULL) {
xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
xmlEntitiesErrMemory("xmlCreateEntity: malloc failed");
return(NULL);
}
memset(ret, 0, sizeof(xmlEntity));
@@ -216,6 +190,50 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
the defining entity */
ret->orig = NULL;
ret->owner = 0;
return(ret);
}
/*
* xmlAddEntity : register a new entity for an entities table.
*/
static xmlEntityPtr
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
const xmlChar *ExternalID, const xmlChar *SystemID,
const xmlChar *content) {
xmlDictPtr dict = NULL;
xmlEntitiesTablePtr table = NULL;
xmlEntityPtr ret;
if (name == NULL)
return(NULL);
if (dtd == NULL)
return(NULL);
if (dtd->doc != NULL)
dict = dtd->doc->dict;
switch (type) {
case XML_INTERNAL_GENERAL_ENTITY:
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
if (dtd->entities == NULL)
dtd->entities = xmlHashCreateDict(0, dict);
table = dtd->entities;
break;
case XML_INTERNAL_PARAMETER_ENTITY:
case XML_EXTERNAL_PARAMETER_ENTITY:
if (dtd->pentities == NULL)
dtd->pentities = xmlHashCreateDict(0, dict);
table = dtd->pentities;
break;
case XML_INTERNAL_PREDEFINED_ENTITY:
return(NULL);
}
if (table == NULL)
return(NULL);
ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
if (ret == NULL)
return(NULL);
ret->doc = dtd->doc;
if (xmlHashAddEntry(table, name, ret)) {
@@ -362,6 +380,44 @@ xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
return(ret);
}
/**
* xmlNewEntity:
* @doc: the document
* @name: the entity name
* @type: the entity type XML_xxx_yyy_ENTITY
* @ExternalID: the entity external ID if available
* @SystemID: the entity system ID if available
* @content: the entity content
*
* Create a new entity, this differs from xmlAddDocEntity() that if
* the document is NULL or has no internal subset defined, then an
* unlinked entity structure will be returned, it is then the responsability
* of the caller to link it to the document later or free it when not needed
* anymore.
*
* Returns a pointer to the entity or NULL in case of error
*/
xmlEntityPtr
xmlNewEntity(xmlDocPtr doc, const xmlChar *name, int type,
const xmlChar *ExternalID, const xmlChar *SystemID,
const xmlChar *content) {
xmlEntityPtr ret;
xmlDictPtr dict;
if ((doc != NULL) && (doc->intSubset != NULL)) {
return(xmlAddDocEntity(doc, name, type, ExternalID, SystemID, content));
}
if (doc != NULL)
dict = doc->dict;
else
dict = NULL;
ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
if (ret == NULL)
return(NULL);
ret->doc = doc;
return(ret);
}
/**
* xmlGetEntityFromTable:
* @table: an entity table

View File

@@ -57,6 +57,8 @@ struct _xmlEntity {
const xmlChar *URI; /* the full URI as computed */
int owner; /* does the entity own the childrens */
int checked; /* was the entity content checked */
/* this is also used to count entites
* references done from that entity */
};
/*
@@ -75,6 +77,14 @@ typedef xmlEntitiesTable *xmlEntitiesTablePtr;
XMLPUBFUN void XMLCALL
xmlInitializePredefinedEntities (void);
#endif /* LIBXML_LEGACY_ENABLED */
XMLPUBFUN xmlEntityPtr XMLCALL
xmlNewEntity (xmlDocPtr doc,
const xmlChar *name,
int type,
const xmlChar *ExternalID,
const xmlChar *SystemID,
const xmlChar *content);
XMLPUBFUN xmlEntityPtr XMLCALL
xmlAddDocEntity (xmlDocPtr doc,
const xmlChar *name,

View File

@@ -314,7 +314,7 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
n = 0;
/* search backwards for beginning-of-line (to max buff size) */
while ((n++ < (sizeof(content)-1)) && (cur > base) &&
(*(cur) != '\n') && (*(cur) != '\r'))
(*(cur) != '\n') && (*(cur) != '\r'))
cur--;
if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
/* calculate the error position in terms of the current position */
@@ -324,7 +324,7 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
ctnt = content;
/* copy selected text to our buffer */
while ((*cur != 0) && (*(cur) != '\n') &&
(*(cur) != '\r') && (n < sizeof(content)-1)) {
(*(cur) != '\r') && (n < sizeof(content)-1)) {
*ctnt++ = *cur++;
n++;
}
@@ -3586,7 +3586,7 @@ load_xpath_expr (xmlDocPtr parent_doc, const char* filename) {
while(ns != NULL) {
if(xmlXPathRegisterNs(ctx, ns->prefix, ns->href) != 0) {
fprintf(stderr,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", ns->prefix, ns->href);
xmlFree(expr);
xmlFree(expr);
xmlXPathFreeContext(ctx);
xmlFreeDoc(doc);
return(NULL);
@@ -3600,7 +3600,7 @@ load_xpath_expr (xmlDocPtr parent_doc, const char* filename) {
xpath = xmlXPathEvalExpression(expr, ctx);
if(xpath == NULL) {
fprintf(stderr,"Error: unable to evaluate xpath expression\n");
xmlFree(expr);
xmlFree(expr);
xmlXPathFreeContext(ctx);
xmlFreeDoc(doc);
return(NULL);
@@ -3620,7 +3620,7 @@ load_xpath_expr (xmlDocPtr parent_doc, const char* filename) {
#define xxx_growBufferReentrant() { \
buffer_size *= 2; \
buffer = (xmlChar **) \
xmlRealloc(buffer, buffer_size * sizeof(xmlChar*)); \
xmlRealloc(buffer, buffer_size * sizeof(xmlChar*)); \
if (buffer == NULL) { \
perror("realloc failed"); \
return(NULL); \
@@ -4392,7 +4392,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
initializeLibxml2();
for (a = 1; a < argc;a++) {
if (!strcmp(argv[a], "-v"))
verbose = 1;

View File

@@ -446,22 +446,27 @@ error:
}
static int
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur, int level) {
xmlChar *profile;
int ret = 0;
int tests = 0;
int output = 0;
profile = xmlGetProp(cur, BAD_CAST "PROFILE");
if (profile != NULL) {
printf("Test cases: %s\n", (char *) profile);
xmlFree(profile);
if (level == 1) {
profile = xmlGetProp(cur, BAD_CAST "PROFILE");
if (profile != NULL) {
output = 1;
level++;
printf("Test cases: %s\n", (char *) profile);
xmlFree(profile);
}
}
cur = cur->children;
while (cur != NULL) {
/* look only at elements we ignore everything else */
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
ret += xmlconfTestCases(doc, cur);
ret += xmlconfTestCases(doc, cur, level);
} else if (xmlStrEqual(cur->name, BAD_CAST "TEST")) {
if (xmlconfTestItem(doc, cur) >= 0)
ret++;
@@ -472,8 +477,10 @@ xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
}
cur = cur->next;
}
if (tests > 0)
printf("Test cases: %d tests\n", tests);
if (output == 1) {
if (tests > 0)
printf("Test cases: %d tests\n", tests);
}
return(ret);
}
@@ -493,7 +500,7 @@ xmlconfTestSuite(xmlDocPtr doc, xmlNodePtr cur) {
/* look only at elements we ignore everything else */
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
ret += xmlconfTestCases(doc, cur);
ret += xmlconfTestCases(doc, cur, 1);
} else {
fprintf(stderr, "Unhandled element %s\n", (char *)cur->name);
}
@@ -584,6 +591,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
ret = 1;
printf("Total %d tests, %d errors, %d leaks\n",
nb_tests, nb_errors, nb_leaks);
printf("See %s for detailed output\n", LOGFILE);
}
xmlXPathFreeContext(ctxtXPath);
xmlCleanupParser();

34
tree.c
View File

@@ -45,7 +45,7 @@ int __xmlRegisterCallbacks = 0;
/************************************************************************
* *
* Forward declarations *
* Forward declarations *
* *
************************************************************************/
@@ -55,7 +55,7 @@ static xmlChar* xmlGetPropNodeValueInternal(xmlAttrPtr prop);
/************************************************************************
* *
* Tree memory error handler *
* Tree memory error handler *
* *
************************************************************************/
/**
@@ -103,7 +103,7 @@ xmlTreeErr(int code, xmlNodePtr node, const char *extra)
/************************************************************************
* *
* A few static variables and macros *
* A few static variables and macros *
* *
************************************************************************/
/* #undef xmlStringText */
@@ -123,7 +123,7 @@ static int xmlCheckDTD = 1;
(n)->last = NULL; \
} else { \
while (ulccur->next != NULL) { \
ulccur->parent = (n); \
ulccur->parent = (n); \
ulccur = ulccur->next; \
} \
ulccur->parent = (n); \
@@ -138,7 +138,7 @@ static int xmlCheckDTD = 1;
/************************************************************************
* *
* Functions to move to entities.c once the *
* Functions to move to entities.c once the *
* API freeze is smoothen and they can be made public. *
* *
************************************************************************/
@@ -162,7 +162,7 @@ xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) {
if((dtd != NULL) && (dtd->entities != NULL)) {
table = (xmlEntitiesTablePtr) dtd->entities;
return((xmlEntityPtr) xmlHashLookup(table, name));
/* return(xmlGetEntityFromTable(table, name)); */
/* return(xmlGetEntityFromTable(table, name)); */
}
return(NULL);
}
@@ -1022,7 +1022,7 @@ xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name,
* current scope
*/
#define DICT_FREE(str) \
if ((str) && ((!dict) || \
if ((str) && ((!dict) || \
(xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
xmlFree((char *)(str));
@@ -3190,7 +3190,7 @@ xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) {
if ((cur->type == XML_TEXT_NODE) &&
(parent->last->type == XML_TEXT_NODE) &&
(cur->name == parent->last->name)) {
xmlNodeAddContent(parent->last, cur->content);
xmlNodeAddContent(parent->last, cur->content);
/*
* if it's the only child, nothing more to be done.
*/
@@ -4140,7 +4140,7 @@ xmlCopyDtd(xmlDtdPtr dtd) {
break;
case XML_INTERNAL_PARAMETER_ENTITY:
case XML_EXTERNAL_PARAMETER_ENTITY:
q = (xmlNodePtr)
q = (xmlNodePtr)
xmlGetParameterEntityFromDtd(ret, tmp->name);
break;
case XML_INTERNAL_PREDEFINED_ENTITY:
@@ -4166,13 +4166,13 @@ xmlCopyDtd(xmlDtdPtr dtd) {
if (p == NULL)
ret->children = q;
else
p->next = q;
p->next = q;
q->prev = p;
q->parent = (xmlNodePtr) ret;
q->prev = p;
q->parent = (xmlNodePtr) ret;
q->next = NULL;
ret->last = q;
p = q;
p = q;
cur = cur->next;
}
@@ -4334,7 +4334,7 @@ xmlGetNodePath(xmlNodePtr node)
if (cur->ns) {
if (cur->ns->prefix != NULL) {
snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s",
(char *)cur->ns->prefix, (char *)cur->name);
(char *)cur->ns->prefix, (char *)cur->name);
nametemp[sizeof(nametemp) - 1] = 0;
name = nametemp;
} else {
@@ -4475,10 +4475,10 @@ xmlGetNodePath(xmlNodePtr node)
if (cur->ns) {
if (cur->ns->prefix != NULL)
snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s",
(char *)cur->ns->prefix, (char *)cur->name);
(char *)cur->ns->prefix, (char *)cur->name);
else
snprintf(nametemp, sizeof(nametemp) - 1, "%s",
(char *)cur->name);
(char *)cur->name);
nametemp[sizeof(nametemp) - 1] = 0;
name = nametemp;
}
@@ -5860,7 +5860,7 @@ xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
snprintf((char *) prefix, sizeof(prefix), "default%d", counter++);
else
snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
(char *)ns->prefix, counter++);
(char *)ns->prefix, counter++);
def = xmlSearchNs(doc, tree, prefix);
}

View File

@@ -1847,17 +1847,22 @@ xmlTextReaderNextTree(xmlTextReaderPtr reader)
}
if (reader->state != XML_TEXTREADER_BACKTRACK) {
if (reader->node->children != 0) {
reader->node = reader->node->children;
reader->depth++;
/* Here removed traversal to child, because we want to skip the subtree,
replace with traversal to sibling to skip subtree */
if (reader->node->next != 0) {
reader->node = reader->node->next;// Move to sibling if present,skipping sub-tree
//reader->depth++;
reader->state = XML_TEXTREADER_START;
return(1);
}
/* if reader->node->next is NULL mean no subtree for current node,
so need to move to sibling of parent node if present */
if ((reader->node->type == XML_ELEMENT_NODE) ||
(reader->node->type == XML_ATTRIBUTE_NODE)) {
reader->state = XML_TEXTREADER_BACKTRACK;
return(1);
xmlTextReaderRead(reader);// This will move to parent if present
//return(xmlTextReaderReadTree(reader));
}
}
@@ -1876,7 +1881,8 @@ xmlTextReaderNextTree(xmlTextReaderPtr reader)
reader->node = reader->node->parent;
reader->depth--;
reader->state = XML_TEXTREADER_BACKTRACK;
return(1);
xmlTextReaderNextTree(reader); //Repeat process to move to sibling of parent node if present
//return(1);
}
reader->state = XML_TEXTREADER_END;