summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-10-25 15:22:34 (GMT)
committerGitHub <noreply@github.com>2023-10-25 15:22:34 (GMT)
commit0db2517687efcf5ec0174a32398ec1564b3204f1 (patch)
tree7d305f234140e67219659fa3e38b14ae79c008fe /Objects
parenta4981921aa2c00f3883ef593fde1dbc034e3c304 (diff)
downloadcpython-0db2517687efcf5ec0174a32398ec1564b3204f1.zip
cpython-0db2517687efcf5ec0174a32398ec1564b3204f1.tar.gz
cpython-0db2517687efcf5ec0174a32398ec1564b3204f1.tar.bz2
gh-100762: Fix optimization in gen_close (#111069)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genobject.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 491e631..6794cc6 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -378,7 +378,6 @@ 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) {
@@ -388,6 +387,7 @@ 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;
@@ -400,12 +400,13 @@ 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.code;
+ int exception_handler_depth = frame->prev_instr[0].op.arg;
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;
}
}