From: Rob Richards Date: Wed, 8 Sep 2004 16:54:53 +0000 (+0000) Subject: MHF: fix issue with multiple xsl objects using registerPHPfunctions X-Git-Tag: php-5.0.2RC1~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e62db3b3c859ca8e43fdeb27013efd7757beeeb9;p=php MHF: fix issue with multiple xsl objects using registerPHPfunctions - also fixes threading issue --- diff --git a/ext/xsl/php_xsl.c b/ext/xsl/php_xsl.c index 70c8419012..904739a265 100644 --- a/ext/xsl/php_xsl.c +++ b/ext/xsl/php_xsl.c @@ -140,6 +140,13 @@ PHP_MINIT_FUNCTION(xsl) exsltRegisterAll(); #endif + xsltRegisterExtModuleFunction ((const xmlChar *) "functionString", + (const xmlChar *) "http://php.net/xsl", + xsl_ext_function_string_php); + xsltRegisterExtModuleFunction ((const xmlChar *) "function", + (const xmlChar *) "http://php.net/xsl", + xsl_ext_function_object_php); + REGISTER_LONG_CONSTANT("XSL_CLONE_AUTO", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XSL_CLONE_NEVER", -1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XSL_CLONE_ALWAYS", 1, CONST_CS | CONST_PERSISTENT); @@ -226,6 +233,12 @@ PHP_MSHUTDOWN_FUNCTION(xsl) /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ + + xsltUnregisterExtModuleFunction ((const xmlChar *) "functionString", + (const xmlChar *) "http://php.net/xsl"); + xsltUnregisterExtModuleFunction ((const xmlChar *) "function", + (const xmlChar *) "http://php.net/xsl"); + xsltCleanupGlobals(); return SUCCESS; diff --git a/ext/xsl/php_xsl.h b/ext/xsl/php_xsl.h index 7d9258feca..fb607659d7 100644 --- a/ext/xsl/php_xsl.h +++ b/ext/xsl/php_xsl.h @@ -64,6 +64,9 @@ void php_xsl_set_object(zval *wrapper, void *obj TSRMLS_DC); void xsl_objects_free_storage(void *object TSRMLS_DC); zval *php_xsl_create_object(xsltStylesheetPtr obj, int *found, zval *wrapper_in, zval *return_value TSRMLS_DC); +void xsl_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs); +void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs); + #define REGISTER_XSL_CLASS(ce, name, parent_ce, funcs, entry) \ INIT_CLASS_ENTRY(ce, name, funcs); \ ce.create_object = xsl_objects_new; \ diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index c5ebf1a879..a7d0efdf2f 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -27,9 +27,6 @@ #include "php_xsl.h" #include "ext/libxml/php_libxml.h" -static void xsl_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs); -static void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs); - /* * class xsl_xsltprocessor * @@ -76,13 +73,6 @@ static char *php_xsl_xslt_string_to_xpathexpr(const char *str TSRMLS_DC) return (char *) value; } -static void php_xsl_unregister_php_functions() { - xsltUnregisterExtModuleFunction ((const xmlChar *) "functionString", - (const xmlChar *) "http://php.net/xsl"); - xsltUnregisterExtModuleFunction ((const xmlChar *) "function", - (const xmlChar *) "http://php.net/xsl"); -} - /* {{{ php_xsl_xslt_make_params() Translates a PHP array to a libxslt parameters array */ @@ -139,6 +129,7 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t zval **args; zval *retval; int result, i, ret; + int error = 0; zend_fcall_info fci; zval handler; xmlXPathObjectPtr obj; @@ -148,17 +139,43 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t TSRMLS_FETCH(); + if (! zend_is_executing(TSRMLS_C)) { + xsltGenericError(xsltGenericErrorContext, + "xsltExtFunctionTest: Function called from outside of PHP\n"); + error = 1; + } else { tctxt = xsltXPathGetTransformContext(ctxt); if (tctxt == NULL) { xsltGenericError(xsltGenericErrorContext, "xsltExtFunctionTest: failed to get the transformation context\n"); + error = 1; + } else { + intern = (xsl_object *) tctxt->_private; + if (intern == NULL) { + xsltGenericError(xsltGenericErrorContext, + "xsltExtFunctionTest: failed to get the internal object\n"); + error = 1; + } + else if (intern->registerPhpFunctions == 0) { + xsltGenericError(xsltGenericErrorContext, + "xsltExtFunctionTest: PHP Object did not register PHP functions\n"); + error = 1; + } + } + } + + if (error == 1) { + for (i = nargs - 1; i >= 0; i--) { + obj = valuePop(ctxt); + xmlXPathFreeObject(obj); + } return; } fci.param_count = nargs - 1; if (fci.param_count > 0) { fci.params = safe_emalloc(fci.param_count, sizeof(zval**), 0); - args = safe_emalloc(nargs - 1, sizeof(zval *), 0); + args = safe_emalloc(fci.param_count, sizeof(zval *), 0); } /* Reverse order to pop values off ctxt stack */ for (i = nargs - 2; i >= 0; i--) { @@ -181,10 +198,10 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t xmlFree(str); } else if (type == 2) { int j; - dom_object *intern; + dom_object *domintern; array_init(args[i]); if (obj->nodesetval->nodeNr > 0) { - intern = (dom_object *) php_dom_object_get_data((void *) obj->nodesetval->nodeTab[0]->doc); + domintern = (dom_object *) php_dom_object_get_data((void *) obj->nodesetval->nodeTab[0]->doc); for (j = 0; j < obj->nodesetval->nodeNr; j++) { xmlNodePtr node = obj->nodesetval->nodeTab[j]; zval *child; @@ -209,7 +226,7 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t node->parent = nsparent; node->ns = curns; } - child = php_dom_create_object(node, &ret, NULL, child, intern TSRMLS_CC); + child = php_dom_create_object(node, &ret, NULL, child, domintern TSRMLS_CC); add_next_index_zval(args[i], child); } } @@ -264,7 +281,6 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) { xmlNode *nodep; dom_object *obj; - intern = (xsl_object *) tctxt->_private; if (intern->node_list == NULL) { ALLOC_HASHTABLE(intern->node_list); zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0); @@ -297,12 +313,12 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t } } -static void xsl_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs) +void xsl_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs) { xsl_ext_function_php(ctxt, nargs, 1); } -static void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs) +void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs) { xsl_ext_function_php(ctxt, nargs, 2); } @@ -425,10 +441,6 @@ static xmlDocPtr php_xsl_apply_stylesheet(xsl_object *intern, xsltStylesheetPtr intern->node_list = NULL; } - if (intern->registerPhpFunctions == 1) { - php_xsl_unregister_php_functions(); - } - if (intern->hasKeys == 1) { xmlFreeDoc(doc); } @@ -670,12 +682,6 @@ PHP_FUNCTION(xsl_xsltprocessor_register_php_functions) intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC); intern->registerPhpFunctions = 1; - xsltRegisterExtModuleFunction ((const xmlChar *) "functionString", - (const xmlChar *) "http://php.net/xsl", - xsl_ext_function_string_php); - xsltRegisterExtModuleFunction ((const xmlChar *) "function", - (const xmlChar *) "http://php.net/xsl", - xsl_ext_function_object_php); } /* }}} end xsl_xsltprocessor_register_php_functions(); */