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

gh-125859: Fix crash when gc.get_objects is called during GC #125882

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Oct 23, 2024

This fixes a crash when gc.get_objects() or gc.get_referrers() is called during a GC in the free threading build.

Switch to _PyObjectStack to avoid corrupting the struct worklist linked list maintained by the GC. Also, don't return objects that are frozen (gc.freeze()) or in the process of being collected to more closely match the behavior of the default build.

This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is
called during a GC in the free threading build. Switch to
`_PyObjectStack` to avoid corrupting the `struct worklist` linked list
maintained by the GC. Also, don't return objects that are frozen
(gc.freeze) or in the process of being collected to more closely match
the behavior of the default build.
Copy link
Contributor

@mpage mpage left a comment

Choose a reason for hiding this comment

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

LGTM

After the `_PyEval_StartTheWorld()` call, other threads may be running
and mutating objects. Ensure that the objects are kept alive by
incref'ing them when they're added to the `_PyObjectStack`.
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