-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Convert ext/xml to use object instead of resource #3526
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
Conversation
Whats the motivation behind improving ext/xml over ext/xmlreader? May sound silly but I have been out of the XML loop for way too long |
@KalleZ Of course, we may consider to deprecate ext/xml and move it to PECL, but still it would be nice to fix the memory leakage issue beforehand. @nikic Thanks for tackling this. I guess we should have an RFC, though, like we had for ext/gmp and ext/hash. Regarding the failing tests: bug68912.phpt needs an updated warning message or perhaps more reasonably some other resource. schema085.phpt shouldn't hardcode the object number anyway (i.e. regardless of this PR). |
@cmb69 I agree that we should fix the memory leakage, thats a no brainer but it just seems odd to introduce a class behind the scenes if there are other alternatives thats perhaps something we would want to promote more. Is there not another way around this without changing it to use objects by continuing to re-use the resource system? |
@KalleZ ext/xml is a push-based streaming parser. ext/xmlreader is a pull-based non-streaming parser. They have different use-cases. If you can use ext/xmlreader, it's the easier option, but it does not cover all use-cases. |
5bdae59
to
4bc797f
Compare
Why not make
Leave as no-op, and deprecate the function (maybe “is deprecated; unset the parser instance instead”). |
Comment on behalf of petk at php.net: Labelling |
quoting nikic:
@cmb69 is this something worth noting in the docs? |
Use an XmlParser object instead of a resource.
These leaks have been resolved by the introduction of a proper get_gc() implementation.
4bc797f
to
250028a
Compare
Rebased onto PHP-7.4.
I think if we want to have that, we should also be offering the rest of the API as methods as well. It seems weird to me to allow
I think that's what we should do longer term. I don't want to deprecate this function in the same release as we change to objects (as previously the use of xml_parser_free was even recommended), but maybe introduce the deprecation one release later. |
I think, if |
I'm -1 on doing this in 7.4 as the check for resource is used in Pear XML parser that is included to quite a few projects in GitHub and I guess it might be even more in closed source. I don't think it's worth the break in minor version though. I'm fine with this going to 8.0. |
Funnily, |
Yeah but it will also break lots of applications. I guess the leak is not such a big issue for all cases and it might have been there for some time already. I think that postponing that to 8.0 would be better though. |
Merged as e35a3cb into PHP 8 only. |
The primary motivation here is to fix https://bugs.php.net/bug.php?id=72793 and https://bugs.php.net/bug.php?id=76874, which cannot be done with a resource, as resources are not part of cycle GC.
The object is called
XmlParser
. An open question is whatxml_parser_free()
is supposed to do. Right now I've left it as essentially a no-op.Targeting PHP 7.4 based on precedent. ext/gmp was converted in 5.6, ext/hash in 7.2, so we seem to be fine with doing these resource->object conversions in minor versions.