summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c16
-rw-r--r--Python/compile.c28
-rw-r--r--Python/opcode_targets.h16
3 files changed, 32 insertions, 28 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index ce4abd5..f7e08c6 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3804,7 +3804,7 @@ handle_eval_breaker:
DISPATCH();
}
- TARGET(JUMP_IF_NOT_EG_MATCH) {
+ TARGET(CHECK_EG_MATCH) {
PyObject *match_type = POP();
if (check_except_star_type_valid(tstate, match_type) < 0) {
Py_DECREF(match_type);
@@ -3825,15 +3825,11 @@ handle_eval_breaker:
assert(rest == NULL);
goto error;
}
-
if (Py_IsNone(match)) {
- Py_DECREF(match);
+ PUSH(match);
Py_XDECREF(rest);
- /* no match - jump to target */
- JUMPTO(oparg);
}
else {
-
/* Total or partial match - update the stack from
* [val]
* to
@@ -3841,17 +3837,11 @@ handle_eval_breaker:
* (rest can be Py_None)
*/
- PyObject *exc = TOP();
-
SET_TOP(rest);
PUSH(match);
-
PyErr_SetExcInfo(NULL, Py_NewRef(match), NULL);
-
- Py_DECREF(exc);
-
+ Py_DECREF(exc_value);
}
-
DISPATCH();
}
diff --git a/Python/compile.c b/Python/compile.c
index c3773a4..c92b267 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1000,8 +1000,8 @@ stack_effect(int opcode, int oparg, int jump)
return -1;
case CHECK_EXC_MATCH:
return 0;
- case JUMP_IF_NOT_EG_MATCH:
- return jump > 0 ? -1 : 0;
+ case CHECK_EG_MATCH:
+ return 0;
case IMPORT_NAME:
return -1;
case IMPORT_FROM:
@@ -3533,14 +3533,18 @@ compiler_try_except(struct compiler *c, stmt_ty s)
[] POP_BLOCK
[] JUMP L0
- [exc] L1: COPY 1 ) save copy of the original exception
+ [exc] L1: COPY 1 ) save copy of the original exception
[orig, exc] BUILD_LIST ) list for raised/reraised excs ("result")
[orig, exc, res] SWAP 2
[orig, res, exc] <evaluate E1>
- [orig, res, exc, E1] JUMP_IF_NOT_EG_MATCH L2
+ [orig, res, exc, E1] CHECK_EG_MATCH
+ [orig, red, rest/exc, match?] COPY 1
+ [orig, red, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
+ [orig, red, exc, None] POP_TOP
+ [orig, red, exc] JUMP L2
- [orig, res, rest, match] <assign to V1> (or POP if no V1)
+ [orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
[orig, res, rest] SETUP_FINALLY R1
[orig, res, rest] <code for S1>
@@ -3622,6 +3626,10 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
if (except == NULL) {
return 0;
}
+ basicblock *handle_match = compiler_new_block(c);
+ if (handle_match == NULL) {
+ return 0;
+ }
if (i == 0) {
/* Push the original EG into the stack */
/*
@@ -3641,9 +3649,15 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
}
if (handler->v.ExceptHandler.type) {
VISIT(c, expr, handler->v.ExceptHandler.type);
- ADDOP_JUMP(c, JUMP_IF_NOT_EG_MATCH, except);
+ ADDOP(c, CHECK_EG_MATCH);
+ ADDOP_I(c, COPY, 1);
+ ADDOP_JUMP(c, POP_JUMP_IF_NOT_NONE, handle_match);
+ ADDOP(c, POP_TOP); // match
+ ADDOP_JUMP(c, JUMP, except);
}
+ compiler_use_next_block(c, handle_match);
+
basicblock *cleanup_end = compiler_new_block(c);
if (cleanup_end == NULL) {
return 0;
@@ -3657,7 +3671,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
compiler_nameop(c, handler->v.ExceptHandler.name, Store);
}
else {
- ADDOP(c, POP_TOP); // exc
+ ADDOP(c, POP_TOP); // match
}
/*
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 2eba553..e71b3e2 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -36,6 +36,7 @@ static void *opcode_targets[256] = {
&&TARGET_JUMP_BACKWARD_QUICK,
&&TARGET_PUSH_EXC_INFO,
&&TARGET_CHECK_EXC_MATCH,
+ &&TARGET_CHECK_EG_MATCH,
&&TARGET_LOAD_ATTR_ADAPTIVE,
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
&&TARGET_LOAD_ATTR_MODULE,
@@ -47,40 +48,39 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_GLOBAL_ADAPTIVE,
&&TARGET_LOAD_GLOBAL_BUILTIN,
&&TARGET_LOAD_GLOBAL_MODULE,
- &&TARGET_LOAD_METHOD_ADAPTIVE,
&&TARGET_WITH_EXCEPT_START,
&&TARGET_GET_AITER,
&&TARGET_GET_ANEXT,
&&TARGET_BEFORE_ASYNC_WITH,
&&TARGET_BEFORE_WITH,
&&TARGET_END_ASYNC_FOR,
+ &&TARGET_LOAD_METHOD_ADAPTIVE,
&&TARGET_LOAD_METHOD_CLASS,
&&TARGET_LOAD_METHOD_MODULE,
&&TARGET_LOAD_METHOD_NO_DICT,
&&TARGET_LOAD_METHOD_WITH_DICT,
- &&TARGET_LOAD_METHOD_WITH_VALUES,
&&TARGET_STORE_SUBSCR,
&&TARGET_DELETE_SUBSCR,
+ &&TARGET_LOAD_METHOD_WITH_VALUES,
&&TARGET_PRECALL_ADAPTIVE,
&&TARGET_PRECALL_BOUND_METHOD,
&&TARGET_PRECALL_BUILTIN_CLASS,
&&TARGET_PRECALL_BUILTIN_FAST_WITH_KEYWORDS,
&&TARGET_PRECALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS,
- &&TARGET_PRECALL_NO_KW_BUILTIN_FAST,
&&TARGET_GET_ITER,
&&TARGET_GET_YIELD_FROM_ITER,
&&TARGET_PRINT_EXPR,
&&TARGET_LOAD_BUILD_CLASS,
+ &&TARGET_PRECALL_NO_KW_BUILTIN_FAST,
&&TARGET_PRECALL_NO_KW_BUILTIN_O,
- &&TARGET_PRECALL_NO_KW_ISINSTANCE,
&&TARGET_LOAD_ASSERTION_ERROR,
&&TARGET_RETURN_GENERATOR,
+ &&TARGET_PRECALL_NO_KW_ISINSTANCE,
&&TARGET_PRECALL_NO_KW_LEN,
&&TARGET_PRECALL_NO_KW_LIST_APPEND,
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST,
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_O,
- &&TARGET_PRECALL_NO_KW_STR_1,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
@@ -112,7 +112,7 @@ static void *opcode_targets[256] = {
&&TARGET_JUMP_FORWARD,
&&TARGET_JUMP_IF_FALSE_OR_POP,
&&TARGET_JUMP_IF_TRUE_OR_POP,
- &&TARGET_PRECALL_NO_KW_TUPLE_1,
+ &&TARGET_PRECALL_NO_KW_STR_1,
&&TARGET_POP_JUMP_IF_FALSE,
&&TARGET_POP_JUMP_IF_TRUE,
&&TARGET_LOAD_GLOBAL,
@@ -120,13 +120,13 @@ static void *opcode_targets[256] = {
&&TARGET_CONTAINS_OP,
&&TARGET_RERAISE,
&&TARGET_COPY,
- &&TARGET_PRECALL_NO_KW_TYPE_1,
+ &&TARGET_PRECALL_NO_KW_TUPLE_1,
&&TARGET_BINARY_OP,
&&TARGET_SEND,
&&TARGET_LOAD_FAST,
&&TARGET_STORE_FAST,
&&TARGET_DELETE_FAST,
- &&TARGET_JUMP_IF_NOT_EG_MATCH,
+ &&TARGET_PRECALL_NO_KW_TYPE_1,
&&TARGET_POP_JUMP_IF_NOT_NONE,
&&TARGET_POP_JUMP_IF_NONE,
&&TARGET_RAISE_VARARGS,