@@ -1224,12 +1224,17 @@ codegen_wrap_in_stopiteration_handler(compiler *c)
12241224{
12251225 NEW_JUMP_TARGET_LABEL (c , handler );
12261226
1227- /* Insert SETUP_CLEANUP just before RESUME */
1227+ /* Insert SETUP_CLEANUP just after the initial RETURN_GENERATOR; POP_TOP */
12281228 instr_sequence * seq = INSTR_SEQUENCE (c );
12291229 int resume = 0 ;
1230- while (_PyInstructionSequence_GetInstruction (seq , resume ).i_opcode != RESUME ) {
1230+ while (_PyInstructionSequence_GetInstruction (seq , resume ).i_opcode != RETURN_GENERATOR ) {
12311231 resume ++ ;
1232+ assert (resume < seq -> s_used );
12321233 }
1234+ resume ++ ;
1235+ assert (_PyInstructionSequence_GetInstruction (seq , resume ).i_opcode == POP_TOP );
1236+ resume ++ ;
1237+ assert (resume < seq -> s_used );
12331238 RETURN_IF_ERROR (
12341239 _PyInstructionSequence_InsertInstruction (
12351240 seq , resume ,
@@ -4977,10 +4982,14 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
49774982 RETURN_IF_ERROR (
49784983 _PyInstructionSequence_InsertInstruction (
49794984 INSTR_SEQUENCE (c ), 0 ,
4980- LOAD_FAST , 0 , LOC ( outermost -> iter ) ));
4985+ RESUME , RESUME_AT_GEN_EXPR_START , NO_LOCATION ));
49814986 RETURN_IF_ERROR (
49824987 _PyInstructionSequence_InsertInstruction (
49834988 INSTR_SEQUENCE (c ), 1 ,
4989+ LOAD_FAST , 0 , LOC (outermost -> iter )));
4990+ RETURN_IF_ERROR (
4991+ _PyInstructionSequence_InsertInstruction (
4992+ INSTR_SEQUENCE (c ), 2 ,
49844993 outermost -> is_async ? GET_AITER : GET_ITER ,
49854994 0 , LOC (outermost -> iter )));
49864995 iter_state = ITERATOR_ON_STACK ;
0 commit comments