@@ -684,7 +684,7 @@ unwind_jump:;
684684 if (unum != 0 ) {
685685 // pop iter and iter_buf
686686 sp -- ;
687- sp -= sizeof ( mp_obj_iter_buf_t ) / sizeof ( mp_obj_t ) ;
687+ sp -= MP_OBJ_ITER_BUF_NSLOTS ;
688688 }
689689 DISPATCH_WITH_PEND_EXC_CHECK ();
690690 }
@@ -729,19 +729,20 @@ unwind_jump:;
729729 SET_TOP (mp_getiter (TOP (), NULL ));
730730 DISPATCH ();
731731
732- // An iterator for a for-loop takes 4 slots on the stack. They are either
733- // used to store the iterator object itself, or the first slot is NULL and
732+ // An iterator for a for-loop takes MP_OBJ_ITER_BUF_NSLOTS slots on
733+ // the Python value stack. These slots are either used to store the
734+ // iterator object itself, or the first slot is MP_OBJ_NULL and
734735 // the second slot holds a reference to the iterator object.
735736 ENTRY (MP_BC_GET_ITER_STACK ): {
736737 MARK_EXC_IP_SELECTIVE ();
737738 mp_obj_t obj = TOP ();
738739 mp_obj_iter_buf_t * iter_buf = (mp_obj_iter_buf_t * )sp ;
739- sp += sizeof ( mp_obj_iter_buf_t ) / sizeof ( mp_obj_t ) - 1 ;
740+ sp += MP_OBJ_ITER_BUF_NSLOTS - 1 ;
740741 obj = mp_getiter (obj , iter_buf );
741742 if (obj != MP_OBJ_FROM_PTR (iter_buf )) {
742743 // Iterator didn't use the stack so indicate that with MP_OBJ_NULL.
743- sp [-3 ] = MP_OBJ_NULL ;
744- sp [-2 ] = obj ;
744+ sp [- MP_OBJ_ITER_BUF_NSLOTS + 1 ] = MP_OBJ_NULL ;
745+ sp [- MP_OBJ_ITER_BUF_NSLOTS + 2 ] = obj ;
745746 }
746747 DISPATCH ();
747748 }
@@ -751,14 +752,14 @@ unwind_jump:;
751752 DECODE_ULABEL ; // the jump offset if iteration finishes; for labels are always forward
752753 code_state -> sp = sp ;
753754 mp_obj_t obj ;
754- if (sp [-3 ] == MP_OBJ_NULL ) {
755- obj = sp [-2 ];
755+ if (sp [- MP_OBJ_ITER_BUF_NSLOTS + 1 ] == MP_OBJ_NULL ) {
756+ obj = sp [- MP_OBJ_ITER_BUF_NSLOTS + 2 ];
756757 } else {
757- obj = MP_OBJ_FROM_PTR (& sp [-3 ]);
758+ obj = MP_OBJ_FROM_PTR (& sp [- MP_OBJ_ITER_BUF_NSLOTS + 1 ]);
758759 }
759760 mp_obj_t value = mp_iternext_allow_raise (obj );
760761 if (value == MP_OBJ_STOP_ITERATION ) {
761- sp -= 4 ; // pop the exhausted iterator
762+ sp -= MP_OBJ_ITER_BUF_NSLOTS ; // pop the exhausted iterator
762763 ip += ulab ; // jump to after for-block
763764 } else {
764765 PUSH (value ); // push the next iteration value
@@ -1334,7 +1335,7 @@ unwind_jump:;
13341335 const byte * ip = code_state -> ip + 1 ;
13351336 DECODE_ULABEL ; // the jump offset if iteration finishes; for labels are always forward
13361337 code_state -> ip = ip + ulab ; // jump to after for-block
1337- code_state -> sp -= 4 ; // pop the exhausted iterator
1338+ code_state -> sp -= MP_OBJ_ITER_BUF_NSLOTS ; // pop the exhausted iterator
13381339 goto outer_dispatch_loop ; // continue with dispatch loop
13391340 } else if (* code_state -> ip == MP_BC_YIELD_FROM ) {
13401341 // StopIteration inside yield from call means return a value of
0 commit comments