mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-21 14:53:44 +03:00
Enhanced xmlXPathCompOpEvalToBoolean() to be also usable outside predicate
* xpath.c: Enhanced xmlXPathCompOpEvalToBoolean() to be also usable outside predicate evaluation; the intention is to use it via xmlXPathCompiledEvalToBoolean() for XSLT tests, like in <xsl:if test="/foo">.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
Thu Jun 29 12:28:07 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
||||||
|
|
||||||
|
* xpath.c: Enhanced xmlXPathCompOpEvalToBoolean() to be also
|
||||||
|
usable outside predicate evaluation; the intention is to
|
||||||
|
use it via xmlXPathCompiledEvalToBoolean() for XSLT tests,
|
||||||
|
like in <xsl:if test="/foo">.
|
||||||
|
|
||||||
Wed Jun 28 19:11:16 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
Wed Jun 28 19:11:16 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
||||||
|
|
||||||
* xpath.c: Fix a memory leak which occurred when using
|
* xpath.c: Fix a memory leak which occurred when using
|
||||||
|
78
xpath.c
78
xpath.c
@@ -599,7 +599,8 @@ xmlXPathCompOpEvalFirst(xmlXPathParserContextPtr ctxt,
|
|||||||
xmlXPathStepOpPtr op, xmlNodePtr *first);
|
xmlXPathStepOpPtr op, xmlNodePtr *first);
|
||||||
static int
|
static int
|
||||||
xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
|
xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
|
||||||
xmlXPathStepOpPtr op);
|
xmlXPathStepOpPtr op,
|
||||||
|
int isPredicate);
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
@@ -11542,7 +11543,7 @@ xmlXPathCompOpEvalPredicate(xmlXPathParserContextPtr ctxt,
|
|||||||
|
|
||||||
valuePush(ctxt, contextObj);
|
valuePush(ctxt, contextObj);
|
||||||
|
|
||||||
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp);
|
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1);
|
||||||
|
|
||||||
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1))
|
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1))
|
||||||
goto evaluation_error;
|
goto evaluation_error;
|
||||||
@@ -11688,7 +11689,7 @@ xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserContextPtr ctxt,
|
|||||||
contextNode);
|
contextNode);
|
||||||
|
|
||||||
valuePush(ctxt, contextObj);
|
valuePush(ctxt, contextObj);
|
||||||
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp);
|
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1);
|
||||||
|
|
||||||
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1))
|
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1))
|
||||||
goto evaluation_error;
|
goto evaluation_error;
|
||||||
@@ -13902,8 +13903,10 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
|
xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt,
|
||||||
xmlXPathStepOpPtr op)
|
xmlXPathStepOpPtr op,
|
||||||
|
int isPredicate)
|
||||||
{
|
{
|
||||||
|
xmlXPathObjectPtr resObj = NULL;
|
||||||
|
|
||||||
start:
|
start:
|
||||||
/* comp = ctxt->comp; */
|
/* comp = ctxt->comp; */
|
||||||
@@ -13911,12 +13914,8 @@ start:
|
|||||||
case XPATH_OP_END:
|
case XPATH_OP_END:
|
||||||
return (0);
|
return (0);
|
||||||
case XPATH_OP_VALUE:
|
case XPATH_OP_VALUE:
|
||||||
if (xmlXPathEvaluatePredicateResult(ctxt,
|
resObj = (xmlXPathObjectPtr) op->value4;
|
||||||
(xmlXPathObjectPtr) op->value4))
|
break;
|
||||||
{
|
|
||||||
return(1);
|
|
||||||
} else
|
|
||||||
return(0);
|
|
||||||
case XPATH_OP_SORT:
|
case XPATH_OP_SORT:
|
||||||
/*
|
/*
|
||||||
* We don't need sorting for boolean results. Skip this one.
|
* We don't need sorting for boolean results. Skip this one.
|
||||||
@@ -13926,9 +13925,7 @@ start:
|
|||||||
goto start;
|
goto start;
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
case XPATH_OP_COLLECT: {
|
case XPATH_OP_COLLECT:
|
||||||
xmlXPathObjectPtr resObj;
|
|
||||||
|
|
||||||
if (op->ch1 == -1)
|
if (op->ch1 == -1)
|
||||||
return(0);
|
return(0);
|
||||||
|
|
||||||
@@ -13943,19 +13940,8 @@ start:
|
|||||||
resObj = valuePop(ctxt);
|
resObj = valuePop(ctxt);
|
||||||
if (resObj == NULL)
|
if (resObj == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
break;
|
||||||
if (xmlXPathEvaluatePredicateResult(ctxt, resObj)) {
|
default:
|
||||||
xmlXPathReleaseObject(ctxt->context, resObj);
|
|
||||||
return(1);
|
|
||||||
} else {
|
|
||||||
xmlXPathReleaseObject(ctxt->context, resObj);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
xmlXPathObjectPtr resObj;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fallback to call xmlXPathCompOpEval().
|
* Fallback to call xmlXPathCompOpEval().
|
||||||
*/
|
*/
|
||||||
@@ -13965,19 +13951,32 @@ start:
|
|||||||
|
|
||||||
resObj = valuePop(ctxt);
|
resObj = valuePop(ctxt);
|
||||||
if (resObj == NULL)
|
if (resObj == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
/*
|
break;
|
||||||
* This checks if the result of the evaluation is 'true'.
|
|
||||||
*/
|
|
||||||
if (xmlXPathEvaluatePredicateResult(ctxt, resObj)) {
|
|
||||||
xmlXPathReleaseObject(ctxt->context, resObj);
|
|
||||||
return(1);
|
|
||||||
} else {
|
|
||||||
xmlXPathReleaseObject(ctxt->context, resObj);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resObj) {
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if (resObj->type == XPATH_BOOLEAN) {
|
||||||
|
res = resObj->boolval;
|
||||||
|
} else if (isPredicate) {
|
||||||
|
/*
|
||||||
|
* For predicates a result of type "number" is handled
|
||||||
|
* differently:
|
||||||
|
* SPEC XPath 1.0:
|
||||||
|
* "If the result is a number, the result will be converted
|
||||||
|
* to true if the number is equal to the context position
|
||||||
|
* and will be converted to false otherwise;"
|
||||||
|
*/
|
||||||
|
res = xmlXPathEvaluatePredicateResult(ctxt, resObj);
|
||||||
|
} else {
|
||||||
|
res = xmlXPathCastToBoolean(resObj);
|
||||||
|
}
|
||||||
|
xmlXPathReleaseObject(ctxt->context, resObj);
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14278,7 +14277,8 @@ xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toBool)
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (toBool)
|
if (toBool)
|
||||||
return(xmlXPathCompOpEvalToBoolean(ctxt, &comp->steps[comp->last]));
|
return(xmlXPathCompOpEvalToBoolean(ctxt,
|
||||||
|
&comp->steps[comp->last], 0));
|
||||||
else
|
else
|
||||||
xmlXPathCompOpEval(ctxt, &comp->steps[comp->last]);
|
xmlXPathCompOpEval(ctxt, &comp->steps[comp->last]);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user