diff options
author | Rob Richards <rrichards@php.net> | 2004-09-08 16:54:17 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2004-09-08 16:54:17 +0000 |
commit | da5ff5d9f1ca9ec9bdd16b6a367c6de533b83bf8 (patch) | |
tree | 538b2896c654e297a17076247b96793e4b61c861 | |
parent | ccb99d0a1e3e2240ad803436c34fd055feeb59cc (diff) | |
download | php-git-da5ff5d9f1ca9ec9bdd16b6a367c6de533b83bf8.tar.gz |
fix issue with multiple xsl objects using registerPHPfunctions
- also fixes threading issue
-rw-r--r-- | ext/xsl/php_xsl.c | 13 | ||||
-rw-r--r-- | ext/xsl/php_xsl.h | 3 | ||||
-rw-r--r-- | ext/xsl/xsltprocessor.c | 68 |
3 files changed, 53 insertions, 31 deletions
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 1ed075a370..b8f4f4e4c0 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,13 +139,39 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t TSRMLS_FETCH(); - tctxt = xsltXPathGetTransformContext(ctxt); - if (tctxt == NULL) { + if (! zend_is_executing(TSRMLS_C)) { xsltGenericError(xsltGenericErrorContext, - "xsltExtFunctionTest: failed to get the transformation context\n"); + "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); @@ -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); } @@ -424,10 +440,6 @@ static xmlDocPtr php_xsl_apply_stylesheet(xsl_object *intern, xsltStylesheetPtr FREE_HASHTABLE(intern->node_list); intern->node_list = NULL; } - - if (intern->registerPhpFunctions == 1) { - php_xsl_unregister_php_functions(); - } if (intern->hasKeys == 1) { xmlFreeDoc(doc); @@ -695,13 +707,7 @@ 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(); */ |