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)

This commit is contained in:
Irit Katriel 2022-01-02 23:22:42 +00:00 committed by GitHub
parent 8e75c6b49b
commit 65e7c1f90e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 179 additions and 149 deletions

View file

@ -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);