mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
[3.13] GH-100964: Fix reference cycle in exhausted generator frames (G… (#142904)
* [3.13] GH-100964: Fix reference cycle in exhausted generator frames (GH-141112)
(cherry picked from commit 92243dc62c)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
This commit is contained in:
parent
db552ddb1e
commit
8f7c4f1cef
3 changed files with 14 additions and 1 deletions
|
|
@ -112,6 +112,18 @@ def g3(): return (yield from f())
|
|||
gen.send(2)
|
||||
self.assertEqual(cm.exception.value, 2)
|
||||
|
||||
def test_exhausted_generator_frame_cycle(self):
|
||||
def g():
|
||||
yield
|
||||
|
||||
generator = g()
|
||||
frame = generator.gi_frame
|
||||
self.assertIsNone(frame.f_back)
|
||||
next(generator)
|
||||
self.assertIsNone(frame.f_back)
|
||||
next(generator, None)
|
||||
self.assertIsNone(frame.f_back)
|
||||
|
||||
|
||||
class GeneratorTest(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix reference cycle in exhausted generator frames. Patch by Savannah Ostrowski.
|
||||
|
|
@ -1696,10 +1696,10 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
|
|||
gen->gi_exc_state.previous_item = NULL;
|
||||
tstate->c_recursion_remaining--;
|
||||
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
|
||||
frame->previous = NULL;
|
||||
_PyFrame_ClearExceptCode(frame);
|
||||
_PyErr_ClearExcState(&gen->gi_exc_state);
|
||||
tstate->c_recursion_remaining++;
|
||||
frame->previous = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue