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
Use traverse & finalize in xxlimited and in PEP 489 tests #68561
Comments
The example object in the xxlimited module can be part of a reference loop (it can contain itself), so it needs GC and tp_traverse. The tp_dealloc hook was incorrect, and a correct version would be difficult to generalize for something more complicated than a example class (bpo-16690; [0]). It's better to avoid dealloc and show off tp_finalize. Same for the class in _testmultiphase (PEP-489 tests), which is based on xxlimited. The incorrect dealloc is causing the reference leak mentioned in bpo-24268. The Xxo object also wasn't actually added to the module. Here is a patch to fix these. [0] https://mail.python.org/pipermail/python-dev/2015-June/140422.html |
Would it also be worth making at docs update to tp_dealloc, suggesting the use of tp_traverse/finalize?: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc And perhaps from PyType_FromSpec? https://docs.python.org/3/c-api/type.html?highlight=pytype_fromspec#c.PyType_FromSpec |
tp_traverse is completely orthogonal to tp_dealloc, it's needed to detect (and then break) reference cycles like: As for tp_finalize: yes, mentioning it in tp_dealloc docs would be good, but I'll need a bit more studying to understand the problem correctly. The cases fixed here are relatively simple; Antoine gives more complex ones in [0]. When I feel qualified to give advice, I'll change the docs. (And most likely, write a PEP to make things easier; some changes to classes will be needed anyway to make PEP-489 multi-phase init work nicely in all cases). [0] https://mail.python.org/pipermail/python-dev/2015-June/140423.html |
New changeset 265eeb60443a by Nick Coghlan in branch '3.5': New changeset f24cd8bc5250 by Nick Coghlan in branch 'default': |
tp_finalize handlers should return "void". See bpo-33644. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: