summaryrefslogtreecommitdiff
path: root/ext/libxml/libxml.c
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 /ext/libxml/libxml.c
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
Diffstat (limited to 'ext/libxml/libxml.c')
-rw-r--r--ext/libxml/libxml.c60
1 files changed, 40 insertions, 20 deletions
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;
}