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-118746: Fix crash in frame_getlocals #118748

Merged
merged 2 commits into from
May 8, 2024

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented May 7, 2024

We don't know the root cause for this yet. For now we create an empty dict for frame->f_locals to avoid the crash.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Please also fix the identical code snippet in _PyFrame_GetLocals.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

This LGTM -- can someone test with sklearn? Also, I'm not sure if this now has a race condition in free-threading mode. Then again, if this is a race condition, the old (pre-pep-667) code also had the same race condition, in _PyFrame_GetLocals.

@colesbury
Copy link
Contributor

This appears to fix the crash for me (tested in a debug, free-threaded build because that's what my scikit-learn deps were built for)

@ngoldbaum
Copy link
Contributor

ngoldbaum commented May 8, 2024

Fixes it for me in a similar non free-threaded build to the one I used in #118746.

@JelleZijlstra
Copy link
Member

Also confirmed the sklearn test no longer segfaults for me with this PR applied.

@gvanrossum gvanrossum merged commit e7aec87 into python:main May 8, 2024
36 checks passed
@gvanrossum
Copy link
Member

Thanks everyone!

@gaogaotiantian gaogaotiantian deleted the fix-f_locals-crash branch May 8, 2024 00:49
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
…ython#118748)

We don't know how to create an unoptimized frame with f_locals == NULL,
but they are seen in the wild, and this fixes the crash.
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.

5 participants