Skip to content

Commit 9c1e590

Browse files
committed
Fix some stack assumptions.
1 parent 5d82066 commit 9c1e590

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Python/codegen.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,20 @@ codegen_async_yield_from(compiler *c, location loc, expr_ty e)
552552

553553
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_ASYNC_GEN_WRAP);
554554
// Stack: [aiterator, wrapped_result]
555+
556+
// Generators expect the iterable at stack_top[-2], so we have to make an
557+
// extra copy.
558+
ADDOP_I(c, loc, COPY, 2);
559+
// Stack: [aiterator, wrapped_result, aiterator]
560+
ADDOP_I(c, loc, SWAP, 2);
561+
// Stack: [aiterator, aiterator, wrapped_result]
562+
555563
ADDOP_I(c, loc, YIELD_VALUE, 1);
564+
// Stack: [aiterator, aiterator, resumed_value]
565+
566+
ADDOP_I(c, loc, SWAP, 2);
567+
// Stack: [aiterator, resumed_value, aiterator]
568+
ADDOP(c, loc, POP_TOP);
556569
// Stack: [aiterator, resumed_value]
557570

558571
ADDOP(c, NO_LOCATION, POP_BLOCK);

0 commit comments

Comments
 (0)