cpython: f90e7540dcba (original) (raw)
Mercurial > cpython
changeset 84869:f90e7540dcba
merge 3.3 (#18565) [#18565]
Benjamin Peterson benjamin@python.org | |
---|---|
date | Sat, 27 Jul 2013 14:07:19 -0700 |
parents | 852e824c7093(current diff)516303f32bad(diff) |
children | 66a3dc613627 |
files | |
diffstat | 1 files changed, 40 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_pep380.py 41 |
line wrap: on
line diff
--- a/Lib/test/test_pep380.py +++ b/Lib/test/test_pep380.py @@ -13,7 +13,7 @@ import sys import inspect import parser -from test.support import captured_stderr +from test.support import captured_stderr, disable_gc, gc_collect class TestPEP380Operation(unittest.TestCase): """ @@ -954,6 +954,45 @@ class TestPEP380Operation(unittest.TestC list(gen()) self.assertEqual(ret, 42)
- def test_close_with_cleared_frame(self):
# See issue #17669.[](#l1.17)
#[](#l1.18)
# Create a stack of generators: outer() delegating to inner()[](#l1.19)
# delegating to innermost(). The key point is that the instance of[](#l1.20)
# inner is created first: this ensures that its frame appears before[](#l1.21)
# the instance of outer in the GC linked list.[](#l1.22)
#[](#l1.23)
# At the gc.collect call:[](#l1.24)
# - frame_clear is called on the inner_gen frame.[](#l1.25)
# - gen_dealloc is called on the outer_gen generator (the only[](#l1.26)
# reference is in the frame's locals).[](#l1.27)
# - gen_close is called on the outer_gen generator.[](#l1.28)
# - gen_close_iter is called to close the inner_gen generator, which[](#l1.29)
# in turn calls gen_close, and gen_yf.[](#l1.30)
#[](#l1.31)
# Previously, gen_yf would crash since inner_gen's frame had been[](#l1.32)
# cleared (and in particular f_stacktop was NULL).[](#l1.33)
def innermost():[](#l1.35)
yield[](#l1.36)
def inner():[](#l1.37)
outer_gen = yield[](#l1.38)
yield from innermost()[](#l1.39)
def outer():[](#l1.40)
inner_gen = yield[](#l1.41)
yield from inner_gen[](#l1.42)
with disable_gc():[](#l1.44)
inner_gen = inner()[](#l1.45)
outer_gen = outer()[](#l1.46)
outer_gen.send(None)[](#l1.47)
outer_gen.send(inner_gen)[](#l1.48)
outer_gen.send(outer_gen)[](#l1.49)
del outer_gen[](#l1.51)
del inner_gen[](#l1.52)
gc_collect()[](#l1.53)