diff --git a/include/libxml/xpath.h b/include/libxml/xpath.h index 6dae0780..b89e105c 100644 --- a/include/libxml/xpath.h +++ b/include/libxml/xpath.h @@ -515,6 +515,10 @@ XMLPUBFUN xmlXPathContextPtr xmlXPathNewContext (xmlDocPtr doc); XMLPUBFUN void xmlXPathFreeContext (xmlXPathContextPtr ctxt); +XMLPUBFUN void + xmlXPathSetErrorHandler(xmlXPathContextPtr ctxt, + xmlStructuredErrorFunc handler, + void *context); XMLPUBFUN int xmlXPathContextSetCache(xmlXPathContextPtr ctxt, int active, diff --git a/include/private/xpath.h b/include/private/xpath.h index 3128a111..72a69720 100644 --- a/include/private/xpath.h +++ b/include/private/xpath.h @@ -8,9 +8,9 @@ xmlInitXPathInternal(void); #ifdef LIBXML_XPATH_ENABLED XML_HIDDEN void -xmlXPathErrMemory(xmlXPathContextPtr ctxt, const char *extra); +xmlXPathErrMemory(xmlXPathContextPtr ctxt); XML_HIDDEN void -xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra); +xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt); #endif #endif /* XML_XPATH_H_PRIVATE__ */ diff --git a/xpath.c b/xpath.c index 0c04390b..b6a06a22 100644 --- a/xpath.c +++ b/xpath.c @@ -58,11 +58,6 @@ #endif #endif -#define TODO \ - xmlGenericError(xmlGenericErrorContext, \ - "Unimplemented block at %s:%d\n", \ - __FILE__, __LINE__); - /** * WITH_TIM_SORT: * @@ -634,24 +629,12 @@ static const char* const xmlXPathErrorMessages[] = { * Handle a memory allocation failure. */ void -xmlXPathErrMemory(xmlXPathContextPtr ctxt, const char *extra) +xmlXPathErrMemory(xmlXPathContextPtr ctxt) { - if (ctxt != NULL) { - xmlResetError(&ctxt->lastError); - if (extra) { - xmlChar buf[200]; - - xmlStrPrintf(buf, 200, - "Memory allocation failed : %s\n", - extra); - ctxt->lastError.message = (char *) xmlStrdup(buf); - } else { - ctxt->lastError.message = (char *) - xmlStrdup(BAD_CAST "Memory allocation failed\n"); - } - ctxt->lastError.domain = XML_FROM_XPATH; - ctxt->lastError.code = XML_ERR_NO_MEMORY; - } + if (ctxt == NULL) + return; + xmlRaiseMemoryError(ctxt->error, NULL, ctxt->userData, XML_FROM_XPATH, + &ctxt->lastError); } /** @@ -662,12 +645,12 @@ xmlXPathErrMemory(xmlXPathContextPtr ctxt, const char *extra) * Handle a memory allocation failure. */ void -xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra) +xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt) { - if (ctxt != NULL) { - ctxt->error = XPATH_MEMORY_ERROR; - xmlXPathErrMemory(ctxt->context, extra); - } + if (ctxt == NULL) + return; + ctxt->error = XPATH_MEMORY_ERROR; + xmlXPathErrMemory(ctxt->context); } /** @@ -680,70 +663,57 @@ xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra) void xmlXPathErr(xmlXPathParserContextPtr ctxt, int code) { - xmlErrorPtr err; + xmlStructuredErrorFunc serror = NULL; + void *data = NULL; + xmlNodePtr node = NULL; + int res; + if (ctxt == NULL) + return; if ((code < 0) || (code > MAXERRNO)) code = MAXERRNO; - if (ctxt == NULL) { - __xmlRaiseError(NULL, NULL, NULL, - NULL, NULL, XML_FROM_XPATH, - code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, - XML_ERR_ERROR, NULL, 0, - NULL, NULL, NULL, 0, 0, - "%s", xmlXPathErrorMessages[code]); - return; - } /* Only report the first error */ if (ctxt->error != 0) return; + ctxt->error = code; - if (ctxt->context == NULL) { - __xmlRaiseError(NULL, NULL, NULL, - NULL, NULL, XML_FROM_XPATH, - code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, - XML_ERR_ERROR, NULL, 0, - (const char *) ctxt->base, NULL, NULL, - ctxt->cur - ctxt->base, 0, - "%s", xmlXPathErrorMessages[code]); - return; - } - err = &ctxt->context->lastError; - /* Don't overwrite memory error. */ - if (err->code == XML_ERR_NO_MEMORY) - return; + if (ctxt->context != NULL) { + xmlErrorPtr err = &ctxt->context->lastError; - /* cleanup current last error */ - xmlResetError(err); - - err->domain = XML_FROM_XPATH; - err->code = code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK; - err->level = XML_ERR_ERROR; - if (ctxt->base != NULL) { - err->str1 = (char *) xmlStrdup(ctxt->base); - if (err->str1 == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + /* Don't overwrite memory error. */ + if (err->code == XML_ERR_NO_MEMORY) return; + + /* cleanup current last error */ + xmlResetError(err); + + err->domain = XML_FROM_XPATH; + err->code = code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK; + err->level = XML_ERR_ERROR; + if (ctxt->base != NULL) { + err->str1 = (char *) xmlStrdup(ctxt->base); + if (err->str1 == NULL) { + xmlXPathPErrMemory(ctxt); + return; + } } - } - err->int1 = ctxt->cur - ctxt->base; - err->node = ctxt->context->debugNode; - if (ctxt->context->error != NULL) { - ctxt->context->error(ctxt->context->userData, err); - } else { - int res; + err->int1 = ctxt->cur - ctxt->base; + err->node = ctxt->context->debugNode; - res = __xmlRaiseError(NULL, NULL, NULL, - NULL, ctxt->context->debugNode, XML_FROM_XPATH, - code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, - XML_ERR_ERROR, NULL, 0, - (const char *) ctxt->base, NULL, NULL, - ctxt->cur - ctxt->base, 0, - "%s", xmlXPathErrorMessages[code]); - if (res < 0) - xmlXPathPErrMemory(ctxt, NULL); + serror = ctxt->context->error; + data = ctxt->context->userData; + node = ctxt->context->debugNode; } + res = __xmlRaiseError(serror, NULL, data, NULL, node, XML_FROM_XPATH, + code + XML_XPATH_EXPRESSION_OK - XPATH_EXPRESSION_OK, + XML_ERR_ERROR, NULL, 0, + (const char *) ctxt->base, NULL, NULL, + ctxt->cur - ctxt->base, 0, + "%s", xmlXPathErrorMessages[code]); + if (res < 0) + xmlXPathPErrMemory(ctxt); } /** @@ -1008,7 +978,7 @@ xmlXPathCompExprAdd(xmlXPathParserContextPtr ctxt, int ch1, int ch2, xmlXPathStepOp *real; if (comp->maxStep >= XPATH_MAX_STEPS) { - xmlXPathPErrMemory(ctxt, "adding step\n"); + xmlXPathPErrMemory(ctxt); return(-1); } comp->maxStep *= 2; @@ -1016,7 +986,7 @@ xmlXPathCompExprAdd(xmlXPathParserContextPtr ctxt, int ch1, int ch2, comp->maxStep * sizeof(xmlXPathStepOp)); if (real == NULL) { comp->maxStep /= 2; - xmlXPathPErrMemory(ctxt, "adding step\n"); + xmlXPathPErrMemory(ctxt); return(-1); } comp->steps = real; @@ -1119,11 +1089,6 @@ struct _xmlXPathContextCache { * * ************************************************************************/ -#define STRANGE \ - xmlGenericError(xmlGenericErrorContext, \ - "Internal error at %s:%d\n", \ - __FILE__, __LINE__); - #ifdef LIBXML_DEBUG_ENABLED static void xmlXPathDebugDumpNode(FILE *output, xmlNodePtr cur, int depth) { @@ -1663,7 +1628,7 @@ xmlXPathContextSetCache(xmlXPathContextPtr ctxt, if (ctxt->cache == NULL) { ctxt->cache = xmlXPathNewCache(); if (ctxt->cache == NULL) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(-1); } } @@ -1716,7 +1681,7 @@ xmlXPathCacheWrapNodeSet(xmlXPathParserContextPtr pctxt, xmlNodeSetPtr val) ret = xmlXPathWrapNodeSet(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1751,7 +1716,7 @@ xmlXPathCacheWrapString(xmlXPathParserContextPtr pctxt, xmlChar *val) ret = xmlXPathWrapString(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1790,7 +1755,7 @@ xmlXPathCacheNewNodeSet(xmlXPathParserContextPtr pctxt, xmlNodePtr val) (val->type == XML_NAMESPACE_DECL)) { if (xmlXPathNodeSetAddUnique(ret->nodesetval, val) < 0) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); } else { ret->nodesetval->nodeTab[0] = val; ret->nodesetval->nodeNr = 1; @@ -1805,7 +1770,7 @@ xmlXPathCacheNewNodeSet(xmlXPathParserContextPtr pctxt, xmlNodePtr val) set = xmlXPathNodeSetCreate(val); if (set == NULL) { - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(NULL); } @@ -1821,7 +1786,7 @@ xmlXPathCacheNewNodeSet(xmlXPathParserContextPtr pctxt, xmlNodePtr val) } ret = xmlXPathNewNodeSet(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1851,7 +1816,7 @@ xmlXPathCacheNewString(xmlXPathParserContextPtr pctxt, const xmlChar *val) val = BAD_CAST ""; copy = xmlStrdup(val); if (copy == NULL) { - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(NULL); } @@ -1866,7 +1831,7 @@ xmlXPathCacheNewString(xmlXPathParserContextPtr pctxt, const xmlChar *val) ret = xmlXPathNewString(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1918,7 +1883,7 @@ xmlXPathCacheNewBoolean(xmlXPathParserContextPtr pctxt, int val) ret = xmlXPathNewBoolean(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1954,7 +1919,7 @@ xmlXPathCacheNewFloat(xmlXPathParserContextPtr pctxt, double val) ret = xmlXPathNewFloat(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -1984,7 +1949,7 @@ xmlXPathCacheObjectCopy(xmlXPathParserContextPtr pctxt, xmlXPathObjectPtr val) set = xmlXPathNodeSetMerge(NULL, val->nodesetval); if (set == NULL) { - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(NULL); } return(xmlXPathCacheWrapNodeSet(pctxt, set)); @@ -2001,7 +1966,7 @@ xmlXPathCacheObjectCopy(xmlXPathParserContextPtr pctxt, xmlXPathObjectPtr val) } ret = xmlXPathObjectCopy(val); if (ret == NULL) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(ret); } @@ -2037,7 +2002,7 @@ xmlXPathCastToNumberInternal(xmlXPathParserContextPtr ctxt, str = xmlXPathCastNodeSetToString(val->nodesetval); if (str == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ret = xmlXPathNAN; } else { ret = xmlXPathCastStringToNumber(str); @@ -2060,7 +2025,7 @@ xmlXPathCastToNumberInternal(xmlXPathParserContextPtr ctxt, case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO; + /* TODO */ ret = xmlXPathNAN; break; } @@ -2112,14 +2077,14 @@ valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value) /* * A NULL value typically indicates that a memory allocation failed. */ - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(-1); } if (ctxt->valueNr >= ctxt->valueMax) { xmlXPathObjectPtr *tmp; if (ctxt->valueMax >= XPATH_MAX_STACK_DEPTH) { - xmlXPathPErrMemory(ctxt, "XPath stack depth limit reached\n"); + xmlXPathPErrMemory(ctxt); xmlXPathFreeObject(value); return (-1); } @@ -2127,7 +2092,7 @@ valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value) 2 * ctxt->valueMax * sizeof(ctxt->valueTab[0])); if (tmp == NULL) { - xmlXPathPErrMemory(ctxt, "pushing value\n"); + xmlXPathPErrMemory(ctxt); xmlXPathFreeObject(value); return (-1); } @@ -2214,7 +2179,7 @@ xmlXPathPopString (xmlXPathParserContextPtr ctxt) { } ret = xmlXPathCastToString(obj); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); xmlXPathReleaseObject(ctxt->context, obj); return(ret); } @@ -3964,7 +3929,7 @@ xmlXPathRegisterFuncNS(xmlXPathContextPtr ctxt, const xmlChar *name, if (ctxt->funcHash == NULL) ctxt->funcHash = xmlHashCreate(0); if (ctxt->funcHash == NULL) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(-1); } if (f == NULL) @@ -3973,7 +3938,7 @@ XML_IGNORE_FPTR_CAST_WARNINGS ret = xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, (void *) f); XML_POP_WARNINGS if (ret < 0) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(-1); } @@ -4250,7 +4215,7 @@ xmlXPathRegisterNs(xmlXPathContextPtr ctxt, const xmlChar *prefix, if (ctxt->nsHash == NULL) ctxt->nsHash = xmlHashCreate(10); if (ctxt->nsHash == NULL) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(-1); } if (ns_uri == NULL) @@ -4259,12 +4224,12 @@ xmlXPathRegisterNs(xmlXPathContextPtr ctxt, const xmlChar *prefix, copy = xmlStrdup(ns_uri); if (copy == NULL) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(-1); } if (xmlHashUpdateEntry(ctxt->nsHash, prefix, copy, xmlHashDefaultDeallocator) < 0) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); xmlFree(copy); return(-1); } @@ -4558,10 +4523,9 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) { case XPATH_USERS: ret->user = val->user; break; - case XPATH_UNDEFINED: - xmlGenericError(xmlGenericErrorContext, - "xmlXPathObjectCopy: unsupported type %d\n", - val->type); + default: + xmlFree(ret); + ret = NULL; break; } return(ret); @@ -4825,7 +4789,7 @@ xmlXPathCastToString(xmlXPathObjectPtr val) { case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ ret = xmlStrdup((const xmlChar *) ""); break; } @@ -4869,7 +4833,7 @@ xmlXPathConvertString(xmlXPathObjectPtr val) { case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO; + /* TODO */ break; } xmlXPathFreeObject(val); @@ -4923,7 +4887,7 @@ xmlXPathNodeToNumberInternal(xmlXPathParserContextPtr ctxt, xmlNodePtr node) { return(xmlXPathNAN); strval = xmlXPathCastNodeToString(node); if (strval == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(xmlXPathNAN); } ret = xmlXPathCastStringToNumber(strval); @@ -5083,7 +5047,7 @@ xmlXPathCastToBoolean (xmlXPathObjectPtr val) { case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO; + /* TODO */ ret = 0; break; } @@ -5190,43 +5154,30 @@ xmlXPathFreeContext(xmlXPathContextPtr ctxt) { xmlFree(ctxt); } +/** + * xmlXPathSetErrorHandler: + * @ctxt: the XPath context + * @handler: error handler + * @data: user data which will be passed to the handler + * + * Set the error handler. + */ +void +xmlXPathSetErrorHandler(xmlXPathContextPtr ctxt, + xmlStructuredErrorFunc handler, void *data) { + if (ctxt == NULL) + return; + + ctxt->error = handler; + ctxt->userData = data; +} + /************************************************************************ * * * Routines to handle XPath parser contexts * * * ************************************************************************/ -#define CHECK_CTXT(ctxt) \ - if (ctxt == NULL) { \ - __xmlRaiseError(NULL, NULL, NULL, \ - NULL, NULL, XML_FROM_XPATH, \ - XML_ERR_INTERNAL_ERROR, XML_ERR_FATAL, \ - __FILE__, __LINE__, \ - NULL, NULL, NULL, 0, 0, \ - "NULL context pointer\n"); \ - return(NULL); \ - } \ - -#define CHECK_CTXT_NEG(ctxt) \ - if (ctxt == NULL) { \ - __xmlRaiseError(NULL, NULL, NULL, \ - NULL, NULL, XML_FROM_XPATH, \ - XML_ERR_INTERNAL_ERROR, XML_ERR_FATAL, \ - __FILE__, __LINE__, \ - NULL, NULL, NULL, 0, 0, \ - "NULL context pointer\n"); \ - return(-1); \ - } \ - - -#define CHECK_CONTEXT(ctxt) \ - if ((ctxt == NULL) || (ctxt->doc == NULL) || \ - (ctxt->doc->children == NULL)) { \ - xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_INVALID_CTXT); \ - return(NULL); \ - } - - /** * xmlXPathNewParserContext: * @str: the XPath expression @@ -5242,7 +5193,7 @@ xmlXPathNewParserContext(const xmlChar *str, xmlXPathContextPtr ctxt) { ret = (xmlXPathParserContextPtr) xmlMalloc(sizeof(xmlXPathParserContext)); if (ret == NULL) { - xmlXPathErrMemory(ctxt, "creating parser context\n"); + xmlXPathErrMemory(ctxt); return(NULL); } memset(ret, 0 , sizeof(xmlXPathParserContext)); @@ -5251,7 +5202,7 @@ xmlXPathNewParserContext(const xmlChar *str, xmlXPathContextPtr ctxt) { ret->comp = xmlXPathNewCompExpr(); if (ret->comp == NULL) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); xmlFree(ret->valueTab); xmlFree(ret); return(NULL); @@ -5279,7 +5230,7 @@ xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctxt) { ret = (xmlXPathParserContextPtr) xmlMalloc(sizeof(xmlXPathParserContext)); if (ret == NULL) { - xmlXPathErrMemory(ctxt, "creating evaluation context\n"); + xmlXPathErrMemory(ctxt); return(NULL); } memset(ret, 0 , sizeof(xmlXPathParserContext)); @@ -5289,7 +5240,7 @@ xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctxt) { xmlMalloc(10 * sizeof(xmlXPathObjectPtr)); if (ret->valueTab == NULL) { xmlFree(ret); - xmlXPathErrMemory(ctxt, "creating evaluation context\n"); + xmlXPathErrMemory(ctxt); return(NULL); } ret->valueNr = 0; @@ -5518,7 +5469,7 @@ xmlXPathCompareNodeSetFloat(xmlXPathParserContextPtr ctxt, int inf, int strict, if (ret) break; } else { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } } } @@ -5574,7 +5525,7 @@ xmlXPathCompareNodeSetString(xmlXPathParserContextPtr ctxt, int inf, int strict, if (ret) break; } else { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } } } @@ -5649,7 +5600,7 @@ xmlXPathCompareNodeSets(xmlXPathParserContextPtr ctxt, int inf, int strict, values2 = (double *) xmlMalloc(ns2->nodeNr * sizeof(double)); if (values2 == NULL) { - xmlXPathPErrMemory(ctxt, "comparing nodesets\n"); + xmlXPathPErrMemory(ctxt); xmlXPathFreeObject(arg1); xmlXPathFreeObject(arg2); return(0); @@ -5728,10 +5679,6 @@ xmlXPathCompareNodeSetValue(xmlXPathParserContextPtr ctxt, int inf, int strict, valuePush(ctxt, val); return(xmlXPathCompareValues(ctxt, inf, strict)); default: - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompareNodeSetValue: Can't compare node set " - "and object of type %d\n", - val->type); xmlXPathReleaseObject(ctxt->context, arg); xmlXPathReleaseObject(ctxt->context, val); XP_ERROR0(XPATH_INVALID_TYPE); @@ -5777,7 +5724,7 @@ xmlXPathEqualNodeSetString(xmlXPathParserContextPtr ctxt, if (xmlXPathNodeValHash(ns->nodeTab[i]) == hash) { str2 = xmlNodeGetContent(ns->nodeTab[i]); if (str2 == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(0); } if (xmlStrEqual(str, str2)) { @@ -5849,7 +5796,7 @@ xmlXPathEqualNodeSetFloat(xmlXPathParserContextPtr ctxt, ret = 1; } } else { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } } } @@ -5913,26 +5860,26 @@ xmlXPathEqualNodeSets(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr arg1, values1 = (xmlChar **) xmlMalloc(ns1->nodeNr * sizeof(xmlChar *)); if (values1 == NULL) { - xmlXPathPErrMemory(ctxt, "comparing nodesets\n"); + xmlXPathPErrMemory(ctxt); return(0); } hashs1 = (unsigned int *) xmlMalloc(ns1->nodeNr * sizeof(unsigned int)); if (hashs1 == NULL) { - xmlXPathPErrMemory(ctxt, "comparing nodesets\n"); + xmlXPathPErrMemory(ctxt); xmlFree(values1); return(0); } memset(values1, 0, ns1->nodeNr * sizeof(xmlChar *)); values2 = (xmlChar **) xmlMalloc(ns2->nodeNr * sizeof(xmlChar *)); if (values2 == NULL) { - xmlXPathPErrMemory(ctxt, "comparing nodesets\n"); + xmlXPathPErrMemory(ctxt); xmlFree(hashs1); xmlFree(values1); return(0); } hashs2 = (unsigned int *) xmlMalloc(ns2->nodeNr * sizeof(unsigned int)); if (hashs2 == NULL) { - xmlXPathPErrMemory(ctxt, "comparing nodesets\n"); + xmlXPathPErrMemory(ctxt); xmlFree(hashs1); xmlFree(values1); xmlFree(values2); @@ -5954,12 +5901,12 @@ xmlXPathEqualNodeSets(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr arg1, if (values1[i] == NULL) { values1[i] = xmlNodeGetContent(ns1->nodeTab[i]); if (values1[i] == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } if (values2[j] == NULL) { values2[j] = xmlNodeGetContent(ns2->nodeTab[j]); if (values2[j] == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } ret = xmlStrEqual(values1[i], values2[j]) ^ neq; if (ret) @@ -6017,7 +5964,7 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; case XPATH_NODESET: case XPATH_XSLT_TREE: @@ -6074,7 +6021,7 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; case XPATH_NODESET: case XPATH_XSLT_TREE: @@ -6135,7 +6082,7 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; case XPATH_NODESET: case XPATH_XSLT_TREE: @@ -6148,7 +6095,7 @@ xmlXPathEqualValuesCommon(xmlXPathParserContextPtr ctxt, case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; case XPATH_NODESET: case XPATH_XSLT_TREE: @@ -6228,7 +6175,7 @@ xmlXPathEqualValues(xmlXPathParserContextPtr ctxt) { case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; } xmlXPathReleaseObject(ctxt->context, arg1); @@ -6308,7 +6255,7 @@ xmlXPathNotEqualValues(xmlXPathParserContextPtr ctxt) { case XPATH_RANGE: case XPATH_LOCATIONSET: #endif /* LIBXML_XPTR_LOCS_ENABLED */ - TODO + /* TODO */ break; } xmlXPathReleaseObject(ctxt->context, arg1); @@ -7380,7 +7327,7 @@ xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { ctxt->context->tmpNsNr = 0; if (xmlGetNsListSafe(ctxt->context->doc, ctxt->context->node, &ctxt->context->tmpNsList) < 0) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(NULL); } if (ctxt->context->tmpNsList != NULL) { @@ -7627,20 +7574,20 @@ xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs) { ret = xmlXPathNodeSetCreate(NULL); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); if (obj->nodesetval != NULL) { for (i = 0; i < obj->nodesetval->nodeNr; i++) { tokens = xmlXPathCastNodeToString(obj->nodesetval->nodeTab[i]); if (tokens == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ns = xmlXPathGetElementsByIds(ctxt->context->doc, tokens); if (ns == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ret = xmlXPathNodeSetMerge(ret, ns); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); xmlXPathFreeNodeSet(ns); if (tokens != NULL) xmlFree(tokens); @@ -7652,11 +7599,11 @@ xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs) { } tokens = xmlXPathCastToString(obj); if (tokens == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); xmlXPathReleaseObject(ctxt->context, obj); ret = xmlXPathGetElementsByIds(ctxt->context->doc, tokens); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); xmlFree(tokens); valuePush(ctxt, xmlXPathCacheWrapNodeSet(ctxt, ret)); return; @@ -7832,7 +7779,7 @@ xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) if (fullname == cur->nodesetval->nodeTab[i]->name) fullname = xmlStrdup(cur->nodesetval->nodeTab[i]->name); if (fullname == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); valuePush(ctxt, xmlXPathCacheWrapString(ctxt, fullname)); } break; @@ -7891,7 +7838,7 @@ xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) { if (nargs == 0) { stringval = xmlXPathCastNodeToString(ctxt->context->node); if (stringval == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); valuePush(ctxt, xmlXPathCacheWrapString(ctxt, stringval)); return; } @@ -7902,7 +7849,7 @@ xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs) { if (cur->type != XPATH_STRING) { stringval = xmlXPathCastToString(cur); if (stringval == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); xmlXPathReleaseObject(ctxt->context, cur); cur = xmlXPathCacheWrapString(ctxt, stringval); } @@ -7935,7 +7882,7 @@ xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs) { content = xmlXPathCastNodeToString(ctxt->context->node); if (content == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, xmlUTF8Strlen(content))); xmlFree(content); @@ -7988,7 +7935,7 @@ xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs) { } tmp = xmlStrcat(newobj->stringval, cur->stringval); if (tmp == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); newobj->stringval = cur->stringval; cur->stringval = tmp; xmlXPathReleaseObject(ctxt->context, newobj); @@ -8160,7 +8107,7 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) { if ((i < j) && (i < xmlUTF8Strlen(str->stringval))) { xmlChar *ret = xmlUTF8Strsub(str->stringval, i, j - i); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); valuePush(ctxt, xmlXPathCacheNewString(ctxt, ret)); xmlFree(ret); } else { @@ -8278,7 +8225,7 @@ xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) { /* Use current context node */ source = xmlXPathCastNodeToString(ctxt->context->node); if (source == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); valuePush(ctxt, xmlXPathCacheWrapString(ctxt, source)); nargs = 1; } @@ -8357,7 +8304,7 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) { target = xmlBufCreate(); if (target == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); goto error; } @@ -8378,17 +8325,13 @@ xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs) { if ( ch & 0x80 ) { /* if not simple ascii, verify proper format */ if ( (ch & 0xc0) != 0xc0 ) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathTranslateFunction: Invalid UTF8 string\n"); - /* not asserting an XPath error is probably better */ + xmlXPathErr(ctxt, XPATH_INVALID_CHAR_ERROR); break; } /* then skip over remaining bytes for this char */ while ( (ch <<= 1) & 0x80 ) if ( (*cptr++ & 0xc0) != 0x80 ) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathTranslateFunction: Invalid UTF8 string\n"); - /* not asserting an XPath error is probably better */ + xmlXPathErr(ctxt, XPATH_INVALID_CHAR_ERROR); break; } if (ch & 0x80) /* must have had error encountered */ @@ -8518,7 +8461,7 @@ xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs) { while (cur != NULL) { if (xmlNodeGetAttrValue(cur, BAD_CAST "lang", XML_XML_NAMESPACE, &theLang) < 0) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); if (theLang != NULL) break; cur = cur->parent; @@ -8558,7 +8501,7 @@ xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) { } else { xmlChar* content = xmlNodeGetContent(ctxt->context->node); if (content == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); res = xmlXPathStringEvalNumber(content); valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, res)); @@ -8833,7 +8776,7 @@ xmlXPathParseNCName(xmlXPathParserContextPtr ctxt) { return(NULL); ret = xmlStrndup(ctxt->cur, count); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ctxt->cur = in; return(ret); } @@ -8916,7 +8859,7 @@ xmlXPathParseName(xmlXPathParserContextPtr ctxt) { } ret = xmlStrndup(ctxt->cur, count); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ctxt->cur = in; return(ret); } @@ -8965,7 +8908,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) { } buffer = (xmlChar *) xmlMallocAtomic(max); if (buffer == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(NULL); } memcpy(buffer, buf, len); @@ -8984,7 +8927,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) { tmp = (xmlChar *) xmlRealloc(buffer, max); if (tmp == NULL) { xmlFree(buffer); - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(NULL); } buffer = tmp; @@ -9001,7 +8944,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) { return(NULL); ret = xmlStrndup(buf, len); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return(ret); } @@ -9254,7 +9197,7 @@ xmlXPathParseLiteral(xmlXPathParserContextPtr ctxt) { } ret = xmlStrndup(q, CUR_PTR - q); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); NEXT; return(ret); } @@ -9540,7 +9483,7 @@ xmlXPathScanName(xmlXPathParserContextPtr ctxt) { } ret = xmlStrndup(cur, ctxt->cur - cur); if (ret == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); ctxt->cur = cur; return(ret); } @@ -10049,7 +9992,6 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, int blanks; if ((test == NULL) || (type == NULL) || (prefix == NULL)) { - STRANGE; return(NULL); } *type = (xmlXPathTypeVal) 0; @@ -10598,7 +10540,7 @@ xmlXPathNodeSetFilter(xmlXPathParserContextPtr ctxt, tmp = (xmlNodePtr *) xmlRealloc(set->nodeTab, nodeMax * sizeof(xmlNodePtr)); if (tmp == NULL) { - xmlXPathPErrMemory(ctxt, "shrinking nodeset\n"); + xmlXPathPErrMemory(ctxt); } else { set->nodeTab = tmp; set->nodeMax = nodeMax; @@ -10716,7 +10658,7 @@ xmlXPathLocationSetFilter(xmlXPathParserContextPtr ctxt, tmp = (xmlXPathObjectPtr *) xmlRealloc(locset->locTab, locMax * sizeof(xmlXPathObjectPtr)); if (tmp == NULL) { - xmlXPathPErrMemory(ctxt, "shrinking locset\n"); + xmlXPathPErrMemory(ctxt); } else { locset->locTab = tmp; locset->locMax = locMax; @@ -10756,8 +10698,6 @@ xmlXPathCompOpEvalPredicate(xmlXPathParserContextPtr ctxt, * Process inner predicates first. */ if (comp->steps[op->ch1].op != XPATH_OP_PREDICATE) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEvalPredicate: Expected a predicate\n"); XP_ERROR(XPATH_INVALID_OPERAND); } if (ctxt->context->depth >= XPATH_MAX_RECURSION_DEPTH) @@ -10840,11 +10780,11 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, if (hasAxisRange != 0) { \ if (++pos == maxPos) { \ if (addNode(seq, cur) < 0) \ - xmlXPathPErrMemory(ctxt, NULL); \ + xmlXPathPErrMemory(ctxt); \ goto axis_range_end; } \ } else { \ if (addNode(seq, cur) < 0) \ - xmlXPathPErrMemory(ctxt, NULL); \ + xmlXPathPErrMemory(ctxt); \ if (breakOnFirstHit) goto first_hit; } #define XP_TEST_HIT_NS \ @@ -10852,12 +10792,12 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, if (++pos == maxPos) { \ hasNsNodes = 1; \ if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ - xmlXPathPErrMemory(ctxt, NULL); \ + xmlXPathPErrMemory(ctxt); \ goto axis_range_end; } \ } else { \ hasNsNodes = 1; \ if (xmlXPathNodeSetAddNs(seq, xpctxt->node, (xmlNsPtr) cur) < 0) \ - xmlXPathPErrMemory(ctxt, NULL); \ + xmlXPathPErrMemory(ctxt); \ if (breakOnFirstHit) goto first_hit; } xmlXPathAxisVal axis = (xmlXPathAxisVal) op->value; @@ -11073,7 +11013,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, if (seq == NULL) { seq = xmlXPathNodeSetCreate(NULL); if (seq == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); total = 0; goto error; } @@ -11127,7 +11067,6 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, switch (test) { case NODE_TEST_NONE: total = 0; - STRANGE goto error; case NODE_TEST_TYPE: if (type == NODE_TYPE_NODE) { @@ -11205,7 +11144,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, } break; case NODE_TEST_NS:{ - TODO; + /* TODO */ break; } case NODE_TEST_NAME: @@ -11290,7 +11229,7 @@ axis_range_end: /* ----------------------------------------------------- */ } else { outSeq = mergeAndClear(outSeq, seq); if (outSeq == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } /* * Break if only a true/false result was requested. @@ -11310,7 +11249,7 @@ first_hit: /* ---------------------------------------------------------- */ } else { outSeq = mergeAndClear(outSeq, seq); if (outSeq == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } break; @@ -11373,7 +11312,7 @@ apply_predicates: /* --------------------------------------------------- */ } else { outSeq = mergeAndClear(outSeq, seq); if (outSeq == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } if (toBool) @@ -11404,7 +11343,7 @@ error: } else { outSeq = xmlXPathNodeSetCreate(NULL); if (outSeq == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } } if ((seq != NULL) && (seq != outSeq)) { @@ -11517,7 +11456,7 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt, arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, arg2->nodesetval); if (arg1->nodesetval == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } valuePush(ctxt, arg1); xmlXPathReleaseObject(ctxt->context, arg2); @@ -11659,7 +11598,7 @@ xmlXPathCompOpEvalLast(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op, arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, arg2->nodesetval); if (arg1->nodesetval == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } valuePush(ctxt, arg1); xmlXPathReleaseObject(ctxt->context, arg2); @@ -11950,7 +11889,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) arg1->nodesetval = xmlXPathNodeSetMerge(arg1->nodesetval, arg2->nodesetval); if (arg1->nodesetval == NULL) - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); } valuePush(ctxt, arg1); @@ -11998,10 +11937,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) URI = xmlXPathNsLookup(ctxt->context, op->value5); if (URI == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEval: variable %s bound to undefined prefix %s\n", - (char *) op->value4, (char *)op->value5); - ctxt->error = XPATH_UNDEF_PREFIX_ERROR; + XP_ERROR0(XPATH_UNDEF_PREFIX_ERROR); break; } val = xmlXPathVariableLookupNS(ctxt->context, @@ -12025,19 +11961,11 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) if (ctxt->error != XPATH_EXPRESSION_OK) break; } - if (ctxt->valueNr < frame + op->value) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEval: parameter error\n"); - ctxt->error = XPATH_INVALID_OPERAND; - break; - } + if (ctxt->valueNr < frame + op->value) + XP_ERROR0(XPATH_INVALID_OPERAND); for (i = 0; i < op->value; i++) { - if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEval: parameter error\n"); - ctxt->error = XPATH_INVALID_OPERAND; - break; - } + if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) + XP_ERROR0(XPATH_INVALID_OPERAND); } if (op->cache != NULL) func = op->cache; @@ -12050,22 +11978,13 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) op->value4); else { URI = xmlXPathNsLookup(ctxt->context, op->value5); - if (URI == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEval: function %s bound to undefined prefix %s\n", - (char *)op->value4, (char *)op->value5); - ctxt->error = XPATH_UNDEF_PREFIX_ERROR; - break; - } + if (URI == NULL) + XP_ERROR0(XPATH_UNDEF_PREFIX_ERROR); func = xmlXPathFunctionLookupNS(ctxt->context, op->value4, URI); } - if (func == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompOpEval: function %s not found\n", - (char *)op->value4); + if (func == NULL) XP_ERROR0(XPATH_UNKNOWN_FUNC_ERROR); - } op->cache = func; op->cacheURI = (void *) URI; } @@ -12395,9 +12314,7 @@ rangeto_error: } #endif /* LIBXML_XPTR_LOCS_ENABLED */ default: - xmlGenericError(xmlGenericErrorContext, - "XPath: unknown precompiled operation %d\n", op->op); - ctxt->error = XPATH_INVALID_OPERAND; + XP_ERROR0(XPATH_INVALID_OPERAND); break; } @@ -12561,7 +12478,7 @@ xmlXPathRunStreamEval(xmlXPathParserContextPtr pctxt, xmlPatternPtr comp, } if (res < 0) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); } if (max_depth == 0) { return(0); @@ -12603,7 +12520,7 @@ xmlXPathRunStreamEval(xmlXPathParserContextPtr pctxt, xmlPatternPtr comp, patstream = xmlPatternGetStreamCtxt(comp); if (patstream == NULL) { - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); return(-1); } @@ -12616,7 +12533,7 @@ xmlXPathRunStreamEval(xmlXPathParserContextPtr pctxt, xmlPatternPtr comp, if (toBool) goto return_1; if (xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, cur) < 0) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); } } depth = 0; @@ -12625,8 +12542,7 @@ next_node: do { if (ctxt->opLimit != 0) { if (ctxt->opCount >= ctxt->opLimit) { - xmlGenericError(xmlGenericErrorContext, - "XPath operation limit exceeded\n"); + xmlXPathErr(ctxt, XPATH_RECURSION_LIMIT_EXCEEDED); xmlFreeStreamCtxt(patstream); return(-1); } @@ -12648,13 +12564,13 @@ next_node: break; if (ret < 0) { - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); } else if (ret == 1) { if (toBool) goto return_1; if (xmlXPathNodeSetAddUnique((*resultSeq)->nodesetval, cur) < 0) - xmlXPathPErrMemory(pctxt, NULL); + xmlXPathPErrMemory(pctxt); } if ((cur->children == NULL) || (depth >= max_depth)) { ret = xmlStreamPop(patstream); @@ -12754,7 +12670,7 @@ xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toBool) ctxt->valueTab = (xmlXPathObjectPtr *) xmlMalloc(10 * sizeof(xmlXPathObjectPtr)); if (ctxt->valueTab == NULL) { - xmlXPathPErrMemory(ctxt, "creating evaluation context\n"); + xmlXPathPErrMemory(ctxt); return(-1); } ctxt->valueNr = 0; @@ -12795,8 +12711,7 @@ xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toBool) #endif comp = ctxt->comp; if (comp->last < 0) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathRunEval: last is less than zero\n"); + xmlXPathErr(ctxt, XPATH_STACK_ERROR); return(-1); } oldDepth = ctxt->context->depth; @@ -12849,7 +12764,7 @@ xmlXPathEvalPredicate(xmlXPathContextPtr ctxt, xmlXPathObjectPtr res) { return((res->stringval != NULL) && (xmlStrlen(res->stringval) != 0)); default: - STRANGE + break; } return(0); } @@ -12900,7 +12815,7 @@ xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt, } #endif default: - STRANGE + break; } return(0); } @@ -12952,7 +12867,7 @@ xmlXPathTryStreamCompile(xmlXPathContextPtr ctxt, const xmlChar *str) { if (ctxt->nsNr > 0) { namespaces = xmlMalloc(2 * (ctxt->nsNr + 1) * sizeof(xmlChar*)); if (namespaces == NULL) { - xmlXPathErrMemory(ctxt, "allocating namespaces array\n"); + xmlXPathErrMemory(ctxt); return(NULL); } for (i = 0, j = 0; (j < ctxt->nsNr); j++) { @@ -12971,13 +12886,13 @@ xmlXPathTryStreamCompile(xmlXPathContextPtr ctxt, const xmlChar *str) { xmlFree((xmlChar **)namespaces); } if (res < 0) { - xmlXPathErrMemory(ctxt, NULL); + xmlXPathErrMemory(ctxt); return(NULL); } if ((stream != NULL) && (xmlPatternStreamable(stream) == 1)) { comp = xmlXPathNewCompExpr(); if (comp == NULL) { - xmlXPathErrMemory(ctxt, "allocating streamable expression\n"); + xmlXPathErrMemory(ctxt); xmlFreePattern(stream); return(NULL); } @@ -13170,14 +13085,12 @@ xmlXPathCompiledEvalInternal(xmlXPathCompExprPtr comp, int toBool) { xmlXPathParserContextPtr pctxt; - xmlXPathObjectPtr resObj; + xmlXPathObjectPtr resObj = NULL; #ifndef LIBXML_THREAD_ENABLED static int reentance = 0; #endif int res; - CHECK_CTXT_NEG(ctxt) - if (comp == NULL) return(-1); xmlInitParser(); @@ -13195,19 +13108,11 @@ xmlXPathCompiledEvalInternal(xmlXPathCompExprPtr comp, return(-1); res = xmlXPathRunEval(pctxt, toBool); - if (pctxt->error != XPATH_EXPRESSION_OK) { - resObj = NULL; - } else { - resObj = valuePop(pctxt); - if (resObj == NULL) { - if (!toBool) - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompiledEval: No result on the stack.\n"); - } else if (pctxt->valueNr > 0) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathCompiledEval: %d object(s) left on the stack.\n", - pctxt->valueNr); - } + if (pctxt->error == XPATH_EXPRESSION_OK) { + if (pctxt->valueNr != ((toBool) ? 0 : 1)) + xmlXPathErr(pctxt, XPATH_STACK_ERROR); + else if (!toBool) + resObj = valuePop(pctxt); } if (resObjPtr) @@ -13284,7 +13189,7 @@ xmlXPathEvalExpr(xmlXPathParserContextPtr ctxt) { comp = xmlXPathTryStreamCompile(ctxt->context, ctxt->base); if ((comp == NULL) && (ctxt->context->lastError.code == XML_ERR_NO_MEMORY)) { - xmlXPathPErrMemory(ctxt, NULL); + xmlXPathPErrMemory(ctxt); return; } if (comp != NULL) { @@ -13333,7 +13238,8 @@ xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) { xmlXPathParserContextPtr ctxt; xmlXPathObjectPtr res; - CHECK_CTXT(ctx) + if (ctx == NULL) + return(NULL); xmlInitParser(); @@ -13346,16 +13252,11 @@ xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) { if (ctxt->error != XPATH_EXPRESSION_OK) { res = NULL; + } else if (ctxt->valueNr != 1) { + xmlXPathErr(ctxt, XPATH_STACK_ERROR); + res = NULL; } else { res = valuePop(ctxt); - if (res == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathEval: No result on the stack.\n"); - } else if (ctxt->valueNr > 0) { - xmlGenericError(xmlGenericErrorContext, - "xmlXPathEval: %d object(s) left on the stack.\n", - ctxt->valueNr); - } } xmlXPathFreeParserContext(ctxt); diff --git a/xpointer.c b/xpointer.c index f1d46113..32744ca0 100644 --- a/xpointer.c +++ b/xpointer.c @@ -47,16 +47,6 @@ #include "private/error.h" #include "private/xpath.h" -#define TODO \ - xmlGenericError(xmlGenericErrorContext, \ - "Unimplemented block at %s:%d\n", \ - __FILE__, __LINE__); - -#define STRANGE \ - xmlGenericError(xmlGenericErrorContext, \ - "Internal error at %s:%d\n", \ - __FILE__, __LINE__); - /************************************************************************ * * * Some factorized error routines * @@ -71,50 +61,51 @@ * Handle an XPointer error */ static void LIBXML_ATTR_FORMAT(3,0) -xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error, +xmlXPtrErr(xmlXPathParserContextPtr ctxt, int code, const char * msg, const xmlChar *extra) { - if (ctxt->context->lastError.code == XML_ERR_NO_MEMORY) + xmlStructuredErrorFunc serror = NULL; + void *data = NULL; + xmlNodePtr node = NULL; + int res; + + if (ctxt == NULL) return; - if (ctxt != NULL) - ctxt->error = error; - if ((ctxt == NULL) || (ctxt->context == NULL)) { - __xmlRaiseError(NULL, NULL, NULL, - NULL, NULL, XML_FROM_XPOINTER, error, - XML_ERR_ERROR, NULL, 0, - (const char *) extra, NULL, NULL, 0, 0, - msg, extra); - return; - } - - /* cleanup current last error */ - xmlResetError(&ctxt->context->lastError); - - ctxt->context->lastError.domain = XML_FROM_XPOINTER; - ctxt->context->lastError.code = error; - ctxt->context->lastError.level = XML_ERR_ERROR; - ctxt->context->lastError.str1 = (char *) xmlStrdup(ctxt->base); - if (ctxt->context->lastError.str1 == NULL) { - xmlXPathPErrMemory(ctxt, NULL); + /* Only report the first error */ + if (ctxt->error != 0) return; - } - ctxt->context->lastError.int1 = ctxt->cur - ctxt->base; - ctxt->context->lastError.node = ctxt->context->debugNode; - if (ctxt->context->error != NULL) { - ctxt->context->error(ctxt->context->userData, - &ctxt->context->lastError); - } else { - int res; - res = __xmlRaiseError(NULL, NULL, NULL, - NULL, ctxt->context->debugNode, XML_FROM_XPOINTER, - error, XML_ERR_ERROR, NULL, 0, - (const char *) extra, (const char *) ctxt->base, NULL, - ctxt->cur - ctxt->base, 0, - msg, extra); - if (res < 0) - xmlXPathPErrMemory(ctxt, NULL); + ctxt->error = code; + + if (ctxt->context != NULL) { + xmlErrorPtr err = &ctxt->context->lastError; + + /* cleanup current last error */ + xmlResetError(err); + + err->domain = XML_FROM_XPOINTER; + err->code = code; + err->level = XML_ERR_ERROR; + err->str1 = (char *) xmlStrdup(ctxt->base); + if (err->str1 == NULL) { + xmlXPathPErrMemory(ctxt); + return; + } + err->int1 = ctxt->cur - ctxt->base; + err->node = ctxt->context->debugNode; + + serror = ctxt->context->error; + data = ctxt->context->userData; + node = ctxt->context->debugNode; } + + res = __xmlRaiseError(serror, NULL, data, NULL, node, + XML_FROM_XPOINTER, code, XML_ERR_ERROR, NULL, 0, + (const char *) extra, (const char *) ctxt->base, + NULL, ctxt->cur - ctxt->base, 0, + msg, extra); + if (res < 0) + xmlXPathPErrMemory(ctxt); } /************************************************************************ @@ -211,12 +202,9 @@ xmlXPtrGetNthChild(xmlNodePtr cur, int no) { * Handle a redefinition of attribute error */ static void -xmlXPtrErrMemory(const char *extra) +xmlXPtrErrMemory(const char *extra ATTRIBUTE_UNUSED) { - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_XPOINTER, - XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Memory allocation failed : %s\n", extra); + xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_XPOINTER, NULL); } /** @@ -970,7 +958,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) { len++; buffer = (xmlChar *) xmlMallocAtomic(len); if (buffer == NULL) { - xmlXPathPErrMemory(ctxt, "allocating buffer"); + xmlXPathPErrMemory(ctxt); xmlFree(name); return; } @@ -1241,7 +1229,7 @@ xmlXPtrEvalXPointer(xmlXPathParserContextPtr ctxt) { ctxt->valueTab = (xmlXPathObjectPtr *) xmlMalloc(10 * sizeof(xmlXPathObjectPtr)); if (ctxt->valueTab == NULL) { - xmlXPathPErrMemory(ctxt, "allocating evaluation context"); + xmlXPathPErrMemory(ctxt); return; } ctxt->valueNr = 0; @@ -1366,7 +1354,7 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) { ctxt = xmlXPathNewParserContext(str, ctx); if (ctxt == NULL) { - xmlXPathErrMemory(ctx, NULL); + xmlXPathErrMemory(ctx); return(NULL); } xmlXPtrEvalXPointer(ctxt); @@ -1553,7 +1541,7 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { /* Do not copy DTD information */ break; case XML_ENTITY_DECL: - TODO /* handle crossing entities -> stack needed */ + /* TODO: handle crossing entities -> stack needed */ break; case XML_XINCLUDE_START: case XML_XINCLUDE_END: @@ -1561,7 +1549,6 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { break; case XML_ATTRIBUTE_NODE: /* Humm, should not happen ! */ - STRANGE break; default: tmp = xmlCopyNode(cur, 1); @@ -1569,7 +1556,6 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { } if (tmp != NULL) { if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - STRANGE return(NULL); } if (last != NULL) @@ -1583,7 +1569,6 @@ xmlXPtrBuildRangeNodeList(xmlXPathObjectPtr range) { * Skip to next node in document order */ if ((list == NULL) || ((last == NULL) && (parent == NULL))) { - STRANGE return(NULL); } cur = xmlXPtrAdvanceNode(cur, NULL); @@ -2012,7 +1997,8 @@ xmlXPtrCoveringRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { } } default: - TODO /* missed one case ??? */ + /* TODO: missed one case ??? */ + break; } return(NULL); } @@ -2159,7 +2145,8 @@ xmlXPtrInsideRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { } } default: - TODO /* missed one case ??? */ + /* TODO: missed one case ??? */ + break; } return(NULL); } @@ -2294,7 +2281,6 @@ found: (cur->type != XML_HTML_DOCUMENT_NODE) && (cur->type != XML_CDATA_SECTION_NODE)) { if (cur->type == XML_ENTITY_REF_NODE) { /* Shouldn't happen */ - TODO goto skip; } goto next; @@ -2368,7 +2354,6 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { } if (pos > len) { /* Strange, the indx in the text node is greater than it's len */ - STRANGE pos = len; } if (pos + bytes >= len) {