#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) { \
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;
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;
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);
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;
}
/* }}} */
*/
PHP_MSHUTDOWN_FUNCTION(simplexml)
{
- xmlCleanupParser();
+ if (xml_parser_inited) {
+ xmlCleanupParser();
+ xml_parser_inited = 0;
+ }
+
return SUCCESS;
}
/* }}} */