Skip to content

Commit

Permalink
Revert "[3.12] pythongh-100762: Fix optimization in gen_close (python…
Browse files Browse the repository at this point in the history
…GH-111069) (python#115818)"

This reverts commit eb4774d.
  • Loading branch information
iritkatriel committed Jun 13, 2024
1 parent 8883db0 commit 47c7a30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_cprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def test_throw(self):

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):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_sys_setprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def g(p):
f_ident = ident(f)
g_ident = ident(g)
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),
Expand Down
5 changes: 2 additions & 3 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Py_RETURN_NONE;
}
}
Expand Down

0 comments on commit 47c7a30

Please sign in to comment.