summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index da98630..a1ca66e 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2369,7 +2369,7 @@ dummy_func(
goto enter_tier_one;
}
- replaced op(_POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
+ replaced op(_POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
assert(PyBool_Check(cond));
int flag = Py_IsFalse(cond);
#if ENABLE_SPECIALIZATION
@@ -2513,7 +2513,7 @@ dummy_func(
#endif /* ENABLE_SPECIALIZATION */
}
- op(_FOR_ITER, (iter -- iter, next)) {
+ replaced op(_FOR_ITER, (iter -- iter, next)) {
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
next = (*Py_TYPE(iter)->tp_iternext)(iter);
if (next == NULL) {
@@ -2536,6 +2536,25 @@ dummy_func(
// Common case: no jump, leave it to the code generator
}
+ op(_FOR_ITER_TIER_TWO, (iter -- iter, next)) {
+ /* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
+ next = (*Py_TYPE(iter)->tp_iternext)(iter);
+ if (next == NULL) {
+ if (_PyErr_Occurred(tstate)) {
+ if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
+ GOTO_ERROR(error);
+ }
+ _PyErr_Clear(tstate);
+ }
+ /* iterator ended normally */
+ Py_DECREF(iter);
+ STACK_SHRINK(1);
+ /* The translator sets the deopt target just past END_FOR */
+ DEOPT_IF(true);
+ }
+ // Common case: no jump, leave it to the code generator
+ }
+
macro(FOR_ITER) = _SPECIALIZE_FOR_ITER + _FOR_ITER;
inst(INSTRUMENTED_FOR_ITER, (unused/1 -- )) {