summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-01-02 23:22:42 (GMT)
committerGitHub <noreply@github.com>2022-01-02 23:22:42 (GMT)
commit65e7c1f90e9136fc61f4af029b065d9f6c5664c3 (patch)
treebf322965684bd0eeef7c220c5d1cb8307933cbb7 /Python/compile.c
parent8e75c6b49b7cb8515b917f01b32ece8c8ea2c0a0 (diff)
downloadcpython-65e7c1f90e9136fc61f4af029b065d9f6c5664c3.zip
cpython-65e7c1f90e9136fc61f4af029b065d9f6c5664c3.tar.gz
cpython-65e7c1f90e9136fc61f4af029b065d9f6c5664c3.tar.bz2
bpo-46219, 46221: simplify except* implementation following exc_info changes. Move helpers to exceptions.c. Do not assume that exception groups are truthy. (GH-30289)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 8e90b1a..48250b5 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1134,7 +1134,7 @@ stack_effect(int opcode, int oparg, int jump)
return jump ? 1 : 0;
case PREP_RERAISE_STAR:
- return 0;
+ return -1;
case RERAISE:
return -1;
case PUSH_EXC_INFO:
@@ -3488,12 +3488,16 @@ compiler_try_except(struct compiler *c, stmt_ty s)
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
[orig, res] PREP_RERAISE_STAR
- [i, exc] POP_JUMP_IF_TRUE RER
- [i, exc] POP
- [i] POP
+ [exc] DUP_TOP
+ [exc, exc] LOAD_CONST None
+ [exc, exc, None] COMPARE_IS
+ [exc, is_none] POP_JUMP_IF_FALSE RER
+ [exc] POP_TOP
[] JUMP_FORWARD L0
- [i, exc] RER: POP_EXCEPT_AND_RERAISE
+ [exc] RER: ROT_TWO
+ [exc, prev_exc_info] POP_EXCEPT
+ [exc] RERAISE 0
[] L0: <next statement>
*/
@@ -3657,18 +3661,21 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
compiler_use_next_block(c, reraise_star);
ADDOP(c, PREP_RERAISE_STAR);
ADDOP(c, DUP_TOP);
- ADDOP_JUMP(c, POP_JUMP_IF_TRUE, reraise);
+ ADDOP_LOAD_CONST(c, Py_None);
+ ADDOP_COMPARE(c, Is);
+ ADDOP_JUMP(c, POP_JUMP_IF_FALSE, reraise);
NEXT_BLOCK(c);
- /* Nothing to reraise - pop it */
- ADDOP(c, POP_TOP);
+ /* Nothing to reraise */
ADDOP(c, POP_TOP);
ADDOP(c, POP_BLOCK);
ADDOP(c, POP_EXCEPT);
ADDOP_JUMP(c, JUMP_FORWARD, end);
compiler_use_next_block(c, reraise);
ADDOP(c, POP_BLOCK);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ ADDOP(c, ROT_TWO);
+ ADDOP(c, POP_EXCEPT);
+ ADDOP_I(c, RERAISE, 0);
compiler_use_next_block(c, cleanup);
ADDOP(c, POP_EXCEPT_AND_RERAISE);
compiler_use_next_block(c, orelse);