[Python-checkins] CVS: python/dist/src/Python compile.c,2.162,2.163

Jeremy Hylton jhylton@users.sourceforge.net
Mon, 12 Feb 2001 08:01:06 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv9526

Modified Files:
	compile.c 
Log Message:
In symtable_update_free_vars() do not modify the dictionary while
iterating over it using PyDict_Next().

This bug fix brought to you by the letters b, c, d, g, h, ... and the
reporter Ping.


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.162
retrieving revision 2.163
diff -C2 -r2.162 -r2.163
*** compile.c	2001/02/09 22:55:26	2.162
--- compile.c	2001/02/12 16:01:03	2.163
***************
*** 4206,4211 ****
  symtable_update_free_vars(struct symtable *st)
  {
! 	PyObject *o, *name;
! 	int i, def;
  	PySymtableEntryObject *child, *ste = st->st_cur;
  
--- 4206,4211 ----
  symtable_update_free_vars(struct symtable *st)
  {
! 	int i, j, def;
! 	PyObject *o, *name, *list = NULL;
  	PySymtableEntryObject *child, *ste = st->st_cur;
  
***************
*** 4217,4220 ****
--- 4217,4223 ----
  		int pos = 0;
  
+ 		if (list)
+ 			PyList_SetSlice(list, 0, 
+ 					((PyVarObject*)list)->ob_size, 0);
  		child = (PySymtableEntryObject *)\
  			PyList_GET_ITEM(ste->ste_children, i);
***************
*** 4223,4239 ****
  			if (!(is_free(v)))
  				continue; /* avoids indentation */
  			ste->ste_child_free = 1;
  			if (ste->ste_nested) {
  				if (symtable_add_def_o(st, ste->ste_symbols,
! 						       name, def) < 0)
! 						return -1;
  			} else {
  				if (symtable_check_global(st, child->ste_id, 
! 							  name) < 0)
! 						return -1;
  			}
  		}
  	}
! 		
  	return 0;
  }
--- 4226,4259 ----
  			if (!(is_free(v)))
  				continue; /* avoids indentation */
+ 			if (list == NULL) {
+ 				list = PyList_New(0);
+ 				if (list == NULL)
+ 					return -1;
+ 			}
  			ste->ste_child_free = 1;
+ 			if (PyList_Append(list, name) < 0) {
+ 				Py_DECREF(list);
+ 				return -1;
+ 			}
+ 		}
+ 		for (j = 0; list && j < PyList_GET_SIZE(list); j++) {
+ 			name = PyList_GET_ITEM(list, j);
  			if (ste->ste_nested) {
  				if (symtable_add_def_o(st, ste->ste_symbols,
! 						       name, def) < 0) {
! 				    Py_DECREF(list);
! 				    return -1;
! 				}
  			} else {
  				if (symtable_check_global(st, child->ste_id, 
! 							  name) < 0) {
! 				    Py_DECREF(list);
! 				    return -1;
! 				}
  			}
  		}
  	}
! 
! 	Py_XDECREF(list);
  	return 0;
  }