@@ -444,7 +444,10 @@ codegen_addop_j(instr_sequence *seq, location loc,
444444 RETURN_IF_ERROR(addop_binary((C), (LOC), (BINOP), true))
445445
446446#define ADD_YIELD_FROM (C , LOC , await ) \
447- RETURN_IF_ERROR(codegen_add_yield_from((C), (LOC), (await)))
447+ RETURN_IF_ERROR(codegen_add_yield_from((C), (LOC), (await), NULL))
448+
449+ #define ADD_YIELD_FROM_WITH_EXIT (C , LOC , await , P_EXIT ) \
450+ RETURN_IF_ERROR(codegen_add_yield_from((C), (LOC), (await), (P_EXIT)))
448451
449452#define POP_EXCEPT_AND_RERAISE (C , LOC ) \
450453 RETURN_IF_ERROR(codegen_pop_except_and_reraise((C), (LOC)))
@@ -497,11 +500,14 @@ codegen_call_exit_with_nones(compiler *c, location loc)
497500}
498501
499502static int
500- codegen_add_yield_from (compiler * c , location loc , int await )
503+ codegen_add_yield_from (compiler * c , location loc , int await , jump_target_label * p_exit )
501504{
502505 NEW_JUMP_TARGET_LABEL (c , send );
503506 NEW_JUMP_TARGET_LABEL (c , fail );
504507 NEW_JUMP_TARGET_LABEL (c , exit );
508+ if (p_exit != NULL ) {
509+ * p_exit = exit ;
510+ }
505511
506512 USE_LABEL (c , send );
507513 ADDOP_JUMP (c , loc , SEND , exit );
@@ -2212,7 +2218,7 @@ codegen_async_for(compiler *c, stmt_ty s)
22122218 location loc = LOC (s );
22132219
22142220 NEW_JUMP_TARGET_LABEL (c , start );
2215- NEW_JUMP_TARGET_LABEL (c , send );
2221+ NEW_JUMP_TARGET_LABEL (c , end_send );
22162222 NEW_JUMP_TARGET_LABEL (c , except );
22172223 NEW_JUMP_TARGET_LABEL (c , end );
22182224
@@ -2227,8 +2233,7 @@ codegen_async_for(compiler *c, stmt_ty s)
22272233 ADDOP (c , loc , GET_ANEXT );
22282234 ADDOP (c , loc , PUSH_NULL );
22292235 ADDOP_LOAD_CONST (c , loc , Py_None );
2230- USE_LABEL (c , send );
2231- ADD_YIELD_FROM (c , loc , 1 );
2236+ ADD_YIELD_FROM_WITH_EXIT (c , loc , 1 , & end_send );
22322237 ADDOP (c , loc , POP_BLOCK ); /* for SETUP_FINALLY */
22332238 ADDOP (c , loc , NOT_TAKEN );
22342239
@@ -2246,7 +2251,7 @@ codegen_async_for(compiler *c, stmt_ty s)
22462251 /* Use same line number as the iterator,
22472252 * as the END_ASYNC_FOR succeeds the `for`, not the body. */
22482253 loc = LOC (s -> v .AsyncFor .iter );
2249- ADDOP_JUMP (c , loc , END_ASYNC_FOR , send );
2254+ ADDOP_JUMP (c , loc , END_ASYNC_FOR , end_send );
22502255
22512256 /* `else` block */
22522257 VISIT_SEQ (c , stmt , s -> v .AsyncFor .orelse );
@@ -4814,7 +4819,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
48144819 IterStackPosition iter_pos , bool avoid_creation )
48154820{
48164821 NEW_JUMP_TARGET_LABEL (c , start );
4817- NEW_JUMP_TARGET_LABEL (c , send );
4822+ NEW_JUMP_TARGET_LABEL (c , end_send );
48184823 NEW_JUMP_TARGET_LABEL (c , except );
48194824 NEW_JUMP_TARGET_LABEL (c , if_cleanup );
48204825
@@ -4845,9 +4850,9 @@ codegen_async_comprehension_generator(compiler *c, location loc,
48454850 ADDOP (c , loc , GET_ANEXT );
48464851 ADDOP (c , loc , PUSH_NULL );
48474852 ADDOP_LOAD_CONST (c , loc , Py_None );
4848- USE_LABEL (c , send );
4849- ADD_YIELD_FROM (c , loc , 1 );
4853+ ADD_YIELD_FROM_WITH_EXIT (c , loc , 1 , & end_send );
48504854 ADDOP (c , loc , POP_BLOCK );
4855+ ADDOP (c , loc , NOT_TAKEN );
48514856 VISIT (c , expr , gen -> target );
48524857
48534858 Py_ssize_t n = asdl_seq_LEN (gen -> ifs );
@@ -4886,7 +4891,7 @@ codegen_async_comprehension_generator(compiler *c, location loc,
48864891
48874892 USE_LABEL (c , except );
48884893
4889- ADDOP_JUMP (c , loc , END_ASYNC_FOR , send );
4894+ ADDOP_JUMP (c , loc , END_ASYNC_FOR , end_send );
48904895
48914896 return SUCCESS ;
48924897}
0 commit comments