summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/simplexml/php_simplexml.h6
-rw-r--r--ext/simplexml/simplexml.c39
2 files changed, 31 insertions, 14 deletions
diff --git a/ext/simplexml/php_simplexml.h b/ext/simplexml/php_simplexml.h
index b57ad28ce6..233452dafa 100644
--- a/ext/simplexml/php_simplexml.h
+++ b/ext/simplexml/php_simplexml.h
@@ -26,8 +26,10 @@ extern zend_module_entry simplexml_module_entry;
#ifdef PHP_WIN32
#define PHP_SIMPLEXML_API __declspec(dllexport)
+#define SIMPLEXML_IMPORT __declspec(dllimport)
#else
#define PHP_SIMPLEXML_API
+#define SIMPLEXML_IMPORT extern
#endif
#ifdef ZTS
@@ -58,10 +60,10 @@ typedef struct {
typedef struct {
zend_object zo;
- xmlHashTablePtr nsmap;
+ xmlNodePtr node;
simplexml_ref_obj *document;
+ xmlHashTablePtr nsmap;
xmlXPathContextPtr xpath;
- xmlNodePtr node;
} php_sxe_object;
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 72277fa727..367010454b 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -28,6 +28,7 @@
#include "php_simplexml.h"
zend_class_entry *sxe_class_entry;
+SIMPLEXML_IMPORT int xml_parser_inited;
#define SKIP_TEXT(__p) \
if ((__p)->type == XML_TEXT_NODE) { \
@@ -154,7 +155,6 @@ sxe_property_read(zval *object, zval *member TSRMLS_DC)
if (!xmlStrcmp(node->name, name)) {
APPEND_PREV_ELEMENT(counter, value);
-
MAKE_STD_ZVAL(value);
_node_as_zval(sxe, node, value TSRMLS_CC);
value->refcount = 0;
@@ -912,20 +912,23 @@ PHP_FUNCTION(simplexml_load_file)
php_sxe_object *sxe;
char *filename;
int filename_len;
+ xmlDocPtr docp;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
return;
}
+ docp = xmlParseFile(filename);
+ if (! docp) {
+ RETURN_FALSE;
+ }
+
sxe = php_sxe_object_new(TSRMLS_C);
sxe->document = emalloc(sizeof(simplexml_ref_obj));
- sxe->document->ptr = (void *) xmlParseFile(filename);
+ sxe->document->ptr = docp;
sxe->document->refcount = 1;
- if (sxe->document->ptr == NULL) {
- efree(sxe->document);
- RETURN_FALSE;
- }
sxe->nsmap = xmlHashCreate(10);
+ sxe->node = NULL;
return_value->type = IS_OBJECT;
@@ -940,20 +943,23 @@ PHP_FUNCTION(simplexml_load_string)
php_sxe_object *sxe;
char *data;
int data_len;
+ xmlDocPtr docp;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) {
return;
}
+ docp = xmlParseMemory(data, data_len);
+ if (! docp) {
+ RETURN_FALSE;
+ }
+
sxe = php_sxe_object_new(TSRMLS_C);
sxe->document = emalloc(sizeof(simplexml_ref_obj));
sxe->document->refcount = 1;
- sxe->document->ptr = xmlParseMemory(data, data_len);
- if (sxe->document->ptr == NULL) {
- efree(sxe->document);
- RETURN_FALSE;
- }
+ sxe->document->ptr = docp;
sxe->nsmap = xmlHashCreate(10);
+ sxe->node = NULL;
return_value->type = IS_OBJECT;
return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
@@ -993,6 +999,11 @@ PHP_MINIT_FUNCTION(simplexml)
sxe.create_object = sxe_object_new;
sxe_class_entry = zend_register_internal_class(&sxe TSRMLS_CC);
+ if (!xml_parser_inited) {
+ xmlInitThreads();
+ xml_parser_inited = 1;
+ }
+
return SUCCESS;
}
/* }}} */
@@ -1001,7 +1012,11 @@ PHP_MINIT_FUNCTION(simplexml)
*/
PHP_MSHUTDOWN_FUNCTION(simplexml)
{
- xmlCleanupParser();
+ if (xml_parser_inited) {
+ xmlCleanupParser();
+ xml_parser_inited = 0;
+ }
+
return SUCCESS;
}
/* }}} */