Browse Source

add global init/shutdown functions for libxml. this is required as

shutdown is not safe to call multiple times, and to make streams work
correctly some init stuff has to happen in a specific order
PEAR_1_4DEV
Shane Caraveo 23 years ago
parent
commit
052f9378b2
  1. 9
      ext/dom/php_dom.c
  2. 60
      ext/libxml/libxml.c
  3. 3
      ext/libxml/php_libxml.h
  4. 5
      ext/simplexml/simplexml.c
  5. 7
      ext/xml/xml.c

9
ext/dom/php_dom.c

@ -32,6 +32,7 @@
#include "dom_properties.h"
#include "ext/standard/info.h"
#include "ext/libxml/php_libxml.h"
#define PHP_XPATH 1
#define PHP_XPTR 2
@ -702,7 +703,7 @@ PHP_MINIT_FUNCTION(dom)
REGISTER_LONG_CONSTANT("DOM_INVALID_ACCESS_ERR", INVALID_ACCESS_ERR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DOM_VALIDATION_ERR", VALIDATION_ERR, CONST_CS | CONST_PERSISTENT);
xmlInitParser();
php_libxml_initialize();
return SUCCESS;
}
@ -723,6 +724,10 @@ PHP_MINFO_FUNCTION(dom)
#endif
#if defined(LIBXML_XPTR_ENABLED)
php_info_print_table_row(2, "XPointer Support", "enabled");
#endif
#ifdef LIBXML_SCHEMAS_ENABLED
php_info_print_table_row(2, "Schema Support", "enabled");
php_info_print_table_row(2, "RelaxNG Support", "enabled");
#endif
php_info_print_table_end();
}
@ -730,7 +735,7 @@ PHP_MINFO_FUNCTION(dom)
PHP_MSHUTDOWN_FUNCTION(dom)
{
xmlCleanupParser();
php_libxml_shutdown();
zend_hash_destroy(&dom_domstringlist_prop_handlers);
zend_hash_destroy(&dom_namelist_prop_handlers);

60
ext/libxml/libxml.c

@ -42,6 +42,9 @@
#include "php_libxml.h"
/* a true global for initialization */
int _php_libxml_initialized = 0;
#ifdef ZTS
int libxml_globals_id;
#else
@ -101,8 +104,7 @@ static void php_libxml_init_globals(php_libxml_globals *libxml_globals_p TSRMLS_
int php_libxml_streams_IO_match_wrapper(const char *filename)
{
TSRMLS_FETCH();
return php_stream_locate_url_wrapper(filename, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ? 1 : 0;
return php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC) ? 1 : 0;
}
void *php_libxml_streams_IO_open_wrapper(const char *filename)
@ -134,31 +136,48 @@ int php_libxml_streams_IO_close(void *context)
return php_stream_close((php_stream*)context);
}
PHP_LIBXML_API void php_libxml_initialize() {
if (!_php_libxml_initialized) {
/* we should be the only one's to ever init!! */
xmlInitParser();
/* Enable php stream/wrapper support for libxml
we only use php streams, so we do not enable
the default io handlers in libxml.
*/
xmlRegisterInputCallbacks(
php_libxml_streams_IO_match_wrapper,
php_libxml_streams_IO_open_wrapper,
php_libxml_streams_IO_read,
php_libxml_streams_IO_close);
xmlRegisterOutputCallbacks(
php_libxml_streams_IO_match_wrapper,
php_libxml_streams_IO_open_wrapper,
php_libxml_streams_IO_write,
php_libxml_streams_IO_close);
_php_libxml_initialized = 1;
}
}
PHP_LIBXML_API void php_libxml_shutdown() {
if (_php_libxml_initialized) {
xmlCleanupParser();
_php_libxml_initialized = 0;
}
}
PHP_MINIT_FUNCTION(libxml)
{
/* Enable php stream/wrapper support for libxml
we only use php streams, so we disable the libxml builtin
io support.
*/
xmlCleanupInputCallbacks();
xmlRegisterInputCallbacks(
php_libxml_streams_IO_match_wrapper,
php_libxml_streams_IO_open_wrapper,
php_libxml_streams_IO_read,
php_libxml_streams_IO_close);
xmlCleanupOutputCallbacks();
xmlRegisterOutputCallbacks(
php_libxml_streams_IO_match_wrapper,
php_libxml_streams_IO_open_wrapper,
php_libxml_streams_IO_write,
php_libxml_streams_IO_close);
php_libxml_initialize();
#ifdef ZTS
ts_allocate_id(&libxml_globals_id, sizeof(php_libxml_globals), (ts_allocate_ctor) php_libxml_init_globals, NULL);
#else
LIBXML(stream_context) = NULL;
#endif
return SUCCESS;
}
@ -171,6 +190,7 @@ PHP_RINIT_FUNCTION(libxml)
PHP_MSHUTDOWN_FUNCTION(libxml)
{
php_libxml_shutdown();
return SUCCESS;
}

3
ext/libxml/php_libxml.h

@ -56,6 +56,9 @@ PHP_FUNCTION(libxml_set_streams_context);
#define LIBXML(v) (libxml_globals.v)
#endif
PHP_LIBXML_API void php_libxml_initialize();
PHP_LIBXML_API void php_libxml_shutdown();
#endif /* PHP_LIBXML_H */
/*

5
ext/simplexml/simplexml.c

@ -28,6 +28,7 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_simplexml.h"
#include "ext/libxml/php_libxml.h"
zend_class_entry *sxe_class_entry;
@ -1037,7 +1038,7 @@ PHP_MINIT_FUNCTION(simplexml)
sxe.create_object = sxe_object_new;
sxe_class_entry = zend_register_internal_class(&sxe TSRMLS_CC);
xmlInitParser();
php_libxml_initialize();
return SUCCESS;
}
@ -1047,7 +1048,7 @@ PHP_MINIT_FUNCTION(simplexml)
*/
PHP_MSHUTDOWN_FUNCTION(simplexml)
{
xmlCleanupParser();
php_libxml_shutdown();
return SUCCESS;
}

7
ext/xml/xml.c

@ -37,6 +37,9 @@
#include "php_xml.h"
# include "ext/standard/head.h"
#ifdef LIBXML_EXPAT_COMPAT
#include "ext/libxml/php_libxml.h"
#endif
/* Short-term TODO list:
* - Implement XML_ExternalEntityParserCreate()
@ -238,7 +241,7 @@ PHP_MINIT_FUNCTION(xml)
php_xml_mem_hdlrs.free_fcn = php_xml_free_wrapper;
#ifdef LIBXML_EXPAT_COMPAT
xmlInitParser();
php_libxml_initialize();
#endif
return SUCCESS;
}
@ -253,7 +256,7 @@ PHP_RINIT_FUNCTION(xml)
PHP_MSHUTDOWN_FUNCTION(xml)
{
#ifdef LIBXML_EXPAT_COMPAT
xmlCleanupParser();
php_libxml_shutdown();
#endif
return SUCCESS;
}

Loading…
Cancel
Save