summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-03-23 12:34:35 (GMT)
committerGitHub <noreply@github.com>2018-03-23 12:34:35 (GMT)
commit702f8f3611bc49b73772cce2b9b041bd11ff9b35 (patch)
treef712f53a42dc54831e7daf7e3686bc9c875b37b3 /Python/ceval.c
parentc65bf3fe4a2bde424b79e350f36b7aaa3f6476f6 (diff)
downloadcpython-702f8f3611bc49b73772cce2b9b041bd11ff9b35.zip
cpython-702f8f3611bc49b73772cce2b9b041bd11ff9b35.tar.gz
cpython-702f8f3611bc49b73772cce2b9b041bd11ff9b35.tar.bz2
bpo-33041: Rework compiling an "async for" loop. (#6142)
* Added new opcode END_ASYNC_FOR. * Setting global StopAsyncIteration no longer breaks "async for" loops. * Jumping into an "async for" loop is now disabled. * Jumping out of an "async for" loop no longer corrupts the stack. * Simplify the compiler.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 1a72413..14603d3 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1944,6 +1944,26 @@ main_loop:
}
}
+ TARGET(END_ASYNC_FOR) {
+ PyObject *exc = POP();
+ assert(PyExceptionClass_Check(exc));
+ if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
+ PyTryBlock *b = PyFrame_BlockPop(f);
+ assert(b->b_type == EXCEPT_HANDLER);
+ Py_DECREF(exc);
+ UNWIND_EXCEPT_HANDLER(b);
+ Py_DECREF(POP());
+ JUMPBY(oparg);
+ FAST_DISPATCH();
+ }
+ else {
+ PyObject *val = POP();
+ PyObject *tb = POP();
+ PyErr_Restore(exc, val, tb);
+ goto exception_unwind;
+ }
+ }
+
TARGET(LOAD_BUILD_CLASS) {
_Py_IDENTIFIER(__build_class__);