summaryrefslogtreecommitdiffstats
path: root/Python/codegen.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-03-07 14:30:31 (GMT)
committerGitHub <noreply@github.com>2025-03-07 14:30:31 (GMT)
commit89df62c12093bfa079860a93032468ebece3774d (patch)
treee982ec3b0a29f1c8fb727e0fe4b49b62909b5fb0 /Python/codegen.c
parente5527f2cdda501542bf94179093e1a15d7889b74 (diff)
downloadcpython-89df62c12093bfa079860a93032468ebece3774d.zip
cpython-89df62c12093bfa079860a93032468ebece3774d.tar.gz
cpython-89df62c12093bfa079860a93032468ebece3774d.tar.bz2
GH-128534: Fix behavior of branch monitoring for `async for` (GH-130847)
* Both branches in a pair now have a common source and are included in co_branches
Diffstat (limited to 'Python/codegen.c')
-rw-r--r--Python/codegen.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index 8f1a298..7a3f787 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -2019,13 +2019,13 @@ codegen_for(compiler *c, stmt_ty s)
return SUCCESS;
}
-
static int
codegen_async_for(compiler *c, stmt_ty s)
{
location loc = LOC(s);
NEW_JUMP_TARGET_LABEL(c, start);
+ NEW_JUMP_TARGET_LABEL(c, send);
NEW_JUMP_TARGET_LABEL(c, except);
NEW_JUMP_TARGET_LABEL(c, end);
@@ -2039,6 +2039,7 @@ codegen_async_for(compiler *c, stmt_ty s)
ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
ADDOP(c, loc, GET_ANEXT);
ADDOP_LOAD_CONST(c, loc, Py_None);
+ USE_LABEL(c, send);
ADD_YIELD_FROM(c, loc, 1);
ADDOP(c, loc, POP_BLOCK); /* for SETUP_FINALLY */
ADDOP(c, loc, NOT_TAKEN);
@@ -2057,7 +2058,7 @@ codegen_async_for(compiler *c, stmt_ty s)
/* Use same line number as the iterator,
* as the END_ASYNC_FOR succeeds the `for`, not the body. */
loc = LOC(s->v.AsyncFor.iter);
- ADDOP(c, loc, END_ASYNC_FOR);
+ ADDOP_JUMP(c, loc, END_ASYNC_FOR, send);
/* `else` block */
VISIT_SEQ(c, stmt, s->v.AsyncFor.orelse);
@@ -4252,6 +4253,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
int iter_on_stack)
{
NEW_JUMP_TARGET_LABEL(c, start);
+ NEW_JUMP_TARGET_LABEL(c, send);
NEW_JUMP_TARGET_LABEL(c, except);
NEW_JUMP_TARGET_LABEL(c, if_cleanup);
@@ -4279,6 +4281,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
ADDOP(c, loc, GET_ANEXT);
ADDOP_LOAD_CONST(c, loc, Py_None);
+ USE_LABEL(c, send);
ADD_YIELD_FROM(c, loc, 1);
ADDOP(c, loc, POP_BLOCK);
VISIT(c, expr, gen->target);
@@ -4338,7 +4341,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
USE_LABEL(c, except);
- ADDOP(c, loc, END_ASYNC_FOR);
+ ADDOP_JUMP(c, loc, END_ASYNC_FOR, send);
return SUCCESS;
}