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

Use Py_TRASHCAN_{BEGIN,END} in tp_dealloc functions #9839

Merged
merged 3 commits into from Dec 28, 2020
Merged

Conversation

msullivan
Copy link
Collaborator

@msullivan msullivan commented Dec 27, 2020

See https://github.com/python/cpython/blob/master/Include/cpython/object.h#L456

Fixes mypyc/mypyc#789.

I didn't add a test because a test needs to create a lot of nodes.
Tested manually.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks, this was a nasty bug. I assume that there's no easy way to fix this on Python 3.7 and earlier. Maybe we could implement something similar ourselves eventually?

Please add a follow-up issue to write a regression test to cover this case, once we have a way of adding expensive tests that only get run daily, for example.

@@ -627,8 +627,10 @@ def generate_dealloc_for_class(cl: ClassIR,
emitter.emit_line('{}({} *self)'.format(dealloc_func_name, cl.struct_name(emitter.names)))
emitter.emit_line('{')
emitter.emit_line('PyObject_GC_UnTrack(self);')
emitter.emit_line('CPy_TRASHCAN_BEGIN(self, {})'.format(dealloc_func_name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add short description of why we need to do this.

@msullivan
Copy link
Collaborator Author

This does work on on 3.7, but a new API got introduced in 3.8

@msullivan msullivan merged commit fe8fac1 into master Dec 28, 2020
@msullivan msullivan deleted the trashcan branch December 28, 2020 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segfault during garbage collection (stackoverflow on deeply nested circular object?)
2 participants