[Python-checkins] python/dist/src/Python compile.c,2.282,2.283

loewis@users.sourceforge.net loewis@users.sourceforge.net
Sat, 03 May 2003 03:53:11 -0700


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

Modified Files:
	compile.c 
Log Message:
Patch #708604: Check more function results. Will backport to 2.2.


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.282
retrieving revision 2.283
diff -C2 -d -r2.282 -r2.283
*** compile.c	29 Apr 2003 17:07:34 -0000	2.282
--- compile.c	3 May 2003 10:53:08 -0000	2.283
***************
*** 4619,4632 ****
  				PyList_SET_ITEM(list, 0, v);
  				Py_INCREF(v);
! 			} else
! 				PyList_Insert(list, 0, v);
  		}
  	}
! 	if (list == NULL || PyList_GET_SIZE(list) == 0)
! 		return 0;
  	/* There are cellvars that are also arguments.  Create a dict
  	   to replace cellvars and put the args at the front.
  	*/
  	d = PyDict_New();
  	for (i = PyList_GET_SIZE(list); --i >= 0; ) {
  		v = PyInt_FromLong(i);
--- 4619,4639 ----
  				PyList_SET_ITEM(list, 0, v);
  				Py_INCREF(v);
! 			} else {
! 				if (PyList_Insert(list, 0, v) < 0) {
! 					Py_DECREF(list);
! 					return -1;
! 				}
! 			}
  		}
  	}
! 	if (list == NULL)	/* There used to be a check here for the size of */
! 		return 0;		/* the list being 0, which would have leaked the */
! 						/* list if that condition was ever possible. JRH */
  	/* There are cellvars that are also arguments.  Create a dict
  	   to replace cellvars and put the args at the front.
  	*/
  	d = PyDict_New();
+ 	if (d == NULL)
+ 		return -1;
  	for (i = PyList_GET_SIZE(list); --i >= 0; ) {
  		v = PyInt_FromLong(i);
***************
*** 4644,4647 ****
--- 4651,4656 ----
  	while (PyDict_Next(*cellvars, &pos, &v, &w)) {
  		w = PyInt_FromLong(i++);  /* don't care about the old key */
+ 		if (w == NULL)
+ 			goto fail;
  		if (PyDict_SetItem(d, v, w) < 0) {
  			Py_DECREF(w);
***************
*** 4794,4797 ****
--- 4803,4808 ----
  	for (i = 0; i < si.si_nlocals; ++i) {
  		v = PyInt_FromLong(i);
+ 		if (v == NULL)
+ 			goto fail;
  		if (PyDict_SetItem(c->c_locals, 
  				   PyList_GET_ITEM(varnames, i), v) < 0)
***************
*** 4866,4869 ****
--- 4877,4882 ----
   				if (st->st_nscopes != 1) {
   					v = PyInt_FromLong(flags);
+ 					if (v == NULL)
+ 						goto fail;
   					if (PyDict_SetItem(st->st_global, 
   							   name, v)) 
***************
*** 4902,4905 ****
--- 4915,4919 ----
  
  	st->st_filename = NULL;
+ 	st->st_symbols = NULL;
  	if ((st->st_stack = PyList_New(0)) == NULL)
  		goto fail;
***************
*** 4954,4959 ****
  
  		if (list)
! 			PyList_SetSlice(list, 0, 
! 					((PyVarObject*)list)->ob_size, 0);
  		child = (PySymtableEntryObject *)
  			PyList_GET_ITEM(ste->ste_children, i);
--- 4968,4979 ----
  
  		if (list)
! 			if (PyList_SetSlice(list, 0, 
! 					((PyVarObject*)list)->ob_size, 0) < 0)
! 				return -1;
! 			/* Yes, the above call CAN fail, even though it's reducing
! 			   the size of the list.  The current implementation will
! 			   allocate temp memory equal to the size of the list: this
! 			   is avoidable in this specific case, but probably not
! 			   worth the effort of special-casing it. - JRH */
  		child = (PySymtableEntryObject *)
  			PyList_GET_ITEM(ste->ste_children, i);
***************
*** 5105,5109 ****
  		prev = st->st_cur;
  		if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
! 			Py_DECREF(st->st_cur);
  			st->st_errors++;
  			return;
--- 5125,5131 ----
  		prev = st->st_cur;
  		if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
! 			/* Py_DECREF(st->st_cur); */
! 			/* I believe the previous line would lead to a
! 			   double-DECREF when st is disposed - JRH */
  			st->st_errors++;
  			return;
***************
*** 5112,5115 ****
--- 5134,5141 ----
  	st->st_cur = (PySymtableEntryObject *)
  		PySymtableEntry_New(st, name, type, lineno);
+ 	if (st->st_cur == NULL) {
+ 		st->st_errors++;
+ 		return;
+ 	}
  	if (strcmp(name, TOP) == 0)
  		st->st_global = st->st_cur->ste_symbols;
***************
*** 5188,5191 ****
--- 5214,5219 ----
  	    val = flag;
  	o = PyInt_FromLong(val);
+ 	if (o == NULL)
+ 		return -1;
  	if (PyDict_SetItem(dict, name, o) < 0) {
  		Py_DECREF(o);
***************
*** 5206,5209 ****
--- 5234,5239 ----
  			val = flag;
  		o = PyInt_FromLong(val);
+ 		if (o == NULL)
+ 			return -1;
  		if (PyDict_SetItem(st->st_global, name, o) < 0) {
  			Py_DECREF(o);