subnode = php_sxe_object_new(TSRMLS_C);
subnode->document = sxe->document;
+ subnode->document->refcount++;
subnode->nsmap = sxe->nsmap;
subnode->node = node;
add_next_index_zval(return_value, __v); \
}
-#define GET_NODE(__s, __n) (__n) = (__s)->node ? (__s)->node : xmlDocGetRootElement((__s)->document)
+#define GET_NODE(__s, __n) (__n) = (__s)->node ? (__s)->node : xmlDocGetRootElement((xmlDocPtr) (__s)->document->ptr)
+
+/* {{{ match_ns()
+ */
+static inline int
+match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name)
+{
+ if (!xmlStrcmp(node->ns->prefix, name) || !xmlStrcmp((xmlChar *) xmlHashLookup(sxe->nsmap, node->ns->href), name)) {
+ return 1;
+ }
+
+ return 0;
+}
+/* }}} */
+
/* {{{ sxe_property_read()
*/
static zval *
APPEND_PREV_ELEMENT(counter, value);
MAKE_STD_ZVAL(value);
- contents = xmlNodeListGetString(sxe->document, attr->children, 1);
+ contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, attr->children, 1);
ZVAL_STRING(value, contents, 0);
APPEND_CUR_ELEMENT(counter, value);
SKIP_TEXT(node);
if (node->ns) {
- if (!xmlStrcmp(node->ns->prefix, name)) {
- MAKE_STD_ZVAL(value);
- _node_as_zval(sxe, node->parent, value);
- APPEND_CUR_ELEMENT(counter, value);
- goto next_iter;
- }
-
- mapname = xmlHashLookup(sxe->nsmap, node->ns->href);
- if (mapname && !xmlStrcmp((xmlChar *) mapname, name)) {
+ if (match_ns(sxe, node, name)) {
MAKE_STD_ZVAL(value);
_node_as_zval(sxe, node->parent, value);
APPEND_CUR_ELEMENT(counter, value);
+
goto next_iter;
}
-
}
-
+
if (!xmlStrcmp(node->name, name)) {
APPEND_PREV_ELEMENT(counter, value);
APPEND_CUR_ELEMENT(counter, value);
}
- next_iter:
+next_iter:
node = node->next;
}
}
} else {
subnode = php_sxe_object_new(TSRMLS_C);
- subnode->document = node->doc;
+ subnode->document = emalloc(sizeof(simplexml_ref_obj));
+ subnode->document->refcount = 2;
+ subnode->document->ptr = node->doc;
subnode->node = node;
(*value)->type = IS_OBJECT;
if (sxe1->node == NULL) {
if (sxe2->node) {
return 1;
- } else if (sxe1->document == sxe2->document) {
- return 9;
+ } else if (sxe1->document->ptr == sxe2->document->ptr) {
+ return 0;
}
} else {
return !(sxe1->node == sxe2->node);
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
if (!sxe->xpath) {
- sxe->xpath = xmlXPathNewContext(sxe->document);
+ sxe->xpath = xmlXPathNewContext((xmlDocPtr) sxe->document->ptr);
}
if (!sxe->node) {
- sxe->node = xmlDocGetRootElement(sxe->document);
+ sxe->node = xmlDocGetRootElement((xmlDocPtr) sxe->document->ptr);
}
sxe->xpath->node = sxe->node;
}
vptr = xmlSchemaNewValidCtxt(sptr);
- is_valid = xmlSchemaValidateDoc(vptr, sxe->document);
+ is_valid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
xmlSchemaFree(sptr);
xmlSchemaFreeValidCtxt(vptr);
}
if (sxe->node) {
- contents = xmlNodeListGetString(sxe->document, sxe->node->children, 1);
+ contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, sxe->node->children, 1);
if (!xmlIsBlankNode(sxe->node->children) && contents) {
cast_object(writeobj, type, NULL TSRMLS_CC);
}
clone = php_sxe_object_new(TSRMLS_C);
- clone->document = xmlCopyDoc(sxe->document, 1);
+ clone->document = emalloc(sizeof(simplexml_ref_obj));
+ clone->document->refcount = 1;
+ clone->document->ptr = xmlCopyDoc((xmlDocPtr) sxe->document->ptr, 1);
*clone_ptr = (void *) clone;
}
sxe = (php_sxe_object *) object;
- if (sxe->document) {
- xmlFreeDoc(sxe->document);
+ if (--sxe->document->refcount <= 0) {
+ xmlFreeDoc(sxe->document->ptr);
}
if (sxe->xpath) {
}
sxe = php_sxe_object_new(TSRMLS_C);
- sxe->document = xmlParseFile(filename);
- sxe->nsmap = xmlHashCreate(10);
- if (sxe->document == NULL) {
+ sxe->document = emalloc(sizeof(simplexml_ref_obj));
+ sxe->document->refcount = 1;
+ sxe->document->ptr = (void *) xmlParseFile(filename);
+ if (sxe->document->ptr == NULL) {
+ efree(sxe->document);
RETURN_FALSE;
}
+ sxe->nsmap = xmlHashCreate(10);
+
return_value->type = IS_OBJECT;
return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
}
sxe = php_sxe_object_new(TSRMLS_C);
- sxe->document = xmlParseMemory(data, data_len);
- sxe->nsmap = xmlHashCreate(10);
- if (sxe->document == NULL) {
+ 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->nsmap = xmlHashCreate(10);
+
return_value->type = IS_OBJECT;
return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
}
sxe = php_sxe_fetch_object(element TSRMLS_CC);
- xmlSaveFile(filename, sxe->document);
+ xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr);
RETURN_TRUE;
}
}
sxe = php_sxe_fetch_object(element TSRMLS_CC);
- xmlDocDumpMemory(sxe->document, (xmlChar **) &Z_STRVAL_P(data), &Z_STRLEN_P(data));
+ xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, (xmlChar **) &Z_STRVAL_P(data), &Z_STRLEN_P(data));
Z_TYPE_P(data) = IS_STRING;
zval_add_ref(&data);