summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-11-10 18:08:28 (GMT)
committerGitHub <noreply@github.com>2021-11-10 18:08:28 (GMT)
commit4cdeee5978ee3f8ea7fe95172ae04d866cd88177 (patch)
tree05bb2cf298351932ff37afd10b1befffc793d340 /Python/compile.c
parent05fbd60147456d77a7aecf29dddd86c5bde5872f (diff)
downloadcpython-4cdeee5978ee3f8ea7fe95172ae04d866cd88177.zip
cpython-4cdeee5978ee3f8ea7fe95172ae04d866cd88177.tar.gz
cpython-4cdeee5978ee3f8ea7fe95172ae04d866cd88177.tar.bz2
bpo-45711: remove unnecessary DUP_TOP and POP in exception handling (GH-29495)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 28b5c07..47889ab 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1127,7 +1127,7 @@ stack_effect(int opcode, int oparg, int jump)
case CONTAINS_OP:
return -1;
case JUMP_IF_NOT_EXC_MATCH:
- return -2;
+ return -1;
case IMPORT_NAME:
return -1;
case IMPORT_FROM:
@@ -3222,16 +3222,15 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
[] POP_BLOCK
[] JUMP_FORWARD L0
- [tb, val, exc] L1: DUP )
- [tb, val, exc, exc] <evaluate E1> )
- [tb, val, exc, exc, E1] JUMP_IF_NOT_EXC_MATCH L2 ) only if E1
+ [tb, val, exc] L1: <evaluate E1> )
+ [tb, val, exc, E1] JUMP_IF_NOT_EXC_MATCH L2 ) only if E1
[tb, val, exc] POP
[tb, val] <assign to V1> (or POP if no V1)
[tb] POP
[] <code for S1>
JUMP_FORWARD L0
- [tb, val, exc] L2: DUP
+ [tb, val, exc] L2: <evaluate E2>
.............................etc.......................
[tb, val, exc] Ln+1: RERAISE # re-raise exception
@@ -3281,7 +3280,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
if (except == NULL)
return 0;
if (handler->v.ExceptHandler.type) {
- ADDOP(c, DUP_TOP);
VISIT(c, expr, handler->v.ExceptHandler.type);
ADDOP_JUMP(c, JUMP_IF_NOT_EXC_MATCH, except);
NEXT_BLOCK(c);