diff --git a/ext/dom/attr.c b/ext/dom/attr.c index a262aea821395..399de6bfb90c2 100644 --- a/ext/dom/attr.c +++ b/ext/dom/attr.c @@ -62,7 +62,7 @@ PHP_METHOD(DOMAttr, __construct) oldnode = dom_object_get_node(intern); if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern); } diff --git a/ext/dom/cdatasection.c b/ext/dom/cdatasection.c index e95e1a9030f39..08d4937341d18 100644 --- a/ext/dom/cdatasection.c +++ b/ext/dom/cdatasection.c @@ -52,7 +52,7 @@ PHP_METHOD(DOMCdataSection, __construct) intern = Z_DOMOBJ_P(ZEND_THIS); oldnode = dom_object_get_node(intern); if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); } diff --git a/ext/dom/comment.c b/ext/dom/comment.c index 76fe3200d4624..16a52a5a4e24c 100644 --- a/ext/dom/comment.c +++ b/ext/dom/comment.c @@ -50,13 +50,11 @@ PHP_METHOD(DOMComment, __construct) } intern = Z_DOMOBJ_P(ZEND_THIS); - if (intern != NULL) { - oldnode = dom_object_get_node(intern); - if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); - } - php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern); + oldnode = dom_object_get_node(intern); + if (oldnode != NULL) { + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } + php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern); } /* }}} end DOMComment::__construct */ diff --git a/ext/dom/document.c b/ext/dom/document.c index ad98cf9a8501b..ea6daafeb30fb 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -1118,22 +1118,20 @@ PHP_METHOD(DOMDocument, __construct) } intern = Z_DOMOBJ_P(ZEND_THIS); - if (intern != NULL) { - olddoc = (xmlDocPtr) dom_object_get_node(intern); - if (olddoc != NULL) { - php_libxml_decrement_node_ptr((php_libxml_node_object *) intern); - refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern); - if (refcount != 0) { - olddoc->_private = NULL; - } - } - intern->document = NULL; - if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) { - /* docp is always non-null so php_libxml_increment_doc_ref() never returns -1 */ - ZEND_UNREACHABLE(); + olddoc = (xmlDocPtr) dom_object_get_node(intern); + if (olddoc != NULL) { + php_libxml_decrement_node_ptr((php_libxml_node_object *) intern); + refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern); + if (refcount != 0) { + olddoc->_private = NULL; } - php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern); } + intern->document = NULL; + if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) { + /* docp is always non-null so php_libxml_increment_doc_ref() never returns -1 */ + ZEND_UNREACHABLE(); + } + php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern); } /* }}} end DOMDocument::__construct */ diff --git a/ext/dom/documentfragment.c b/ext/dom/documentfragment.c index 274d695435388..033ee08aee172 100644 --- a/ext/dom/documentfragment.c +++ b/ext/dom/documentfragment.c @@ -50,9 +50,8 @@ PHP_METHOD(DOMDocumentFragment, __construct) intern = Z_DOMOBJ_P(ZEND_THIS); oldnode = dom_object_get_node(intern); if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } - /* php_dom_set_object(intern, nodep); */ php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); } /* }}} end DOMDocumentFragment::__construct */ diff --git a/ext/dom/element.c b/ext/dom/element.c index 2379b81e1dd5b..c630bec2b5007 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -97,7 +97,7 @@ PHP_METHOD(DOMElement, __construct) intern = Z_DOMOBJ_P(ZEND_THIS); oldnode = dom_object_get_node(intern); if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); } diff --git a/ext/dom/entityreference.c b/ext/dom/entityreference.c index 16aadabfb5999..61f0b92eedc22 100644 --- a/ext/dom/entityreference.c +++ b/ext/dom/entityreference.c @@ -57,13 +57,11 @@ PHP_METHOD(DOMEntityReference, __construct) } intern = Z_DOMOBJ_P(ZEND_THIS); - if (intern != NULL) { - oldnode = dom_object_get_node(intern); - if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); - } - php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern); + oldnode = dom_object_get_node(intern); + if (oldnode != NULL) { + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } + php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern); } /* }}} end DOMEntityReference::__construct */ diff --git a/ext/dom/processinginstruction.c b/ext/dom/processinginstruction.c index 465ecb431e73a..a1c3d3a08783c 100644 --- a/ext/dom/processinginstruction.c +++ b/ext/dom/processinginstruction.c @@ -59,7 +59,7 @@ PHP_METHOD(DOMProcessingInstruction, __construct) intern = Z_DOMOBJ_P(ZEND_THIS); oldnode = dom_object_get_node(intern); if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); } diff --git a/ext/dom/tests/DOMDocumentFragment_construct_basic_002.phpt b/ext/dom/tests/DOMDocumentFragment_construct_basic_002.phpt deleted file mode 100644 index 36a0762c16f07..0000000000000 --- a/ext/dom/tests/DOMDocumentFragment_construct_basic_002.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -DOMDocumentFragment::__construct() called twice. ---CREDITS-- -Eric Lee Stewart -# TestFest Atlanta 2009-05-24 ---EXTENSIONS-- -dom ---FILE-- -__construct(); -var_dump($fragment); -?> ---EXPECT-- -object(DOMDocumentFragment)#1 (0) { -} diff --git a/ext/dom/tests/manually_call_constructor/attribute.phpt b/ext/dom/tests/manually_call_constructor/attribute.phpt new file mode 100644 index 0000000000000..5e8be0abf7479 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/attribute.phpt @@ -0,0 +1,34 @@ +--TEST-- +Manually call __construct() - attribute variation +--EXTENSIONS-- +dom +--FILE-- +nodeName, $attr->nodeValue); +$attr->__construct("newattribute", "my new value"); +var_dump($attr->nodeName, $attr->nodeValue); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->setAttributeNode($attr); +echo $doc->saveXML(); + +$attr->__construct("newnewattribute", "my even newer value"); +$doc->documentElement->setAttributeNode($attr); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(9) "attribute" +string(8) "my value" +string(12) "newattribute" +string(12) "my new value" + + + + diff --git a/ext/dom/tests/manually_call_constructor/cdatasection.phpt b/ext/dom/tests/manually_call_constructor/cdatasection.phpt new file mode 100644 index 0000000000000..01b8ab7ebd427 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/cdatasection.phpt @@ -0,0 +1,32 @@ +--TEST-- +Manually call __construct() - CDATA section variation +--EXTENSIONS-- +dom +--FILE-- +nodeValue); +$cdata->__construct("my new value"); +var_dump($cdata->nodeValue); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($cdata); +echo $doc->saveXML(); + +$cdata->__construct("my even newer value"); +$doc->documentElement->appendChild($cdata); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(8) "my value" +string(12) "my new value" + + + + diff --git a/ext/dom/tests/manually_call_constructor/comment.phpt b/ext/dom/tests/manually_call_constructor/comment.phpt new file mode 100644 index 0000000000000..0abf6bcf6c1c3 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/comment.phpt @@ -0,0 +1,34 @@ +--TEST-- +Manually call __construct() - comment variation +--EXTENSIONS-- +dom +--FILE-- +nodeName, $comment->nodeValue); +$comment->__construct("my new value"); +var_dump($comment->nodeName, $comment->nodeValue); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($comment); +echo $doc->saveXML(); + +$comment->__construct("my even newer value"); +$doc->documentElement->appendChild($comment); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(8) "#comment" +string(8) "my value" +string(8) "#comment" +string(12) "my new value" + + + + diff --git a/ext/dom/tests/manually_call_constructor/document.phpt b/ext/dom/tests/manually_call_constructor/document.phpt new file mode 100644 index 0000000000000..ce7aacc08b6ed --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/document.phpt @@ -0,0 +1,15 @@ +--TEST-- +Manually call __construct() - document variation +--EXTENSIONS-- +dom +--FILE-- +loadXML(''); +$doc->__construct("1.1", "UTF-8"); +echo $doc->saveXML(); + +?> +--EXPECT-- + diff --git a/ext/dom/tests/manually_call_constructor/documentfragment.phpt b/ext/dom/tests/manually_call_constructor/documentfragment.phpt new file mode 100644 index 0000000000000..8e6f40d995180 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/documentfragment.phpt @@ -0,0 +1,32 @@ +--TEST-- +Manually call __construct() - document fragment variation +--EXTENSIONS-- +dom +--FILE-- +textContent); +$fragment->__construct(); +var_dump($fragment->textContent); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +@$doc->documentElement->appendChild($fragment); +echo $doc->saveXML(); + +$fragment->__construct(); +@$doc->documentElement->appendChild($fragment); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(0) "" +string(0) "" + + + + diff --git a/ext/dom/tests/manually_call_constructor/element.phpt b/ext/dom/tests/manually_call_constructor/element.phpt new file mode 100644 index 0000000000000..9187340a46185 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/element.phpt @@ -0,0 +1,34 @@ +--TEST-- +Manually call __construct() - element variation +--EXTENSIONS-- +dom +--FILE-- +nodeName, $element->textContent); +$element->__construct('foo2', 'my new value'); +var_dump($element->nodeName, $element->textContent); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($element); +echo $doc->saveXML(); + +$element->__construct('foo3', 'my new new value'); +$doc->documentElement->appendChild($element); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(3) "foo" +string(8) "my value" +string(4) "foo2" +string(12) "my new value" + +my new value + +my new valuemy new new value diff --git a/ext/dom/tests/manually_call_constructor/entityreference.phpt b/ext/dom/tests/manually_call_constructor/entityreference.phpt new file mode 100644 index 0000000000000..5bffda5fd0231 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/entityreference.phpt @@ -0,0 +1,34 @@ +--TEST-- +Manually call __construct() - entity reference variation +--EXTENSIONS-- +dom +--FILE-- +nodeName, $entityRef->textContent); +$entityRef->__construct('foo2'); +var_dump($entityRef->nodeName, $entityRef->textContent); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($entityRef); +echo $doc->saveXML(); + +$entityRef->__construct('foo3'); +$doc->documentElement->appendChild($entityRef); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(3) "foo" +string(0) "" +string(4) "foo2" +string(0) "" + +&foo2; + +&foo2;&foo3; diff --git a/ext/dom/tests/manually_call_constructor/processinginstruction.phpt b/ext/dom/tests/manually_call_constructor/processinginstruction.phpt new file mode 100644 index 0000000000000..11e7ab1e28d90 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/processinginstruction.phpt @@ -0,0 +1,34 @@ +--TEST-- +Manually call __construct() - processing instruction variation +--EXTENSIONS-- +dom +--FILE-- +target, $pi->data); +$pi->__construct('name2', 'value2'); +var_dump($pi->target, $pi->data); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($pi); +echo $doc->saveXML(); + +$pi->__construct('name3', 'value3'); +$doc->documentElement->appendChild($pi); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(5) "name1" +string(6) "value1" +string(5) "name2" +string(6) "value2" + + + + diff --git a/ext/dom/tests/manually_call_constructor/text.phpt b/ext/dom/tests/manually_call_constructor/text.phpt new file mode 100644 index 0000000000000..b91b0f66e33d5 --- /dev/null +++ b/ext/dom/tests/manually_call_constructor/text.phpt @@ -0,0 +1,33 @@ +--TEST-- +Manually call __construct() - text variation +--EXTENSIONS-- +dom +--FILE-- +textContent); +$text->__construct('my new value'); +var_dump($text->textContent); + +$doc = new DOMDocument(); +$doc->loadXML(<< + +XML); +$doc->documentElement->appendChild($text); +echo $doc->saveXML(); + +$text->__construct("\nmy new new value"); +$doc->documentElement->appendChild($text); +echo $doc->saveXML(); + +?> +--EXPECT-- +string(8) "my value" +string(12) "my new value" + +my new value + +my new value +my new new value diff --git a/ext/dom/text.c b/ext/dom/text.c index e782ff8ff6c78..2a5630fa60883 100644 --- a/ext/dom/text.c +++ b/ext/dom/text.c @@ -51,13 +51,11 @@ PHP_METHOD(DOMText, __construct) } intern = Z_DOMOBJ_P(ZEND_THIS); - if (intern != NULL) { - oldnode = dom_object_get_node(intern); - if (oldnode != NULL) { - php_libxml_node_free_resource(oldnode ); - } - php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); + oldnode = dom_object_get_node(intern); + if (oldnode != NULL) { + php_libxml_node_decrement_resource((php_libxml_node_object *)intern); } + php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern); } /* }}} end DOMText::__construct */