/*
* compute depth to root
*/
- for (depth2 = 0, cur = node2; cur->parent != NULL; cur = cur->parent) {
- if (cur->parent == node1)
+ for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) {
+ if (cur == node1)
return(1);
depth2++;
}
root = cur;
- for (depth1 = 0, cur = node1; cur->parent != NULL; cur = cur->parent) {
- if (cur->parent == node2)
+ for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) {
+ if (cur == node2)
return(-1);
depth1++;
}
xmlChar buf[200];
xmlStrPrintf(buf, 200,
- "Memory allocation failed : %s\n",
+ BAD_CAST "Memory allocation failed : %s\n",
extra);
ctxt->lastError.message = (char *) xmlStrdup(buf);
} else {
xmlXPathStepOp *steps; /* ops for computation of this expression */
int last; /* index of last step in expression */
xmlChar *expr; /* the expression being computed */
- xmlDictPtr dict; /* the dictionary to use if any */
+ xmlDictPtr dict; /* the dictionnary to use if any */
#ifdef DEBUG_EVAL_COUNTS
int nb;
xmlChar *string;
/* @@ with_ns to check whether namespace nodes should be looked at @@ */
/*
- * prevent duplicates
+ * prevent duplcates
*/
for (i = 0;i < cur->nodeNr;i++)
if (cur->nodeTab[i] == val) return(0);
xmlNodePtr
xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
- if (cur == NULL)
+ if (cur == NULL) {
+ if (ctxt->context->node == NULL)
+ return(NULL);
+ if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
+ (ctxt->context->node->type == XML_NAMESPACE_DECL))
+ return(NULL);
return(ctxt->context->node);
-
- if (ctxt->context->node == NULL)
- return(NULL);
- if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
- (ctxt->context->node->type == XML_NAMESPACE_DECL))
- return(NULL);
+ }
return(xmlXPathNextDescendant(ctxt, cur));
}
xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL);
- if (cur == NULL) {
+ if (ctxt->context->tmpNsList == NULL && cur != (xmlNodePtr) xmlXPathXMLNamespace) {
if (ctxt->context->tmpNsList != NULL)
xmlFree(ctxt->context->tmpNsList);
ctxt->context->tmpNsList =
(c == '[') || (c == ']') || (c == '@') || /* accelerators */
(c == '*') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
- ((!qualified) || (c != ':')))) {
+ ((qualified) && (c != ':')))) {
return(NULL);
}
STRANGE
goto error;
case NODE_TEST_TYPE:
+ /*
+ * TODO: Don't we need to use
+ * xmlXPathNodeSetAddNs() for namespace nodes here?
+ * Surprisingly, some c14n tests fail, if we do this.
+ */
if (type == NODE_TYPE_NODE) {
switch (cur->type) {
case XML_DOCUMENT_NODE:
case XML_COMMENT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_TEXT_NODE:
+ case XML_NAMESPACE_DECL:
XP_TEST_HIT
break;
- case XML_NAMESPACE_DECL: {
- if (axis == AXIS_NAMESPACE) {
- XP_TEST_HIT_NS
- } else {
- hasNsNodes = 1;
- XP_TEST_HIT
- }
- break;
- }
default:
break;
}
* Reset the context node.
*/
xpctxt->node = oldContextNode;
- /*
- * When traversing the namespace axis in "toBool" mode, it's
- * possible that tmpNsList wasn't freed.
- */
- if (xpctxt->tmpNsList != NULL) {
- xmlFree(xpctxt->tmpNsList);
- xpctxt->tmpNsList = NULL;
- }
#ifdef DEBUG_STEP
xmlGenericError(xmlGenericErrorContext,
}
}
- /* OP_VALUE has invalid ch1. */
- if (op->op == XPATH_OP_VALUE)
- return;
-
/* Recurse */
if (op->ch1 != -1)
xmlXPathOptimizeExpression(comp, &comp->steps[op->ch1]);