diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-01-27 13:40:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 13:40:44 (GMT) |
commit | 3d2ce3471646704ebd5252f4b20f065f139a53b1 (patch) | |
tree | 8942b677163981fb1b61cf35dcd461831557c28e /Python/compile.c | |
parent | c7f810b34d91a5c2fbe0a8385562015d2dd961f2 (diff) | |
download | cpython-3d2ce3471646704ebd5252f4b20f065f139a53b1.zip cpython-3d2ce3471646704ebd5252f4b20f065f139a53b1.tar.gz cpython-3d2ce3471646704ebd5252f4b20f065f139a53b1.tar.bz2 |
bpo-46458: emit code for else of a try block immediately after the try body (GH-30751)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/compile.c b/Python/compile.c index f1049fd..6883a4b 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3353,15 +3353,14 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s) static int compiler_try_except(struct compiler *c, stmt_ty s) { - basicblock *body, *orelse, *except, *end, *cleanup; + basicblock *body, *except, *end, *cleanup; Py_ssize_t i, n; body = compiler_new_block(c); except = compiler_new_block(c); - orelse = compiler_new_block(c); end = compiler_new_block(c); cleanup = compiler_new_block(c); - if (body == NULL || except == NULL || orelse == NULL || end == NULL || cleanup == NULL) + if (body == NULL || except == NULL || end == NULL || cleanup == NULL) return 0; ADDOP_JUMP(c, SETUP_FINALLY, except); compiler_use_next_block(c, body); @@ -3370,7 +3369,11 @@ compiler_try_except(struct compiler *c, stmt_ty s) VISIT_SEQ(c, stmt, s->v.Try.body); compiler_pop_fblock(c, TRY_EXCEPT, body); ADDOP_NOLINE(c, POP_BLOCK); - ADDOP_JUMP_NOLINE(c, JUMP_FORWARD, orelse); + if (s->v.Try.orelse && asdl_seq_LEN(s->v.Try.orelse)) { + NEXT_BLOCK(c); + VISIT_SEQ(c, stmt, s->v.Try.orelse); + } + ADDOP_JUMP_NOLINE(c, JUMP_FORWARD, end); n = asdl_seq_LEN(s->v.Try.handlers); compiler_use_next_block(c, except); @@ -3474,8 +3477,6 @@ compiler_try_except(struct compiler *c, stmt_ty s) ADDOP_I(c, RERAISE, 0); compiler_use_next_block(c, cleanup); POP_EXCEPT_AND_RERAISE(c); - compiler_use_next_block(c, orelse); - VISIT_SEQ(c, stmt, s->v.Try.orelse); compiler_use_next_block(c, end); return 1; } |