Skip to content

bpo-45813: Drop redundant assertion from frame.clear() #29990

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 3 commits into from
Dec 8, 2021

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Dec 8, 2021

#29700 fixes one crash scenario.

This PR fixes a case when the generator is held by external reference, not the generator's frame object.

A separate NEWs entry is not required, #29700 already provides a good enough description.

https://bugs.python.org/issue45813

@@ -686,7 +686,6 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
}
if (f->f_frame->generator) {
_PyGen_Finalize(f->f_frame->generator);
assert(f->f_frame->generator == NULL);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check doesn't make sense, frame->generator consistency is checked by InterpreterFrame (Python/frame.c), not by PyFrameObject (Objects/frameobject.c).

@markshannon I very much appreciate it if you find time for the review.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. This assert would be appropriate in the dealloc function, but not in clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brilliant idea. Added assertion to frame_dealloc().

@@ -686,7 +686,6 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
}
if (f->f_frame->generator) {
_PyGen_Finalize(f->f_frame->generator);
assert(f->f_frame->generator == NULL);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brilliant idea. Added assertion to frame_dealloc().

'This would crash the interpreter in 3.11a2'
async def f():
pass
frame = f().cr_frame
frame.clear()
with self.assertWarns(RuntimeWarning):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suppress printing RuntimeWarning: coroutine 'CoroutineTest.test_bpo_....<locals>.f' was never awaited on the console.

@markshannon markshannon merged commit d4363d2 into python:main Dec 8, 2021
@asvetlov asvetlov deleted the drop-frame-clear-assertion branch December 8, 2021 16:07
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.

4 participants