Skip to content

gh-116098: Clean up frame allocation code and remove the invalid sneaky frame test #116687

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

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Mar 12, 2024

After a discussion with @brandtbucher , we believe the test is not testing what it's supposed to anymore. No new frame is created during the frame allocation and the test lost its meaning. Under no circumstance this test is valid or checking something reasonable. So we should just remove this test.

The fundamental reason the test is invalid is that the current frame allocation code is immune from being interrupted by Python code that can somehow create the same frame object. So we also remove the dead code in frame allocation, and replace it with an assert and some comments.

There's no user observable behavior changes so I'll skip the news, unless someone disagrees.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Thanks!

@brandtbucher brandtbucher enabled auto-merge (squash) March 12, 2024 22:50
@brandtbucher brandtbucher added tests Tests in the Lib/test dir interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Mar 12, 2024
@brandtbucher brandtbucher self-assigned this Mar 12, 2024
@brandtbucher
Copy link
Member

Probably not worth backporting.

@brandtbucher brandtbucher merged commit a53cc3f into python:main Mar 12, 2024
@gaogaotiantian gaogaotiantian deleted the remove-sneaky-frame-test branch March 12, 2024 23:41
vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 20, 2024
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
// Just pretend that we have an owned, cleared frame so frame_dealloc
// doesn't make the situation worse:
f->f_frame = (_PyInterpreterFrame *)f->_f_frame_data;
f->f_frame->owner = FRAME_CLEARED;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also remove the corresponding assert(frame->owner != FRAME_CLEARED) statements, especially since FRAME_CLEARED was never a valid member of enum _frameowner (it’s from enum _framestate).

colesbury pushed a commit that referenced this pull request Jan 2, 2025
GH-124148)

The `owner` field of `_PyInterpreterFrame` is supposed to be a member of
`enum _frameowner`, but `FRAME_CLEARED` is a member of `enum _framestate`.

At present, it happens that `FRAME_CLEARED` is not numerically equal to any
member of `enum _frameowner`, but that could change in the future. The code
that incorrectly assigned `owner = FRAME_CLEARED` was deleted in commit
a53cc3f (GH-116687). Remove the incorrect
checks for `owner != FRAME_CLEARED` as well.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
pythonGH-124148)

The `owner` field of `_PyInterpreterFrame` is supposed to be a member of
`enum _frameowner`, but `FRAME_CLEARED` is a member of `enum _framestate`.

At present, it happens that `FRAME_CLEARED` is not numerically equal to any
member of `enum _frameowner`, but that could change in the future. The code
that incorrectly assigned `owner = FRAME_CLEARED` was deleted in commit
a53cc3f (pythonGH-116687). Remove the incorrect
checks for `owner != FRAME_CLEARED` as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants