@@ -3045,20 +3045,24 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3045
3045
[orig, res, exc] <evaluate E1>
3046
3046
[orig, res, exc, E1] CHECK_EG_MATCH
3047
3047
[orig, res, rest/exc, match?] COPY 1
3048
- [orig, res, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3049
- [orig, res, exc, None] POP_TOP
3050
- [orig, res, exc] JUMP L2
3048
+ [orig, res, rest/exc, match?, match?] POP_JUMP_IF_NONE C1
3051
3049
3052
- [orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
3050
+ [orig, res, rest, match] <assign to V1> (or POP if no V1)
3053
3051
3054
3052
[orig, res, rest] SETUP_FINALLY R1
3055
3053
[orig, res, rest] <code for S1>
3056
3054
[orig, res, rest] JUMP L2
3057
3055
3058
3056
[orig, res, rest, i, v] R1: LIST_APPEND 3 ) exc raised in except* body - add to res
3059
3057
[orig, res, rest, i] POP
3058
+ [orig, res, rest] JUMP LE2
3060
3059
3061
- [orig, res, rest] L2: <evaluate E2>
3060
+ [orig, res, rest] L2: NOP ) for lineno
3061
+ [orig, res, rest] JUMP LE2
3062
+
3063
+ [orig, res, rest/exc, None] C1: POP
3064
+
3065
+ [orig, res, rest] LE2: <evaluate E2>
3062
3066
.............................etc.......................
3063
3067
3064
3068
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
@@ -3114,7 +3118,8 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3114
3118
location loc = LOC (handler );
3115
3119
NEW_JUMP_TARGET_LABEL (c , next_except );
3116
3120
except = next_except ;
3117
- NEW_JUMP_TARGET_LABEL (c , handle_match );
3121
+ NEW_JUMP_TARGET_LABEL (c , except_with_error );
3122
+ NEW_JUMP_TARGET_LABEL (c , no_match );
3118
3123
if (i == 0 ) {
3119
3124
/* create empty list for exceptions raised/reraise in the except* blocks */
3120
3125
/*
@@ -3132,13 +3137,9 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3132
3137
VISIT (c , expr , handler -> v .ExceptHandler .type );
3133
3138
ADDOP (c , loc , CHECK_EG_MATCH );
3134
3139
ADDOP_I (c , loc , COPY , 1 );
3135
- ADDOP_JUMP (c , loc , POP_JUMP_IF_NOT_NONE , handle_match );
3136
- ADDOP (c , loc , POP_TOP ); // match
3137
- ADDOP_JUMP (c , loc , JUMP , except );
3140
+ ADDOP_JUMP (c , loc , POP_JUMP_IF_NONE , no_match );
3138
3141
}
3139
3142
3140
- USE_LABEL (c , handle_match );
3141
-
3142
3143
NEW_JUMP_TARGET_LABEL (c , cleanup_end );
3143
3144
NEW_JUMP_TARGET_LABEL (c , cleanup_body );
3144
3145
@@ -3197,9 +3198,16 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3197
3198
/* add exception raised to the res list */
3198
3199
ADDOP_I (c , NO_LOCATION , LIST_APPEND , 3 ); // exc
3199
3200
ADDOP (c , NO_LOCATION , POP_TOP ); // lasti
3200
- ADDOP_JUMP (c , NO_LOCATION , JUMP , except );
3201
+ ADDOP_JUMP (c , NO_LOCATION , JUMP , except_with_error );
3201
3202
3202
3203
USE_LABEL (c , except );
3204
+ ADDOP (c , NO_LOCATION , NOP ); // to hold a propagated location info
3205
+ ADDOP_JUMP (c , NO_LOCATION , JUMP , except_with_error );
3206
+
3207
+ USE_LABEL (c , no_match );
3208
+ ADDOP (c , loc , POP_TOP ); // match (None)
3209
+
3210
+ USE_LABEL (c , except_with_error );
3203
3211
3204
3212
if (i == n - 1 ) {
3205
3213
/* Add exc to the list (if not None it's the unhandled part of the EG) */
0 commit comments