diff --git a/Python/bytecodes.c b/Python/bytecodes.c index f91b791e68741a..a453de5d6d7d37 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2615,13 +2615,13 @@ dummy_func( STAT_INC(FOR_ITER, hit); PyListObject *seq = it->it_seq; if (seq == NULL || it->it_index >= PyList_GET_SIZE(seq)) { - it->it_index = -1; #ifndef Py_GIL_DISABLED if (seq != NULL) { it->it_seq = NULL; Py_DECREF(seq); } #endif + it->it_index = -1; Py_DECREF(iter); STACK_SHRINK(1); /* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */ diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 068eefafd1b4a4..c23c8bf99c8aff 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2553,13 +2553,13 @@ STAT_INC(FOR_ITER, hit); PyListObject *seq = it->it_seq; if (seq == NULL || it->it_index >= PyList_GET_SIZE(seq)) { - it->it_index = -1; #ifndef Py_GIL_DISABLED if (seq != NULL) { it->it_seq = NULL; Py_DECREF(seq); } #endif + it->it_index = -1; Py_DECREF(iter); STACK_SHRINK(1); /* Jump forward oparg, then skip following END_FOR and POP_TOP instructions */