-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-34784: Posixmodule: Heap StructSequence #9665
Conversation
Tested this on the gevent (https://github.com/gevent/gevent) third-party dep. This change is backwards-compatible. Repro steps:
|
@eduardo-elizondo Thanks for the PR. Is this PR still a WIP? If it is not, please edit the title. Thanks! |
@willingc Hi Carol, sorry yes this is ready for review - totally forgot to update the title. |
Looping in @encukou to look at this changes as well! Feel free to leave any feedback |
Hello Eddie, I will be adding some inline review comments to this PR. Your approach looks good to me. I.e. fix PyStructSequence_NewType() and then use it so that the types are heap allocated. In your commit message, NEWS entry or maybe in some code comments, I would try to incorporate the information in your post to python-dev, i.e. https://mail.python.org/pipermail/python-dev/2018-September/155069.html. That is good analysis and should get saved somewhere. Probably the commit message and NEWS would be most appropriate. It looks like there are some issues with memory leaks and ref counting. See inline comments. The BPO bug has multiple PR linked. I think the older one is obsolete by this one. You should close it in that case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure PyStructSequence_NewType() leaks memory. It would be useful to write a test in _testcapimodule.c that uses the API multiple times and the decrefs the types returned. Then we can use leak testing tools to ensure we are not losing memory either to refcount bugs or due to missing PyMem_Del() calls.
The older PR has the structseq.c changes; this one has the posixmodule.c changes. But one depends on the other, so this PR needs to include the structseq.c changes as well. To me, it does make sense to review the new implementation together with an example of using it. |
I finally updated the change to address all of your comments! I managed to fully clean up all the memory allocations without the need of an extra flag. Here's the rundown of the issues and the fixes: Leak of PyMemberDef: StructSequences have to dynamically create the This can be improved by looking at how new types get allocated. If we look into the implementation of Going back to StructSequences, we can easily reuse all of that machinery to clean up the dynamically allocated Leak of PyType_Slots: Leak of PyType_Spec: Testing: |
Misc/NEWS.d/next/Core and Builtins/2018-10-02-09-10-47.bpo-34784.07hdgD.rst
Outdated
Show resolved
Hide resolved
I like the approach! There's a nice way to resolve the current confusion about what from |
Addressed all of @encukou comments:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I'll merge and watch the buildbots.
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: #10854. All the issues in that commit have now been addressed since #11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
After python#9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: python#10854. All the issues in that commit have now been addressed since python#11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
After python#9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: python#10854. All the issues in that commit have now been addressed since python#11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
This PR was never backported to Python 3.7 and below? I cannot use PyStructSequence_NewType in Python 3.7 and earlier, even latest patch release. Is this only going to be fixed for Python 3.8 and forwards? My extension works in 3.8+ |
Correct, looks like this never got backported. 3.6 does not accept bug fixes anymore and 3.7 will only have one last bugfix release before it goes into security fixes only. Seems to me like it's not worth backporting this at this point since you wouldn't be able to use PyStructSequence_NewType in 3.7.0 - 3.7.7 anyway. |
Alright, I can live with that. Good to know, I'll put a 3.8+ note on my project. Thanks. |
https://bugs.python.org/issue34784