Skip to content

Commit aab5579

Browse files
committed
refcount should be unsigned, and update tests
1 parent 11b3bdd commit aab5579

2 files changed

Lines changed: 61 additions & 18 deletions

File tree

ext/dom/php_dom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ void dom_objects_free_storage(zend_object *object)
14871487
xmlNodePtr node = ptr->node;
14881488

14891489
if (node->type == XML_NOTATION_NODE) {
1490-
int refcount = php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
1490+
unsigned int refcount = php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
14911491
php_libxml_decrement_doc_ref((php_libxml_node_object *) intern);
14921492
if (refcount == 0) {
14931493
dom_free_notation((xmlEntityPtr) node);

ext/dom/tests/modern/xml/XMLDocument_node_notation_wiring.phpt

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,49 @@ Dom\XMLDocument: Dom\Notation nodes are connected to their document and doctype
44
dom
55
--FILE--
66
<?php
7-
$xml = <<<XML
7+
$cases = [
8+
'GIF' => '<!NOTATION GIF SYSTEM "image/gif">',
9+
'JPEG' => '<!NOTATION JPEG PUBLIC "-//W3C//NOTATION JPEG//EN" "image/jpeg">',
10+
'HTML' => '<!NOTATION HTML PUBLIC "-//W3C//NOTATION HTML//EN">',
11+
];
12+
13+
foreach ($cases as $name => $declaration) {
14+
$xml = <<<XML
815
<!DOCTYPE root [
9-
<!NOTATION GIF SYSTEM "image/gif">
10-
<!NOTATION JPEG PUBLIC "-//W3C//NOTATION JPEG//EN" "image/jpeg">
11-
<!NOTATION HTML PUBLIC "-//W3C//NOTATION HTML//EN">
16+
$declaration
1217
]>
1318
<root/>
1419
XML;
1520

16-
$dom = Dom\XMLDocument::createFromString($xml);
17-
$doctype = $dom->doctype;
18-
$notations = $doctype->notations;
21+
$dom = Dom\XMLDocument::createFromString($xml);
22+
$doctype = $dom->doctype;
23+
$notations = $doctype->notations;
1924

20-
// Make notations deterministic by name, as the order of notations in the map is not guaranteed
21-
foreach (['GIF', 'JPEG', 'HTML'] as $name) {
2225
echo "=== $name ===\n";
23-
$notation = $notations->getNamedItem($name);
24-
var_dump($notation->nodeName);
25-
var_dump($notation->textContent);
26-
var_dump($notation->nodeValue);
27-
var_dump($notation->isConnected);
28-
var_dump($notation->ownerDocument === $dom);
29-
var_dump($notation->parentNode === $doctype);
30-
var_dump($notation->parentElement);
26+
27+
$namedNotation = $notations->getNamedItem($name);
28+
foreach ($notations as $iteratedNotation) {
29+
// getNamedItem
30+
var_dump($namedNotation->nodeName);
31+
var_dump($namedNotation->textContent);
32+
var_dump($namedNotation->nodeValue);
33+
var_dump($namedNotation->isConnected);
34+
var_dump($namedNotation->ownerDocument === $dom);
35+
var_dump($namedNotation->parentNode === $doctype);
36+
var_dump($namedNotation->parentElement);
37+
38+
// iteration
39+
var_dump($iteratedNotation->nodeName);
40+
var_dump($iteratedNotation->textContent);
41+
var_dump($iteratedNotation->nodeValue);
42+
var_dump($iteratedNotation->isConnected);
43+
var_dump($iteratedNotation->ownerDocument === $dom);
44+
var_dump($iteratedNotation->parentNode === $doctype);
45+
var_dump($iteratedNotation->parentElement);
46+
47+
// wiring
48+
var_dump($namedNotation->nodeName === $iteratedNotation->nodeName);
49+
}
3150
}
3251
?>
3352
--EXPECT--
@@ -39,6 +58,14 @@ bool(true)
3958
bool(true)
4059
bool(true)
4160
NULL
61+
string(3) "GIF"
62+
NULL
63+
NULL
64+
bool(true)
65+
bool(true)
66+
bool(true)
67+
NULL
68+
bool(true)
4269
=== JPEG ===
4370
string(4) "JPEG"
4471
NULL
@@ -47,6 +74,14 @@ bool(true)
4774
bool(true)
4875
bool(true)
4976
NULL
77+
string(4) "JPEG"
78+
NULL
79+
NULL
80+
bool(true)
81+
bool(true)
82+
bool(true)
83+
NULL
84+
bool(true)
5085
=== HTML ===
5186
string(4) "HTML"
5287
NULL
@@ -55,3 +90,11 @@ bool(true)
5590
bool(true)
5691
bool(true)
5792
NULL
93+
string(4) "HTML"
94+
NULL
95+
NULL
96+
bool(true)
97+
bool(true)
98+
bool(true)
99+
NULL
100+
bool(true)

0 commit comments

Comments
 (0)