]> granicus.if.org Git - php/commitdiff
add global init/shutdown functions for libxml. this is required as
authorShane Caraveo <shane@php.net>
Sun, 19 Oct 2003 23:17:56 +0000 (23:17 +0000)
committerShane Caraveo <shane@php.net>
Sun, 19 Oct 2003 23:17:56 +0000 (23:17 +0000)
shutdown is not safe to call multiple times, and to make streams work
correctly some init stuff has to happen in a specific order

ext/dom/php_dom.c
ext/libxml/libxml.c
ext/libxml/php_libxml.h
ext/simplexml/simplexml.c
ext/xml/xml.c

index b1149d8b86f64fb2e992447a4558742c1e759eff..eb39de3bb2e87eb12e15cff9f2d0756dc06f40a9 100644 (file)
@@ -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);
index 1683f199c9609f350c06ba3cd42627470bdf7b0a..9957f3e411c2acfa9270b1d9378ab188421d4992 100644 (file)
@@ -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;
 }
 
index 095fa56c61632cd3a6fcd06cad41e28cc356b087..9db788496fe4992e20d3e50570c7ae90575741dd 100644 (file)
@@ -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 */
 
 /*
index da3968f753c09c85d3cb69d84d28405f47b0fc9c..e636b1d262d28e2749d2370ebbb0ee98e00554cb 100644 (file)
@@ -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;
 }
index 10b49119c3621289895be80656ffd1e661f27260..4d644cacc05f3c800af65af53583ed5c95254afb 100644 (file)
@@ -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;
 }