diff options
-rw-r--r-- | Lib/test/test_cprofile.py | 4 | ||||
-rw-r--r-- | Lib/test/test_sys_setprofile.py | 4 | ||||
-rw-r--r-- | Objects/genobject.c | 5 |
3 files changed, 8 insertions, 5 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index 27e8a76790..3056fe84da 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -83,8 +83,8 @@ class CProfileTest(ProfileTest): for func, (cc, nc, _, _, _) in pr.stats.items(): if func[2] == "<genexpr>": - self.assertEqual(cc, 1) - self.assertEqual(nc, 1) + self.assertEqual(cc, 2) + self.assertEqual(nc, 2) class TestCommandLine(unittest.TestCase): diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py index bb8adc8b55..9e8936630d 100644 --- a/Lib/test/test_sys_setprofile.py +++ b/Lib/test/test_sys_setprofile.py @@ -267,6 +267,10 @@ class ProfileHookTestCase(TestCaseBase): self.check_events(g, [(1, 'call', g_ident), (2, 'call', f_ident), (2, 'return', f_ident), + # once more; the generator is being garbage collected + # and it will do a PY_THROW + (2, 'call', f_ident), + (2, 'return', f_ident), (1, 'return', g_ident), ]) diff --git a/Objects/genobject.c b/Objects/genobject.c index dc034a4b72..98d24b9acf 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -374,6 +374,7 @@ static PyObject * gen_close(PyGenObject *gen, PyObject *args) { PyObject *retval; + PyObject *yf = _PyGen_yf(gen); int err = 0; if (gen->gi_frame_state == FRAME_CREATED) { @@ -383,7 +384,6 @@ gen_close(PyGenObject *gen, PyObject *args) if (gen->gi_frame_state >= FRAME_COMPLETED) { Py_RETURN_NONE; } - PyObject *yf = _PyGen_yf(gen); if (yf) { PyFrameState state = gen->gi_frame_state; gen->gi_frame_state = FRAME_EXECUTING; @@ -396,13 +396,12 @@ gen_close(PyGenObject *gen, PyObject *args) * YIELD_VALUE if the debugger has changed the lineno. */ if (err == 0 && is_yield(frame->prev_instr)) { assert(is_resume(frame->prev_instr + 1)); - int exception_handler_depth = frame->prev_instr[0].op.arg; + int exception_handler_depth = frame->prev_instr[0].op.code; assert(exception_handler_depth > 0); /* We can safely ignore the outermost try block * as it automatically generated to handle * StopIteration. */ if (exception_handler_depth == 1) { - gen->gi_frame_state = FRAME_COMPLETED; _PyFrame_ClearLocals((_PyInterpreterFrame *)gen->gi_iframe); Py_RETURN_NONE; } |