diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-03-23 14:35:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 14:35:33 +0200 |
commit | b9744e924ca07ba7db977e5958b91cd8db565632 (patch) | |
tree | aede553c802a392e1302b7f193b3a7112c84a3de /Python/compile.c | |
parent | c71edab15d023360388da8360700d419b5f48c81 (diff) | |
download | cpython-git-b9744e924ca07ba7db977e5958b91cd8db565632.tar.gz |
bpo-33041: Fixed jumping if the function contains an "async for" loop. (GH-6154)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/Python/compile.c b/Python/compile.c index 8ab33613b5..618f31a47d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2383,24 +2383,19 @@ compiler_async_for(struct compiler *c, stmt_ty s) ADDOP(c, DUP_TOP); ADDOP_O(c, LOAD_GLOBAL, stop_aiter_error, names); ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH); - ADDOP_JABS(c, POP_JUMP_IF_FALSE, try_cleanup); - - ADDOP(c, POP_TOP); - ADDOP(c, POP_TOP); - ADDOP(c, POP_TOP); - ADDOP(c, POP_EXCEPT); /* for SETUP_EXCEPT */ - ADDOP(c, POP_TOP); /* for correct calculation of stack effect */ - ADDOP(c, POP_BLOCK); /* for SETUP_LOOP */ - ADDOP_JABS(c, JUMP_ABSOLUTE, after_loop_else); - - - compiler_use_next_block(c, try_cleanup); + ADDOP_JABS(c, POP_JUMP_IF_TRUE, try_cleanup); ADDOP(c, END_FINALLY); compiler_use_next_block(c, after_try); VISIT_SEQ(c, stmt, s->v.AsyncFor.body); ADDOP_JABS(c, JUMP_ABSOLUTE, try); + compiler_use_next_block(c, try_cleanup); + ADDOP(c, POP_TOP); + ADDOP(c, POP_TOP); + ADDOP(c, POP_TOP); + ADDOP(c, POP_EXCEPT); /* for SETUP_EXCEPT */ + ADDOP(c, POP_TOP); /* for correct calculation of stack effect */ ADDOP(c, POP_BLOCK); /* for SETUP_LOOP */ compiler_pop_fblock(c, LOOP, try); @@ -3890,7 +3885,7 @@ compiler_async_comprehension_generator(struct compiler *c, _Py_IDENTIFIER(StopAsyncIteration); comprehension_ty gen; - basicblock *anchor, *if_cleanup, *try, + basicblock *if_cleanup, *try, *after_try, *except, *try_cleanup; Py_ssize_t i, n; @@ -3901,12 +3896,11 @@ compiler_async_comprehension_generator(struct compiler *c, try = compiler_new_block(c); after_try = compiler_new_block(c); - try_cleanup = compiler_new_block(c); except = compiler_new_block(c); if_cleanup = compiler_new_block(c); - anchor = compiler_new_block(c); + try_cleanup = compiler_new_block(c); - if (if_cleanup == NULL || anchor == NULL || + if (if_cleanup == NULL || try == NULL || after_try == NULL || except == NULL || try_cleanup == NULL) { return 0; @@ -3945,16 +3939,7 @@ compiler_async_comprehension_generator(struct compiler *c, ADDOP(c, DUP_TOP); ADDOP_O(c, LOAD_GLOBAL, stop_aiter_error, names); ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH); - ADDOP_JABS(c, POP_JUMP_IF_FALSE, try_cleanup); - - ADDOP(c, POP_TOP); - ADDOP(c, POP_TOP); - ADDOP(c, POP_TOP); - ADDOP(c, POP_EXCEPT); /* for SETUP_EXCEPT */ - ADDOP_JABS(c, JUMP_ABSOLUTE, anchor); - - - compiler_use_next_block(c, try_cleanup); + ADDOP_JABS(c, POP_JUMP_IF_TRUE, try_cleanup); ADDOP(c, END_FINALLY); compiler_use_next_block(c, after_try); @@ -4003,7 +3988,12 @@ compiler_async_comprehension_generator(struct compiler *c, } compiler_use_next_block(c, if_cleanup); ADDOP_JABS(c, JUMP_ABSOLUTE, try); - compiler_use_next_block(c, anchor); + + compiler_use_next_block(c, try_cleanup); + ADDOP(c, POP_TOP); + ADDOP(c, POP_TOP); + ADDOP(c, POP_TOP); + ADDOP(c, POP_EXCEPT); /* for SETUP_EXCEPT */ ADDOP(c, POP_TOP); return 1; |