@@ -84,8 +84,8 @@ It's called a frame block to distinguish it from a basic block in the
84
84
compiler IR.
85
85
*/
86
86
87
- enum fblocktype { WHILE_LOOP , FOR_LOOP , EXCEPT , FINALLY_TRY , FINALLY_END ,
88
- WITH , ASYNC_WITH , HANDLER_CLEANUP , POP_VALUE };
87
+ enum fblocktype { WHILE_LOOP , FOR_LOOP , TRY_EXCEPT , FINALLY_TRY , FINALLY_END ,
88
+ WITH , ASYNC_WITH , HANDLER_CLEANUP , POP_VALUE , EXCEPTION_HANDLER };
89
89
90
90
struct fblockinfo {
91
91
enum fblocktype fb_type ;
@@ -1624,9 +1624,7 @@ compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b,
1624
1624
{
1625
1625
struct fblockinfo * f ;
1626
1626
if (c -> u -> u_nfblocks >= CO_MAXBLOCKS ) {
1627
- PyErr_SetString (PyExc_SyntaxError ,
1628
- "too many statically nested blocks" );
1629
- return 0 ;
1627
+ return compiler_error (c , "too many statically nested blocks" );
1630
1628
}
1631
1629
f = & c -> u -> u_fblock [c -> u -> u_nfblocks ++ ];
1632
1630
f -> fb_type = t ;
@@ -1666,6 +1664,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
1666
1664
{
1667
1665
switch (info -> fb_type ) {
1668
1666
case WHILE_LOOP :
1667
+ case EXCEPTION_HANDLER :
1669
1668
return 1 ;
1670
1669
1671
1670
case FOR_LOOP :
@@ -1676,7 +1675,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
1676
1675
ADDOP (c , POP_TOP );
1677
1676
return 1 ;
1678
1677
1679
- case EXCEPT :
1678
+ case TRY_EXCEPT :
1680
1679
ADDOP (c , POP_BLOCK );
1681
1680
return 1 ;
1682
1681
@@ -3064,14 +3063,17 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3064
3063
return 0 ;
3065
3064
ADDOP_JREL (c , SETUP_FINALLY , except );
3066
3065
compiler_use_next_block (c , body );
3067
- if (!compiler_push_fblock (c , EXCEPT , body , NULL , NULL ))
3066
+ if (!compiler_push_fblock (c , TRY_EXCEPT , body , NULL , NULL ))
3068
3067
return 0 ;
3069
3068
VISIT_SEQ (c , stmt , s -> v .Try .body );
3070
3069
ADDOP (c , POP_BLOCK );
3071
- compiler_pop_fblock (c , EXCEPT , body );
3070
+ compiler_pop_fblock (c , TRY_EXCEPT , body );
3072
3071
ADDOP_JREL (c , JUMP_FORWARD , orelse );
3073
3072
n = asdl_seq_LEN (s -> v .Try .handlers );
3074
3073
compiler_use_next_block (c , except );
3074
+ /* Runtime will push a block here, so we need to account for that */
3075
+ if (!compiler_push_fblock (c , EXCEPTION_HANDLER , NULL , NULL , NULL ))
3076
+ return 0 ;
3075
3077
for (i = 0 ; i < n ; i ++ ) {
3076
3078
excepthandler_ty handler = (excepthandler_ty )asdl_seq_GET (
3077
3079
s -> v .Try .handlers , i );
@@ -3156,6 +3158,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3156
3158
}
3157
3159
compiler_use_next_block (c , except );
3158
3160
}
3161
+ compiler_pop_fblock (c , EXCEPTION_HANDLER , NULL );
3159
3162
ADDOP (c , RERAISE );
3160
3163
compiler_use_next_block (c , orelse );
3161
3164
VISIT_SEQ (c , stmt , s -> v .Try .orelse );
0 commit comments