rrichards Wed Sep 8 12:54:17 2004 EDT Modified files: /php-src/ext/xsl php_xsl.c php_xsl.h xsltprocessor.c Log: fix issue with multiple xsl objects using registerPHPfunctions - also fixes threading issue http://cvs.php.net/diff.php/php-src/ext/xsl/php_xsl.c?r1=1.26&r2=1.27&ty=u Index: php-src/ext/xsl/php_xsl.c diff -u php-src/ext/xsl/php_xsl.c:1.26 php-src/ext/xsl/php_xsl.c:1.27 --- php-src/ext/xsl/php_xsl.c:1.26 Mon Aug 30 10:59:30 2004 +++ php-src/ext/xsl/php_xsl.c Wed Sep 8 12:54:17 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_xsl.c,v 1.26 2004/08/30 14:59:30 rrichards Exp $ */ +/* $Id: php_xsl.c,v 1.27 2004/09/08 16:54:17 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -140,6 +140,13 @@ 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 @@ /* 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; http://cvs.php.net/diff.php/php-src/ext/xsl/php_xsl.h?r1=1.11&r2=1.12&ty=u Index: php-src/ext/xsl/php_xsl.h diff -u php-src/ext/xsl/php_xsl.h:1.11 php-src/ext/xsl/php_xsl.h:1.12 --- php-src/ext/xsl/php_xsl.h:1.11 Wed Jul 28 08:40:53 2004 +++ php-src/ext/xsl/php_xsl.h Wed Sep 8 12:54:17 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_xsl.h,v 1.11 2004/07/28 12:40:53 chregu Exp $ */ +/* $Id: php_xsl.h,v 1.12 2004/09/08 16:54:17 rrichards Exp $ */ #ifndef PHP_XSL_H #define PHP_XSL_H @@ -63,6 +63,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); \ http://cvs.php.net/diff.php/php-src/ext/xsl/xsltprocessor.c?r1=1.33&r2=1.34&ty=u Index: php-src/ext/xsl/xsltprocessor.c diff -u php-src/ext/xsl/xsltprocessor.c:1.33 php-src/ext/xsl/xsltprocessor.c:1.34 --- php-src/ext/xsl/xsltprocessor.c:1.33 Tue Aug 10 04:00:06 2004 +++ php-src/ext/xsl/xsltprocessor.c Wed Sep 8 12:54:17 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xsltprocessor.c,v 1.33 2004/08/10 08:00:06 chregu Exp $ */ +/* $Id: xsltprocessor.c,v 1.34 2004/09/08 16:54:17 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -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 @@ 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 @@ zval **args; zval *retval; int result, i, ret; + int error = 0; zend_fcall_info fci; zval handler; xmlXPathObjectPtr obj; @@ -148,13 +139,39 @@ 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 @@ 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 @@ 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 @@ 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_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 @@ 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 @@ 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(); */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php