mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-45711: remove unnecessary DUP_TOP and POP in exception handling (GH-29495)
This commit is contained in:
parent
05fbd60147
commit
4cdeee5978
4 changed files with 90 additions and 97 deletions
|
@ -3907,7 +3907,7 @@ check_eval_breaker:
|
|||
"inherit from BaseException is not "
|
||||
"allowed";
|
||||
PyObject *right = POP();
|
||||
PyObject *left = POP();
|
||||
PyObject *left = TOP();
|
||||
if (PyTuple_Check(right)) {
|
||||
Py_ssize_t i, length;
|
||||
length = PyTuple_GET_SIZE(right);
|
||||
|
@ -3916,7 +3916,6 @@ check_eval_breaker:
|
|||
if (!PyExceptionClass_Check(exc)) {
|
||||
_PyErr_SetString(tstate, PyExc_TypeError,
|
||||
cannot_catch_msg);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
goto error;
|
||||
}
|
||||
|
@ -3926,13 +3925,11 @@ check_eval_breaker:
|
|||
if (!PyExceptionClass_Check(right)) {
|
||||
_PyErr_SetString(tstate, PyExc_TypeError,
|
||||
cannot_catch_msg);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
int res = PyErr_GivenExceptionMatches(left, right);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
if (res > 0) {
|
||||
/* Exception matches -- Do nothing */;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue