Skip to content

gh-118746: Fix crash in frame_getlocals - #118748

Merged
gvanrossum merged 2 commits into
python:mainfrom
gaogaotiantian:fix-f_locals-crash
May 8, 2024
Merged

gh-118746: Fix crash in frame_getlocals#118748
gvanrossum merged 2 commits into
python:mainfrom
gaogaotiantian:fix-f_locals-crash

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented May 7, 2024

Copy link
Copy Markdown
Member

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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

ngoldbaum commented May 8, 2024

Copy link
Copy Markdown
Contributor

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

@JelleZijlstra

Copy link
Copy Markdown
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
@gvanrossum

Copy link
Copy Markdown
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