summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShane Caraveo <shane@php.net>2003-10-19 23:17:56 +0000
committerShane Caraveo <shane@php.net>2003-10-19 23:17:56 +0000
commit052f9378b2cc5a3fffc3c7caad7a1df8a48ecd15 (patch)
treebfcecebe5fdb99d7d9acd95b8f0cafc0bae9965b
parent399095e7a5c3cc6a288c137b290db04bc9ed17b8 (diff)
downloadphp-git-052f9378b2cc5a3fffc3c7caad7a1df8a48ecd15.tar.gz
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
-rw-r--r--ext/dom/php_dom.c9
-rw-r--r--ext/libxml/libxml.c60
-rw-r--r--ext/libxml/php_libxml.h3
-rw-r--r--ext/simplexml/simplexml.c5
-rw-r--r--ext/xml/xml.c7
5 files changed, 58 insertions, 26 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index b1149d8b86..eb39de3bb2 100644
--- a/ext/dom/php_dom.c
+++ b/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;
}
@@ -724,13 +725,17 @@ PHP_MINFO_FUNCTION(dom)
#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();
}
/* }}} */
PHP_MSHUTDOWN_FUNCTION(dom)
{
- xmlCleanupParser();
+ php_libxml_shutdown();
zend_hash_destroy(&dom_domstringlist_prop_handlers);
zend_hash_destroy(&dom_namelist_prop_handlers);
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index 1683f199c9..9957f3e411 100644
--- a/ext/libxml/libxml.c
+++ b/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;
}
diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h
index 095fa56c61..9db788496f 100644
--- a/ext/libxml/php_libxml.h
+++ b/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 */
/*
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index da3968f753..e636b1d262 100644
--- a/ext/simplexml/simplexml.c
+++ b/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;
}
diff --git a/ext/xml/xml.c b/ext/xml/xml.c
index 10b49119c3..4d644cacc0 100644
--- a/ext/xml/xml.c
+++ b/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;
}