From f7eb794c142e31ca895f2d7743f872a809e514ab Mon Sep 17 00:00:00 2001 From: "William M. Brack" Date: Wed, 31 Dec 2003 07:59:17 +0000 Subject: [PATCH] =?UTF-8?q?fixed=20problem=20pointed=20out=20by=20St=E9pha?= =?UTF-8?q?ne=20Bidoul=20on=20the=20list.=20completed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * python/generator.py, python/libxml2class.txt: fixed problem pointed out by Stéphane Bidoul on the list. * xinclude.c, xpointer.c, xpath.c, include/libxml/xpointer.h: completed modifications required to fix Bug 129967 (at last!). Now wait to see how long before further trouble... --- ChangeLog | 8 ++++ include/libxml/xpointer.h | 2 - python/generator.py | 4 +- python/libxml2class.txt | 1 - xinclude.c | 85 +++++++++++++++++++++++++-------------- xpath.c | 18 +++------ xpointer.c | 19 +++++---- 7 files changed, 82 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b88c4e0..d3cfd1dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Dec 31 15:55:55 HKT 2003 William Brack + + * python/generator.py, python/libxml2class.txt: fixed problem + pointed out by Stéphane Bidoul on the list. + * xinclude.c, xpointer.c, xpath.c, include/libxml/xpointer.h: + completed modifications required to fix Bug 129967 (at last!). + Now wait to see how long before further trouble... + Tue Dec 30 16:26:13 HKT 2003 William Brack * parser.c, xmlmemory.c, include/libxml/xmlmemory.h: Fixed diff --git a/include/libxml/xpointer.h b/include/libxml/xpointer.h index 2856bdd6..2285b0ed 100644 --- a/include/libxml/xpointer.h +++ b/include/libxml/xpointer.h @@ -103,8 +103,6 @@ XMLPUBFUN xmlNodePtr XMLCALL xmlXPtrBuildNodeList (xmlXPathObjectPtr obj); XMLPUBFUN void XMLCALL xmlXPtrEvalRangePredicate (xmlXPathParserContextPtr ctxt); -XMLPUBFUN xmlNodePtr XMLCALL - xmlXPtrAdvanceNode (xmlNodePtr cur); #ifdef __cplusplus } #endif diff --git a/python/generator.py b/python/generator.py index 3896177c..ce0b8f35 100755 --- a/python/generator.py +++ b/python/generator.py @@ -325,6 +325,8 @@ def skip_function(name): return 1 if name == "xmlOutputBufferFlush": # handled by by the superclass return 1 + if name == "xmlErrMemory": + return 1 return 0 def print_function_wrapper(name, output, export, include): @@ -573,8 +575,6 @@ def buildStubs(): wrapper = open("libxml2-py.c", "w") wrapper.write("/* Generated */\n\n") wrapper.write("#include \n") -# wrapper.write("#include \"config.h\"\n") - wrapper.write("#define IN_LIBXML\n") wrapper.write("#include \n") wrapper.write("#include \n") wrapper.write("#include \n") diff --git a/python/libxml2class.txt b/python/libxml2class.txt index 8eab9308..a5de430a 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -896,7 +896,6 @@ Class parserCtxt(parserCtxtCore) # functions from module parserInternals decodeEntities() - errMemory() handleEntity() namespaceParseNCName() namespaceParseNSDef() diff --git a/xinclude.c b/xinclude.c index ca66d622..3d27f5ea 100644 --- a/xinclude.c +++ b/xinclude.c @@ -844,6 +844,7 @@ xmlXIncludeGetNthChild(xmlNodePtr cur, int no) { return(cur); } +xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur, int *level); /* in xpointer.c */ /** * xmlXIncludeCopyRange: * @ctxt: the XInclude context @@ -860,10 +861,12 @@ static xmlNodePtr xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, xmlDocPtr source, xmlXPathObjectPtr range) { /* pointers to generated nodes */ - xmlNodePtr list = NULL, last = NULL, parent = NULL, tmp; + xmlNodePtr list = NULL, last = NULL, listParent = NULL; + xmlNodePtr tmp, tmp2; /* pointers to traversal nodes */ xmlNodePtr start, cur, end; int index1, index2; + int level = 0, lastLevel = 0; if ((ctxt == NULL) || (target == NULL) || (source == NULL) || (range == NULL)) @@ -881,7 +884,36 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, cur = start; index1 = range->index; index2 = range->index2; + /* + * level is depth of the current node under consideration + * list is the pointer to the root of the output tree + * listParent is a pointer to the parent of output tree (within + the included file) in case we need to add another level + * last is a pointer to the last node added to the output tree + * lastLevel is the depth of last (relative to the root) + */ while (cur != NULL) { + /* + * Check if our output tree needs a parent + */ + if (level < 0) { + while (level < 0) { + tmp2 = xmlDocCopyNode(listParent, target, 0); + xmlAddChild(tmp2, list); + list = tmp2; + listParent = listParent->parent; + level++; + } + last = list; + lastLevel = 0; + } + /* + * Check whether we need to change our insertion point + */ + while (level < lastLevel) { + last = last->parent; + lastLevel --; + } if (cur == end) { /* Are we at the end of the range? */ if (cur->type == XML_TEXT_NODE) { const xmlChar *content = cur->content; @@ -904,23 +936,25 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, if (list == NULL) return(tmp); /* prune and return full set */ - if (last != NULL) + if (level == lastLevel) xmlAddNextSibling(last, tmp); else - xmlAddChild(parent, tmp); + xmlAddChild(last, tmp); return(list); } else { /* ending node not a text node */ tmp = xmlDocCopyNode(cur, target, 0); - if (list == NULL) + if (list == NULL) { list = tmp; - else { - if (last != NULL) + listParent = cur->parent; + } else { + if (level == lastLevel) xmlAddNextSibling(last, tmp); - else - xmlAddChild(parent, tmp); + else { + xmlAddChild(last, tmp); + lastLevel = level; + } } - last = NULL; - parent = tmp; + last = tmp; if (index2 > 1) { end = xmlXIncludeGetNthChild(cur, index2 - 1); @@ -937,8 +971,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, */ continue; /* while */ } - } else if ((cur == start) && /* Not at the end, are we at start? */ - (list == NULL) /* looks superfluous but ... */ ) { + } else if (cur == start) { /* Not at the end, are we at start? */ if ((cur->type == XML_TEXT_NODE) || (cur->type == XML_CDATA_SECTION_NODE)) { const xmlChar *content = cur->content; @@ -953,23 +986,20 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, tmp = xmlNewText(content); } last = list = tmp; + listParent = cur->parent; } else { /* Not text node */ + tmp = xmlDocCopyNode(cur, target, 0); + list = last = tmp; + listParent = cur->parent; if (index1 > 1) { /* Do we need to position? */ - tmp = xmlDocCopyNode(cur, target, 0); - list = tmp; - parent = tmp; - last = NULL; cur = xmlXIncludeGetNthChild(cur, index1 - 1); + level = lastLevel = 1; index1 = 0; /* * Now gather the remaining nodes from cur to end */ continue; /* while */ } - tmp = xmlDocCopyNode(cur, target, 0); - list = tmp; - parent = NULL; - last = tmp; } } else { tmp = NULL; @@ -995,24 +1025,19 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, break; } if (tmp != NULL) { - if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - return(NULL); - } - if (last != NULL) + if (level == lastLevel) xmlAddNextSibling(last, tmp); else { - xmlAddChild(parent, tmp); - last = tmp; + xmlAddChild(last, tmp); + lastLevel = level; } + last = tmp; } } /* * Skip to next node in document order */ - if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - return(NULL); - } - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, &level); } return(list); } diff --git a/xpath.c b/xpath.c index 563e307e..4b0ca110 100644 --- a/xpath.c +++ b/xpath.c @@ -10447,10 +10447,10 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) * single item in the nodelocset. */ ctxt->context->node = oldlocset->locTab[i]->user; - tmp = xmlXPathNewNodeSet(ctxt->context->node); - valuePush(ctxt, tmp); ctxt->context->contextSize = oldlocset->locNr; ctxt->context->proximityPosition = i + 1; + tmp = xmlXPathNewNodeSet(ctxt->context->node); + valuePush(ctxt, tmp); if (op->ch2 != -1) total += @@ -10632,9 +10632,9 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) * Run the evaluation with a node list made of a * single item in the nodelocset. */ - ctxt->context->node = (xmlNodePtr)ctxt->context->doc; - ctxt->context->contextSize = 1; - ctxt->context->proximityPosition = 1; + ctxt->context->node = oldlocset->locTab[i]->user; + ctxt->context->contextSize = oldlocset->locNr; + ctxt->context->proximityPosition = i + 1; tmp = xmlXPathNewNodeSet(ctxt->context->node); valuePush(ctxt, tmp); @@ -10644,10 +10644,6 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) &comp->steps[op->ch2]); CHECK_ERROR0; - /* - * The result of the evaluation needs to be tested to - * decide whether the filter succeeded or not - */ res = valuePop(ctxt); if (res->type == XPATH_LOCATIONSET) { xmlLocationSetPtr rloc = @@ -10706,10 +10702,6 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) &comp->steps[op->ch2]); CHECK_ERROR0; - /* - * The result of the evaluation need to be tested to - * decided whether the filter succeeded or not - */ res = valuePop(ctxt); range = xmlXPtrNewRangeNodeObject(oldset->nodeTab[i], diff --git a/xpointer.c b/xpointer.c index adc854c1..145b1344 100644 --- a/xpointer.c +++ b/xpointer.c @@ -123,7 +123,8 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error, * A few helper functions for child sequences * * * ************************************************************************/ - +/* xmlXPtrAdvanceNode is a private function, but used by xinclude.c */ +xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur, int *level); /** * xmlXPtrGetArity: * @cur: the node @@ -1582,7 +1583,7 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { STRANGE return(NULL); } - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, NULL); } return(list); } @@ -2296,12 +2297,14 @@ xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs) { * Returns -1 in case of failure, 0 otherwise */ xmlNodePtr -xmlXPtrAdvanceNode(xmlNodePtr cur) { +xmlXPtrAdvanceNode(xmlNodePtr cur, int *level) { next: if (cur == NULL) return(NULL); if (cur->children != NULL) { cur = cur->children ; + if (level != NULL) + (*level)++; goto found; } if (cur->next != NULL) { @@ -2310,6 +2313,8 @@ next: } do { cur = cur->parent; + if (level != NULL) + (*level)--; if (cur == NULL) return(NULL); if (cur->next != NULL) { cur = cur->next; @@ -2366,7 +2371,7 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { cur = xmlXPtrGetNthChild(cur, pos); pos = 0; } else { - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, NULL); pos = 0; } } @@ -2401,7 +2406,7 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { } if (pos + bytes >= len) { bytes -= (len - pos); - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, NULL); cur = 0; } else if (pos + bytes < len) { pos += bytes; @@ -2490,7 +2495,7 @@ xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex, } } } - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, NULL); if (cur == NULL) return(0); pos = 0; @@ -2583,7 +2588,7 @@ xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex, } if ((cur == *end) && (pos >= *endindex)) return(0); - cur = xmlXPtrAdvanceNode(cur); + cur = xmlXPtrAdvanceNode(cur, NULL); if (cur == NULL) return(0); pos = 1;