Re: svn: /php/php-src/ branches/PHP_5_4/ext/libxml/libxml.c trunk/ext/libxml/libxml.c

From: Date: Fri, 02 Sep 2011 11:42:26 +0000
Subject: Re: svn: /php/php-src/ branches/PHP_5_4/ext/libxml/libxml.c trunk/ext/libxml/libxml.c
References: 1  Groups: php.cvs 
Request: Send a blank email to [email protected] to get a copy of this message
I finally got a chance to look at the code. Any reason you didn't just manage everything in a per request state similar to the other global function usage? You might even be able to get away with only initializing it on the first call to setting the loader and you already are performing actions in the RSHUTDOWN so no real additional overhead taking that approach.

Rob

On 9/2/11 1:14 AM, Gustavo André dos Santos Lopes wrote:
cataphract                               Fri, 02 Sep 2011 05:14:32 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=316019 Log: - Use our external entity loader only in the context of a PHP request. Changed paths:
     U   php/php-src/branches/PHP_5_4/ext/libxml/libxml.c
     U   php/php-src/trunk/ext/libxml/libxml.c
Modified: php/php-src/branches/PHP_5_4/ext/libxml/libxml.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/libxml/libxml.c 2011-09-02 04:55:59 UTC (rev 316018) +++ php/php-src/branches/PHP_5_4/ext/libxml/libxml.c 2011-09-02 05:14:32 UTC (rev 316019) @@ -674,6 +674,18 @@ return ret; } +static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL, + const char *ID, xmlParserCtxtPtr context) +{ + /* Check whether we're running in a PHP context, since the entity loader + * we've defined is an application level (true global) setting */ + if (xmlGenericError == php_libxml_error_handler) { + return _php_libxml_external_entity_loader(URL, ID, context); + } else { + return _php_libxml_default_entity_loader(URL, ID, context); + } +} + PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...) { va_list args; @@ -713,7 +725,7 @@ xmlInitParser(); _php_libxml_default_entity_loader = xmlGetExternalEntityLoader(); - xmlSetExternalEntityLoader(_php_libxml_external_entity_loader); + xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader); zend_hash_init(&php_libxml_exports, 0, NULL, NULL, 1); @@ -729,6 +741,8 @@ #endif xmlCleanupParser(); zend_hash_destroy(&php_libxml_exports); + + xmlSetExternalEntityLoader(_php_libxml_default_entity_loader); _php_libxml_initialized = 0; } } Modified: php/php-src/trunk/ext/libxml/libxml.c =================================================================== --- php/php-src/trunk/ext/libxml/libxml.c 2011-09-02 04:55:59 UTC (rev 316018) +++ php/php-src/trunk/ext/libxml/libxml.c 2011-09-02 05:14:32 UTC (rev 316019) @@ -674,6 +674,18 @@ return ret; } +static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL, + const char *ID, xmlParserCtxtPtr context) +{ + /* Check whether we're running in a PHP context, since the entity loader + * we've defined is an application level (true global) setting */ + if (xmlGenericError == php_libxml_error_handler) { + return _php_libxml_external_entity_loader(URL, ID, context); + } else { + return _php_libxml_default_entity_loader(URL, ID, context); + } +} + PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...) { va_list args; @@ -713,7 +725,7 @@ xmlInitParser(); _php_libxml_default_entity_loader = xmlGetExternalEntityLoader(); - xmlSetExternalEntityLoader(_php_libxml_external_entity_loader); + xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader); zend_hash_init(&php_libxml_exports, 0, NULL, NULL, 1); @@ -729,6 +741,8 @@ #endif xmlCleanupParser(); zend_hash_destroy(&php_libxml_exports); + + xmlSetExternalEntityLoader(_php_libxml_default_entity_loader); _php_libxml_initialized = 0; } }


Thread (3 messages)

« previous php.cvs (#66155) next »