From e2a2aa75b00c7f867c48fc89fe4beffe23ae3497 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Thu, 9 Aug 2001 12:15:58 +0000 Subject: [PATCH] Restore xpath_eval() and the underlying php_xpathptr_eval(). It still leaks like crazy, but does not appear to crash, and seems to work correctly. Anyone who can possibly test this, please do. @- Restore xpath_eval() and php_xpathptr_eval() for 4.0.7. There @ are still some known leaks. --- ext/domxml/php_domxml.c | 146 ++++++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 58 deletions(-) diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 41cbfb6df6..9a2880d9c6 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -1,18 +1,18 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP version 4.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | Copyright (c) 1997-2001 The PHP Group | +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Uwe Steinmann | + | Authors: Uwe Steinmann | +----------------------------------------------------------------------+ */ @@ -102,13 +102,13 @@ static zend_function_entry domxml_functions[] = { PHP_FE(domxml_new_xmldoc, NULL) PHP_FALIAS(new_xmldoc, domxml_new_xmldoc, NULL) #if defined(LIBXML_XPATH_ENABLED) -/* PHP_FE(xpath_new_context, NULL) + PHP_FE(xpath_new_context, NULL) PHP_FE(xpath_eval, NULL) - PHP_FE(xpath_eval_expression, NULL) */ + PHP_FE(xpath_eval_expression, NULL) #endif #if defined(LIBXML_XPTR_ENABLED) -/* PHP_FE(xptr_new_context, NULL) - PHP_FE(xptr_eval, NULL) */ + PHP_FE(xptr_new_context, NULL) + PHP_FE(xptr_eval, NULL) #endif {NULL, NULL, NULL} }; @@ -1012,35 +1012,35 @@ PHP_FUNCTION(domxml_node_name) n = php_dom_get_object(id, le_domxmlnodep, 0 TSRMLS_CC); switch (n->type) - { - case XML_ELEMENT_NODE: - str = n->name; - break; - case XML_TEXT_NODE: - str = "#text"; - break; - case XML_CDATA_SECTION_NODE: - str = "#cdata-section"; - break; - case XML_ENTITY_REF_NODE: - str = n->name; - break; - case XML_ENTITY_NODE: - str = NULL; - break; - case XML_PI_NODE: - str = n->name; - break; - case XML_COMMENT_NODE: - str = "#comment"; - break; - case XML_DOCUMENT_FRAG_NODE: - str = "#document-fragment"; - break; - default: - str = NULL; - break; - } + { + case XML_ELEMENT_NODE: + str = n->name; + break; + case XML_TEXT_NODE: + str = "#text"; + break; + case XML_CDATA_SECTION_NODE: + str = "#cdata-section"; + break; + case XML_ENTITY_REF_NODE: + str = n->name; + break; + case XML_ENTITY_NODE: + str = NULL; + break; + case XML_PI_NODE: + str = n->name; + break; + case XML_COMMENT_NODE: + str = "#comment"; + break; + case XML_DOCUMENT_FRAG_NODE: + str = "#document-fragment"; + break; + default: + str = NULL; + break; + } RETURN_STRING((char *) str, 1); } /* }}} */ @@ -1060,17 +1060,17 @@ PHP_FUNCTION(domxml_node_value) RETURN_FALSE; } switch (n->type) - { - case XML_TEXT_NODE: - case XML_COMMENT_NODE: - case XML_CDATA_SECTION_NODE: - case XML_PI_NODE: - str = n->content; - break; - default: - str = NULL; - break; - } + { + case XML_TEXT_NODE: + case XML_COMMENT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_PI_NODE: + str = n->content; + break; + default: + str = NULL; + break; + } RETURN_STRING(str, 1); } /* }}} */ @@ -2477,20 +2477,49 @@ PHP_FUNCTION(xptr_new_context) } /* }}} */ +/* {{{ */ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr) { - zval *id, *str, *rv; + zval *id, *str, *rv, *contextnode; xmlXPathContextPtr ctxp; xmlXPathObjectPtr xpathobjp; + xmlNode *contextnodep; int ret; - if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } + contextnode = NULL; + contextnodep = NULL; id = getThis(); + + if (! id) { + switch(ZEND_NUM_ARGS()) { + case 2: + if ((getParameters(ht, 2, &id, &str)) == FAILURE) + { + WRONG_PARAM_COUNT; + } + break; + + case 3: + if ((getParameters(ht, 3, &id, &str, &contextnode)) == FAILURE) + { + WRONG_PARAM_COUNT; + } + break; + + default: + WRONG_PARAM_COUNT; + } + } + + ctxp = php_xpath_get_context(id, le_xpathctxp, 0 TSRMLS_CC); convert_to_string(str); + + if (contextnode) { + contextnodep = php_dom_get_object(contextnode, le_domxmlnodep, 0); + } + ctxp->node = contextnodep; #if defined(LIBXML_XPTR_ENABLED) if(mode == PHP_XPTR) { @@ -2504,7 +2533,8 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr) #if defined(LIBXML_XPTR_ENABLED) } #endif - + + ctxp->node = NULL; if (!xpathobjp) { RETURN_FALSE; } -- 2.40.0