diff options
author | Mark Shannon <mark@hotpy.org> | 2021-06-03 19:57:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 19:57:31 +0100 |
commit | cea0585b7939b487d7089f9d473f495264e8a491 (patch) | |
tree | f9a174a273315c61ff049bcb77fb292b8a5744f6 /Python/compile.c | |
parent | 84d80f5f30b1f545083c70a7d4e1e79ab75f9fa6 (diff) | |
download | cpython-git-cea0585b7939b487d7089f9d473f495264e8a491.tar.gz |
[3.10] bpo-44298: Backport #26513 to 3.10 (#26516)
* Backport 937cebc93 to 3.10
* Update importlib
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 3c69ce2eb8..4abc9f05ea 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1767,7 +1767,6 @@ static int compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info, int preserve_tos) { - int loc; switch (info->fb_type) { case WHILE_LOOP: case EXCEPTION_HANDLER: @@ -1820,7 +1819,6 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info, case WITH: case ASYNC_WITH: - loc = c->u->u_lineno; SET_LOC(c, (stmt_ty)info->fb_datum); ADDOP(c, POP_BLOCK); if (preserve_tos) { @@ -1835,7 +1833,10 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info, ADDOP(c, YIELD_FROM); } ADDOP(c, POP_TOP); - c->u->u_lineno = loc; + /* The exit block should appear to execute after the + * statement causing the unwinding, so make the unwinding + * instruction artificial */ + c->u->u_lineno = -1; return 1; case HANDLER_CLEANUP: @@ -2986,12 +2987,17 @@ compiler_return(struct compiler *c, stmt_ty s) if (preserve_tos) { VISIT(c, expr, s->v.Return.value); } else { - /* Emit instruction with line number for expression */ + /* Emit instruction with line number for return value */ if (s->v.Return.value != NULL) { SET_LOC(c, s->v.Return.value); ADDOP(c, NOP); } } + if (s->v.Return.value == NULL || s->v.Return.value->lineno != s->lineno) { + SET_LOC(c, s); + ADDOP(c, NOP); + } + if (!compiler_unwind_fblock_stack(c, preserve_tos, NULL)) return 0; if (s->v.Return.value == NULL) { @@ -3010,6 +3016,8 @@ static int compiler_break(struct compiler *c) { struct fblockinfo *loop = NULL; + /* Emit instruction with line number */ + ADDOP(c, NOP); if (!compiler_unwind_fblock_stack(c, 0, &loop)) { return 0; } @@ -3028,6 +3036,8 @@ static int compiler_continue(struct compiler *c) { struct fblockinfo *loop = NULL; + /* Emit instruction with line number */ + ADDOP(c, NOP); if (!compiler_unwind_fblock_stack(c, 0, &loop)) { return 0; } |