diff options
author | Mike Hommey <glandium@debian.org> | 2005-09-05 17:10:35 +0000 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2005-09-05 17:10:35 +0000 |
commit | a464d9993e2acd5b8e1089b218ba74c6fcf215c5 (patch) | |
tree | 72fe00eb59147367a1d660b90d08172357e0dffc /xpath.c | |
parent | 112cb5bb5475afec1c1cbf1d6728ce4880d0fee8 (diff) | |
download | libxml2-a464d9993e2acd5b8e1089b218ba74c6fcf215c5.tar.gz |
Load /usr/tmp/tmp.CMoFff/libxml2-2.6.21 intoupstream/2.6.21
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'xpath.c')
-rw-r--r-- | xpath.c | 94 |
1 files changed, 59 insertions, 35 deletions
@@ -89,7 +89,7 @@ double xmlXPathNAN = 0; double xmlXPathPINF = 1; double xmlXPathNINF = -1; -double xmlXPathNZERO = 0; +static double xmlXPathNZERO = 0; /* not exported from headers */ static int xmlXPathInitialized = 0; /** @@ -189,6 +189,15 @@ static int xmlXPathDisableOptimizer = 0; * * ************************************************************************/ +/** + * XP_ERRORNULL: + * @X: the error code + * + * Macro to raise an XPath error and return NULL. + */ +#define XP_ERRORNULL(X) \ + { xmlXPathErr(ctxt, X); return(NULL); } + /* * The array xmlXPathErrorMessages corresponds to the enum xmlXPathError */ @@ -1116,20 +1125,20 @@ xmlXPathDebugDumpCompExpr(FILE *output, xmlXPathCompExprPtr comp, * * Returns the XPath object just removed */ -extern xmlXPathObjectPtr +xmlXPathObjectPtr valuePop(xmlXPathParserContextPtr ctxt) { xmlXPathObjectPtr ret; if ((ctxt == NULL) || (ctxt->valueNr <= 0)) - return (0); + return (NULL); ctxt->valueNr--; if (ctxt->valueNr > 0) ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; else ctxt->value = NULL; ret = ctxt->valueTab[ctxt->valueNr]; - ctxt->valueTab[ctxt->valueNr] = 0; + ctxt->valueTab[ctxt->valueNr] = NULL; return (ret); } /** @@ -1141,7 +1150,7 @@ valuePop(xmlXPathParserContextPtr ctxt) * * returns the number of items on the value stack */ -extern int +int valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value) { if ((ctxt == NULL) || (value == NULL)) return(-1); @@ -1391,25 +1400,16 @@ xmlXPathFormatNumber(double number, char buffer[], int buffersize) } else if (number == ((int) number)) { char work[30]; char *ptr, *cur; - int res, value = (int) number; + int value = (int) number; ptr = &buffer[0]; - if (value < 0) { - *ptr++ = '-'; - value = -value; - } if (value == 0) { *ptr++ = '0'; } else { + snprintf(work, 29, "%d", value); cur = &work[0]; - while (value != 0) { - res = value % 10; - value = value / 10; - *cur++ = '0' + res; - } - cur--; - while ((cur >= &work[0]) && (ptr - buffer < buffersize)) { - *ptr++ = *cur--; + while ((*cur) && (ptr - buffer < buffersize)) { + *ptr++ = *cur++; } } if (ptr - buffer < buffersize) { @@ -4577,6 +4577,9 @@ xmlXPathEqualNodeSetFloat(xmlXPathParserContextPtr ctxt, ret = 1; break; } + } else { /* NaN is unequal to any value */ + if (neq) + ret = 1; } } } @@ -7571,7 +7574,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) { buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); if (buffer == NULL) { - XP_ERROR0(XPATH_MEMORY_ERROR); + XP_ERRORNULL(XPATH_MEMORY_ERROR); } memcpy(buffer, buf, len); while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigname.xml */ @@ -7584,7 +7587,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) { buffer = (xmlChar *) xmlRealloc(buffer, max * sizeof(xmlChar)); if (buffer == NULL) { - XP_ERROR0(XPATH_MEMORY_ERROR); + XP_ERRORNULL(XPATH_MEMORY_ERROR); } } COPY_BUF(l,buffer,len,c); @@ -7820,7 +7823,7 @@ xmlXPathParseLiteral(xmlXPathParserContextPtr ctxt) { while ((IS_CHAR_CH(CUR)) && (CUR != '"')) NEXT; if (!IS_CHAR_CH(CUR)) { - XP_ERROR0(XPATH_UNFINISHED_LITERAL_ERROR); + XP_ERRORNULL(XPATH_UNFINISHED_LITERAL_ERROR); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; @@ -7831,13 +7834,13 @@ xmlXPathParseLiteral(xmlXPathParserContextPtr ctxt) { while ((IS_CHAR_CH(CUR)) && (CUR != '\'')) NEXT; if (!IS_CHAR_CH(CUR)) { - XP_ERROR0(XPATH_UNFINISHED_LITERAL_ERROR); + XP_ERRORNULL(XPATH_UNFINISHED_LITERAL_ERROR); } else { ret = xmlStrndup(q, CUR_PTR - q); NEXT; } } else { - XP_ERROR0(XPATH_START_LITERAL_ERROR); + XP_ERRORNULL(XPATH_START_LITERAL_ERROR); } return(ret); } @@ -7924,6 +7927,9 @@ xmlXPathCompVariableReference(xmlXPathParserContextPtr ctxt) { PUSH_LONG_EXPR(XPATH_OP_VARIABLE, 0, 0, 0, name, prefix); SKIP_BLANKS; + if ((ctxt->context != NULL) && (ctxt->context->flags & XML_XPATH_NOVAR)) { + XP_ERROR(XPATH_UNDEF_VARIABLE_ERROR); + } } /** @@ -8647,7 +8653,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, if (name == NULL) name = xmlXPathParseNCName(ctxt); if (name == NULL) { - XP_ERROR0(XPATH_EXPR_ERROR); + XP_ERRORNULL(XPATH_EXPR_ERROR); } blanks = IS_BLANK_CH(CUR); @@ -8668,7 +8674,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, else { if (name != NULL) xmlFree(name); - XP_ERROR0(XPATH_EXPR_ERROR); + XP_ERRORNULL(XPATH_EXPR_ERROR); } *test = NODE_TEST_TYPE; @@ -8683,7 +8689,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, name = NULL; if (CUR != ')') { name = xmlXPathParseLiteral(ctxt); - CHECK_ERROR 0; + CHECK_ERROR NULL; *test = NODE_TEST_PI; SKIP_BLANKS; } @@ -8691,7 +8697,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, if (CUR != ')') { if (name != NULL) xmlFree(name); - XP_ERROR0(XPATH_UNCLOSED_ERROR); + XP_ERRORNULL(XPATH_UNCLOSED_ERROR); } NEXT; return(name); @@ -8729,7 +8735,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, name = xmlXPathParseNCName(ctxt); if (name == NULL) { - XP_ERROR0(XPATH_EXPR_ERROR); + XP_ERRORNULL(XPATH_EXPR_ERROR); } } return(name); @@ -8919,10 +8925,18 @@ xmlXPathCompStep(xmlXPathParserContextPtr ctxt) { CHECK_ERROR; + type = (xmlXPathTypeVal) 0; + test = (xmlXPathTestVal) 0; name = xmlXPathCompNodeTest(ctxt, &test, &type, &prefix, name); if (test == 0) return; + if ((prefix != NULL) && (ctxt->context != NULL) && + (ctxt->context->flags & XML_XPATH_CHECKNS)) { + if (xmlXPathNsLookup(ctxt->context, prefix) == NULL) { + xmlXPathErr(ctxt, XPATH_UNDEF_PREFIX_ERROR); + } + } #ifdef DEBUG_STEP xmlGenericError(xmlGenericErrorContext, "Basis : computing new set\n"); @@ -10983,7 +10997,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) */ static xmlXPathObjectPtr xmlXPathRunStreamEval(xmlXPathContextPtr ctxt, xmlPatternPtr comp) { - int max_depth; + int max_depth, min_depth; int from_root; int ret, depth; xmlNodePtr cur = NULL, limit = NULL; @@ -10999,6 +11013,9 @@ xmlXPathRunStreamEval(xmlXPathContextPtr ctxt, xmlPatternPtr comp) { return(NULL); if (max_depth == -2) max_depth = 10000; + min_depth = xmlPatternMinDepth(comp); + if (min_depth == -1) + return(NULL); from_root = xmlPatternFromRoot(comp); if (from_root < 0) return(NULL); @@ -11010,13 +11027,20 @@ xmlXPathRunStreamEval(xmlXPathContextPtr ctxt, xmlPatternPtr comp) { if (retval == NULL) return(NULL); - if ((from_root) && (max_depth == 0)) { - xmlXPathNodeSetAddUnique(retval->nodesetval, (xmlNodePtr) ctxt->doc); - return(retval); - } else if (max_depth == 0) { - xmlXPathNodeSetAddUnique(retval->nodesetval, ctxt->node); + /* + * handle the special cases of / amd . being matched + */ + if (min_depth == 0) { + if (from_root) { + xmlXPathNodeSetAddUnique(retval->nodesetval, (xmlNodePtr) ctxt->doc); + } else { + xmlXPathNodeSetAddUnique(retval->nodesetval, ctxt->node); + } + } + if (max_depth == 0) { return(retval); } + if (from_root) { cur = (xmlNodePtr)ctxt->doc; } else if (ctxt->node != NULL) { @@ -11381,7 +11405,7 @@ xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) { if( pctxt->error != XPATH_EXPRESSION_OK ) { xmlXPathFreeParserContext(pctxt); - return (0); + return(NULL); } if (*pctxt->cur != 0) { |