summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-10-27 10:55:03 (GMT)
committerGitHub <noreply@github.com>2022-10-27 10:55:03 (GMT)
commit22863df7ca5f9cd01a40ab3dce3d067ec5666081 (patch)
tree73c460d80f41b45a331b7d886defe39127e12472 /Python/ceval.c
parente60892f9db1316dbabf7a652d7648e4f968b745d (diff)
downloadcpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.zip
cpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.tar.gz
cpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.tar.bz2
GH-96793: Change `FOR_ITER` to not pop the iterator on exhaustion. (GH-96801)
Change FOR_ITER to have the same stack effect regardless of whether it branches or not. Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 35ce767..ac995d7 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1298,6 +1298,14 @@ handle_eval_breaker:
DISPATCH();
}
+ TARGET(END_FOR) {
+ PyObject *value = POP();
+ Py_DECREF(value);
+ value = POP();
+ Py_DECREF(value);
+ DISPATCH();
+ }
+
TARGET(UNARY_POSITIVE) {
PyObject *value = TOP();
PyObject *res = PyNumber_Positive(value);
@@ -3844,9 +3852,11 @@ handle_eval_breaker:
_PyErr_Clear(tstate);
}
/* iterator ended normally */
+ assert(_Py_OPCODE(next_instr[INLINE_CACHE_ENTRIES_FOR_ITER + oparg] == END_FOR));
STACK_SHRINK(1);
Py_DECREF(iter);
- JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
+ /* Skip END_FOR */
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
DISPATCH();
}
@@ -3884,7 +3894,7 @@ handle_eval_breaker:
}
STACK_SHRINK(1);
Py_DECREF(it);
- JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
DISPATCH();
}
@@ -3898,7 +3908,7 @@ handle_eval_breaker:
if (r->index >= r->len) {
STACK_SHRINK(1);
Py_DECREF(r);
- JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
DISPATCH();
}
long value = (long)(r->start +