summaryrefslogtreecommitdiff
path: root/ext/dom/php_dom.c
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2004-02-17 11:13:47 +0000
committerRob Richards <rrichards@php.net>2004-02-17 11:13:47 +0000
commitec2ea131fbee3bfe682eafcd75ff87ae550d8ad6 (patch)
tree896b392a8ab2729032d34e68f8dc1adb9a91bc42 /ext/dom/php_dom.c
parent0ecd198dc5b4a7328020c02b1147bd5eab593eb3 (diff)
downloadphp-git-ec2ea131fbee3bfe682eafcd75ff87ae550d8ad6.tar.gz
implement clone functionality to fix segfault
DomNode->clone() creates new doc proxy if document is cloned remove printf from xpath fix remaining invalid object state issues
Diffstat (limited to 'ext/dom/php_dom.c')
-rw-r--r--ext/dom/php_dom.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 657999f796..137dd2c044 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -338,6 +338,7 @@ PHP_MINIT_FUNCTION(dom)
dom_object_handlers.read_property = dom_read_property;
dom_object_handlers.write_property = dom_write_property;
dom_object_handlers.get_property_ptr_ptr = NULL;
+ dom_object_handlers.clone_obj = zend_objects_store_clone_obj;
zend_hash_init(&classes, 0, NULL, NULL, 1);
@@ -720,13 +721,6 @@ void node_list_unlink(xmlNodePtr node TSRMLS_DC)
}
/* }}} end node_list_unlink */
-/* {{{ dom_objects_clone */
-void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
-{
- /* TODO */
-}
-/* }}} */
-
#if defined(LIBXML_XPATH_ENABLED)
/* {{{ dom_xpath_objects_free_storage */
void dom_xpath_objects_free_storage(void *object TSRMLS_DC)
@@ -821,6 +815,36 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type TSRMLS_DC)
return intern;
}
+/* {{{ dom_objects_clone */
+void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
+{
+ dom_object *intern = (dom_object *) object;
+ dom_object *clone;
+ xmlNodePtr node;
+ xmlNodePtr cloned_node;
+
+ clone = dom_objects_set_class(intern->std.ce TSRMLS_CC);
+
+ if (instanceof_function(intern->std.ce, dom_node_class_entry TSRMLS_CC)) {
+ node = (xmlNodePtr)dom_object_get_node((dom_object *) object);
+ if (node != NULL) {
+ cloned_node = xmlDocCopyNode(node, node->doc, 1);
+ if (cloned_node != NULL) {
+ /* If we cloned a document then we must create new doc proxy */
+ if (cloned_node->doc == node->doc) {
+ clone->document = intern->document;
+ }
+ php_libxml_increment_doc_ref((php_libxml_node_object *)clone, cloned_node->doc TSRMLS_CC);
+ php_libxml_increment_node_ptr((php_libxml_node_object *)clone, cloned_node, NULL TSRMLS_CC);
+ }
+
+ }
+ }
+
+ *object_clone = (void *) clone;
+}
+/* }}} */
+
/* {{{ dom_objects_new */
zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
{