@@ -731,6 +731,7 @@ static void symtable_global(struct symtable *, node *);
731731static void symtable_import (struct symtable * , node * );
732732static void symtable_assign (struct symtable * , node * , int );
733733static void symtable_list_comprehension (struct symtable * , node * );
734+ static void symtable_list_for (struct symtable * , node * );
734735
735736static int symtable_update_free_vars (struct symtable * );
736737static int symtable_undo_free (struct symtable * , PyObject * , PyObject * );
@@ -1602,6 +1603,8 @@ com_list_comprehension(struct compiling *c, node *n)
16021603{
16031604 /* listmaker: test list_for */
16041605 char tmpname [30 ];
1606+
1607+ REQ (n , listmaker );
16051608 PyOS_snprintf (tmpname , sizeof (tmpname ), "_[%d]" , ++ c -> c_tmpname );
16061609 com_addoparg (c , BUILD_LIST , 0 );
16071610 com_addbyte (c , DUP_TOP ); /* leave the result on the stack */
@@ -4921,7 +4924,6 @@ symtable_init()
49214924 st -> st_cur = NULL ;
49224925 st -> st_nscopes = 0 ;
49234926 st -> st_errors = 0 ;
4924- st -> st_tmpname = 0 ;
49254927 st -> st_private = NULL ;
49264928 return st ;
49274929 fail :
@@ -5123,9 +5125,6 @@ symtable_enter_scope(struct symtable *st, char *name, int type,
51235125 if (st -> st_cur ) {
51245126 prev = st -> st_cur ;
51255127 if (PyList_Append (st -> st_stack , (PyObject * )st -> st_cur ) < 0 ) {
5126- /* Py_DECREF(st->st_cur); */
5127- /* I believe the previous line would lead to a
5128- double-DECREF when st is disposed - JRH */
51295128 st -> st_errors ++ ;
51305129 return ;
51315130 }
@@ -5395,12 +5394,12 @@ symtable_node(struct symtable *st, node *n)
53955394 }
53965395 goto loop ;
53975396 case list_iter :
5397+ /* only occurs when there are multiple for loops
5398+ in a list comprehension */
53985399 n = CHILD (n , 0 );
5399- if (TYPE (n ) == list_for ) {
5400- st -> st_tmpname ++ ;
5401- symtable_list_comprehension (st , n );
5402- st -> st_tmpname -- ;
5403- } else {
5400+ if (TYPE (n ) == list_for )
5401+ symtable_list_for (st , n );
5402+ else {
54045403 REQ (n , list_if );
54055404 symtable_node (st , CHILD (n , 1 ));
54065405 if (NCH (n ) == 3 ) {
@@ -5428,10 +5427,7 @@ symtable_node(struct symtable *st, node *n)
54285427 /* fall through */
54295428 case listmaker :
54305429 if (NCH (n ) > 1 && TYPE (CHILD (n , 1 )) == list_for ) {
5431- st -> st_tmpname ++ ;
5432- symtable_list_comprehension (st , CHILD (n , 1 ));
5433- symtable_node (st , CHILD (n , 0 ));
5434- st -> st_tmpname -- ;
5430+ symtable_list_comprehension (st , n );
54355431 break ;
54365432 }
54375433 /* fall through */
@@ -5629,10 +5625,23 @@ symtable_global(struct symtable *st, node *n)
56295625static void
56305626symtable_list_comprehension (struct symtable * st , node * n )
56315627{
5628+ /* listmaker: test list_for */
56325629 char tmpname [30 ];
56335630
5634- PyOS_snprintf (tmpname , sizeof (tmpname ), "_[%d]" , st -> st_tmpname );
5631+ REQ (n , listmaker );
5632+ PyOS_snprintf (tmpname , sizeof (tmpname ), "_[%d]" ,
5633+ ++ st -> st_cur -> ste_tmpname );
56355634 symtable_add_def (st , tmpname , DEF_LOCAL );
5635+ symtable_list_for (st , CHILD (n , 1 ));
5636+ symtable_node (st , CHILD (n , 0 ));
5637+ -- st -> st_cur -> ste_tmpname ;
5638+ }
5639+
5640+ static void
5641+ symtable_list_for (struct symtable * st , node * n )
5642+ {
5643+ REQ (n , list_for );
5644+ /* list_for: for v in expr [list_iter] */
56365645 symtable_assign (st , CHILD (n , 1 ), 0 );
56375646 symtable_node (st , CHILD (n , 3 ));
56385647 if (NCH (n ) == 5 )
0 commit comments