@@ -958,8 +958,7 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
958
958
case YIELD_FROM :
959
959
return -1 ;
960
960
case POP_BLOCK :
961
- /* Adjust 6 entries reserved by SETUP_FINALLY */
962
- return -6 ;
961
+ return 0 ;
963
962
case POP_EXCEPT :
964
963
return -3 ;
965
964
case END_FINALLY :
@@ -1036,10 +1035,11 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
1036
1035
* the handler if an exception be raised. */
1037
1036
return 6 ;
1038
1037
case BEGIN_FINALLY :
1039
- /* The stack has been reserved by SETUP_FINALLY */
1038
+ /* Actually pushes 1 value, but count 6 for balancing with
1039
+ * END_FINALLY and POP_FINALLY. */
1040
1040
return 6 ;
1041
1041
case CALL_FINALLY :
1042
- return 0 ;
1042
+ return 1 ;
1043
1043
1044
1044
case LOAD_FAST :
1045
1045
return 1 ;
@@ -1509,7 +1509,15 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
1509
1509
ADDOP (c , POP_BLOCK );
1510
1510
if (preserve_tos )
1511
1511
ADDOP (c , ROT_TWO );
1512
- ADDOP_JREL (c , CALL_FINALLY , info -> fb_exit );
1512
+ ADDOP (c , BEGIN_FINALLY );
1513
+ ADDOP (c , WITH_CLEANUP_START );
1514
+ if (info -> fb_type == ASYNC_WITH ) {
1515
+ ADDOP (c , GET_AWAITABLE );
1516
+ ADDOP_O (c , LOAD_CONST , Py_None , consts );
1517
+ ADDOP (c , YIELD_FROM );
1518
+ }
1519
+ ADDOP (c , WITH_CLEANUP_FINISH );
1520
+ ADDOP_I (c , POP_FINALLY , 0 );
1513
1521
return 1 ;
1514
1522
1515
1523
case HANDLER_CLEANUP :
@@ -5003,7 +5011,7 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
5003
5011
{
5004
5012
int i , target_depth , effect ;
5005
5013
struct instr * instr ;
5006
- // assert(!b->b_seen || b->b_startdepth == depth);
5014
+ assert (!b -> b_seen || b -> b_startdepth == depth );
5007
5015
if (b -> b_seen || b -> b_startdepth >= depth )
5008
5016
return maxdepth ;
5009
5017
/* Guard against infinite recursion */
@@ -5020,13 +5028,12 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
5020
5028
5021
5029
if (depth > maxdepth )
5022
5030
maxdepth = depth ;
5023
- if (depth < 0 )
5024
- return maxdepth ;
5025
5031
assert (depth >= 0 ); /* invalid code or bug in stackdepth() */
5026
5032
if (instr -> i_jrel || instr -> i_jabs ) {
5027
5033
/* Recursively inspect jump target */
5028
5034
target_depth = depth ;
5029
5035
if (instr -> i_opcode == CALL_FINALLY ) {
5036
+ depth = depth - 1 ;
5030
5037
continue ;
5031
5038
}
5032
5039
if (instr -> i_opcode == FOR_ITER ) {
0 commit comments