Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bogus tree setting code from parentnode/tree.c #15044

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

nielsdos
Copy link
Member

I don't know why this code was here in the first place, it is present since the initial implementation. It doesn't make sense because:

  1. It would require updating the refcounts if the document wasn't actually already set.
  2. We enforce that the document is the same as the target document by this point, so setting the tree is pointless.

I don't know why this code was here in the first place, it is present
since the initial implementation. It doesn't make sense because:
1. It would require updating the refcounts if the document wasn't
   actually already set.
2. We enforce that the document is the same as the target document by
   this point, so setting the tree is pointless.
@SakiTakamachi
Copy link
Member

@nielsdos

It would require updating the refcounts if the document wasn't actually already set.

I'm not very familiar with DOM, but where is this processing?
(If someone else with more knowledge reviews it, you can forget about this question.)

@nielsdos
Copy link
Member Author

@nielsdos

It would require updating the refcounts if the document wasn't actually already set.

I'm not very familiar with DOM, but where is this processing? (If someone else with more knowledge reviews it, you can forget about this question.)

You would need to call php_libxml_increment_doc_ref to increment the ref count of the document reference, see this code for example:

php-src/ext/dom/element.c

Lines 733 to 736 in ba54ceb

if (attrp->doc == NULL && nodep->doc != NULL) {
attrobj->document = intern->document;
php_libxml_increment_doc_ref((php_libxml_node_object *)attrobj, NULL);
}

@SakiTakamachi
Copy link
Member

@nielsdos

Thanks!

In other words, does it mean that php_libxml_increment_doc_ref is always called before this function is called?

@nielsdos
Copy link
Member Author

@nielsdos

Thanks!

In other words, does it mean that php_libxml_increment_doc_ref is always called before this function is called?

Not necessarily right before this function, but it must've been called at some point. Usually this is at the time that the node object was created, but it could also have happened during adoption. If this wasn't called then a WRONG_DOCUMENT_ERR type of DOMException is thrown.

Copy link
Member

@SakiTakamachi SakiTakamachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nielsdos

Thank you for the explanation, I understand.

I was concerned that the execution path was a little complicated, but since use ZEND_ASSERT, I don't think it will be a problem.

@nielsdos nielsdos merged commit d5faf44 into php:master Jul 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants