@@ -1000,8 +1000,8 @@ stack_effect(int opcode, int oparg, int jump)
10001000 return -1 ;
10011001 case CHECK_EXC_MATCH :
10021002 return 0 ;
1003- case JUMP_IF_NOT_EG_MATCH :
1004- return jump > 0 ? -1 : 0 ;
1003+ case CHECK_EG_MATCH :
1004+ return 0 ;
10051005 case IMPORT_NAME :
10061006 return -1 ;
10071007 case IMPORT_FROM :
@@ -3533,14 +3533,18 @@ compiler_try_except(struct compiler *c, stmt_ty s)
35333533 [] POP_BLOCK
35343534 [] JUMP L0
35353535
3536- [exc] L1: COPY 1 ) save copy of the original exception
3536+ [exc] L1: COPY 1 ) save copy of the original exception
35373537 [orig, exc] BUILD_LIST ) list for raised/reraised excs ("result")
35383538 [orig, exc, res] SWAP 2
35393539
35403540 [orig, res, exc] <evaluate E1>
3541- [orig, res, exc, E1] JUMP_IF_NOT_EG_MATCH L2
3541+ [orig, res, exc, E1] CHECK_EG_MATCH
3542+ [orig, red, rest/exc, match?] COPY 1
3543+ [orig, red, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3544+ [orig, red, exc, None] POP_TOP
3545+ [orig, red, exc] JUMP L2
35423546
3543- [orig, res, rest, match] <assign to V1> (or POP if no V1)
3547+ [orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
35443548
35453549 [orig, res, rest] SETUP_FINALLY R1
35463550 [orig, res, rest] <code for S1>
@@ -3622,6 +3626,10 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
36223626 if (except == NULL ) {
36233627 return 0 ;
36243628 }
3629+ basicblock * handle_match = compiler_new_block (c );
3630+ if (handle_match == NULL ) {
3631+ return 0 ;
3632+ }
36253633 if (i == 0 ) {
36263634 /* Push the original EG into the stack */
36273635 /*
@@ -3641,9 +3649,15 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
36413649 }
36423650 if (handler -> v .ExceptHandler .type ) {
36433651 VISIT (c , expr , handler -> v .ExceptHandler .type );
3644- ADDOP_JUMP (c , JUMP_IF_NOT_EG_MATCH , except );
3652+ ADDOP (c , CHECK_EG_MATCH );
3653+ ADDOP_I (c , COPY , 1 );
3654+ ADDOP_JUMP (c , POP_JUMP_IF_NOT_NONE , handle_match );
3655+ ADDOP (c , POP_TOP ); // match
3656+ ADDOP_JUMP (c , JUMP , except );
36453657 }
36463658
3659+ compiler_use_next_block (c , handle_match );
3660+
36473661 basicblock * cleanup_end = compiler_new_block (c );
36483662 if (cleanup_end == NULL ) {
36493663 return 0 ;
@@ -3657,7 +3671,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
36573671 compiler_nameop (c , handler -> v .ExceptHandler .name , Store );
36583672 }
36593673 else {
3660- ADDOP (c , POP_TOP ); // exc
3674+ ADDOP (c , POP_TOP ); // match
36613675 }
36623676
36633677 /*
0 commit comments