summaryrefslogtreecommitdiff
path: root/xpath.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2005-02-05 12:06:19 +0000
committerMike Hommey <mh@glandium.org>2005-02-05 12:06:19 +0000
commita7457388701e6ccba9091ba3ec09505dc903b758 (patch)
tree80a7d0fba3968fee73cc71a62ffe1af039396f29 /xpath.c
parentf51dd67f3a3f472af0620391eb588eeca4533689 (diff)
downloadlibxml2-a7457388701e6ccba9091ba3ec09505dc903b758.tar.gz
Load /tmp/tmp.5kkLmZ/libxml2-2.6.17 intoupstream/2.6.17
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'xpath.c')
-rw-r--r--xpath.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/xpath.c b/xpath.c
index fad8c26..c075711 100644
--- a/xpath.c
+++ b/xpath.c
@@ -64,7 +64,7 @@
* any use of the macros IS_ASCII_CHARACTER and IS_ASCII_DIGIT)
*/
-#if defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_XPATH_ENABLED)
+#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
/************************************************************************
* *
* Floating point stuff *
@@ -208,10 +208,11 @@ static const char *xmlXPathErrorMessages[] = {
"Undefined namespace prefix\n",
"Encoding error\n",
"Char out of XML range\n",
- "Invalid or inclomplete context\n"
+ "Invalid or incomplete context\n",
+ "?? Unknown error ??\n" /* Must be last in the list! */
};
-
-
+#define MAXERRNO ((int)(sizeof(xmlXPathErrorMessages) / \
+ sizeof(xmlXPathErrorMessages[0])) - 1)
/**
* xmlXPathErrMemory:
* @ctxt: an XPath context
@@ -276,11 +277,13 @@ xmlXPathPErrMemory(xmlXPathParserContextPtr ctxt, const char *extra)
* @ctxt: a XPath parser context
* @error: the error code
*
- * Handle a Relax NG Parsing error
+ * Handle an XPath error
*/
void
xmlXPathErr(xmlXPathParserContextPtr ctxt, int error)
{
+ if ((error < 0) || (error > MAXERRNO))
+ error = MAXERRNO;
if (ctxt == NULL) {
__xmlRaiseError(NULL, NULL, NULL,
NULL, NULL, XML_FROM_XPATH,
@@ -2813,7 +2816,7 @@ xmlXPathRegisterFuncNS(xmlXPathContextPtr ctxt, const xmlChar *name,
return(-1);
if (f == NULL)
return(xmlHashRemoveEntry2(ctxt->funcHash, name, ns_uri, NULL));
- return(xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, (void *) f));
+ return(xmlHashAddEntry2(ctxt->funcHash, name, ns_uri, XML_CAST_FPTR(f)));
}
/**
@@ -2875,13 +2878,14 @@ xmlXPathFunctionLookup(xmlXPathContextPtr ctxt, const xmlChar *name) {
xmlXPathFunction
xmlXPathFunctionLookupNS(xmlXPathContextPtr ctxt, const xmlChar *name,
const xmlChar *ns_uri) {
+ xmlXPathFunction ret;
+
if (ctxt == NULL)
return(NULL);
if (name == NULL)
return(NULL);
if (ctxt->funcLookupFunc != NULL) {
- xmlXPathFunction ret;
xmlXPathFuncLookupFunc f;
f = ctxt->funcLookupFunc;
@@ -2893,7 +2897,8 @@ xmlXPathFunctionLookupNS(xmlXPathContextPtr ctxt, const xmlChar *name,
if (ctxt->funcHash == NULL)
return(NULL);
- return((xmlXPathFunction) xmlHashLookup2(ctxt->funcHash, name, ns_uri));
+ XML_CAST_FPTR(ret) = xmlHashLookup2(ctxt->funcHash, name, ns_uri);
+ return(ret);
}
/**
@@ -3917,9 +3922,12 @@ xmlXPathNewContext(xmlDocPtr doc) {
*/
void
xmlXPathFreeContext(xmlXPathContextPtr ctxt) {
+ if (ctxt == NULL) return;
+
xmlXPathRegisteredNsCleanup(ctxt);
xmlXPathRegisteredFuncsCleanup(ctxt);
xmlXPathRegisteredVariablesCleanup(ctxt);
+ xmlResetError(&ctxt->lastError);
xmlFree(ctxt);
}
@@ -3931,9 +3939,13 @@ xmlXPathFreeContext(xmlXPathContextPtr ctxt) {
#define CHECK_CTXT(ctxt) \
if (ctxt == NULL) { \
- xmlGenericError(xmlGenericErrorContext, \
- "%s:%d Internal error: ctxt == NULL\n", \
- __FILE__, __LINE__); \
+ __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); \
} \
@@ -10397,7 +10409,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
return (total);
}
if (op->cache != NULL)
- func = (xmlXPathFunction) op->cache;
+ XML_CAST_FPTR(func) = op->cache;
else {
const xmlChar *URI = NULL;
@@ -10422,7 +10434,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
op->value4);
XP_ERROR0(XPATH_UNKNOWN_FUNC_ERROR);
}
- op->cache = (void *) func;
+ op->cache = XML_CAST_FPTR(func);
op->cacheURI = (void *) URI;
}
oldFunc = ctxt->context->function;
@@ -11105,12 +11117,12 @@ xmlXPathCompiledEval(xmlXPathCompExprPtr comp, xmlXPathContextPtr ctx) {
static int reentance = 0;
#endif
- if ((comp == NULL) || (ctx == NULL))
+ CHECK_CTXT(ctx)
+
+ if (comp == NULL)
return(NULL);
xmlXPathInit();
- CHECK_CONTEXT(ctx)
-
#ifndef LIBXML_THREAD_ENABLED
reentance++;
if (reentance > 1)
@@ -11194,9 +11206,9 @@ xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) {
xmlXPathObjectPtr res, tmp, init = NULL;
int stack = 0;
- xmlXPathInit();
+ CHECK_CTXT(ctx)
- CHECK_CONTEXT(ctx)
+ xmlXPathInit();
ctxt = xmlXPathNewParserContext(str, ctx);
xmlXPathEvalExpr(ctxt);
@@ -11250,9 +11262,9 @@ xmlXPathEvalExpression(const xmlChar *str, xmlXPathContextPtr ctxt) {
xmlXPathObjectPtr res, tmp;
int stack = 0;
- xmlXPathInit();
+ CHECK_CTXT(ctxt)
- CHECK_CONTEXT(ctxt)
+ xmlXPathInit();
pctxt = xmlXPathNewParserContext(str, ctxt);
xmlXPathEvalExpr(pctxt);