[Python-checkins] python/dist/src/Objects listobject.c,2.165,2.166

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Fri Nov 28 16:43:04 EST 2003


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

Modified Files:
	listobject.c 
Log Message:
Make sure the list.sort's decorate step unwinds itself before returning
an exception raised by the key function.
(Suggested by Michael Hudson.)



Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.165
retrieving revision 2.166
diff -C2 -d -r2.165 -r2.166
*** listobject.c	8 Nov 2003 11:58:44 -0000	2.165
--- listobject.c	28 Nov 2003 21:43:02 -0000	2.166
***************
*** 1877,1882 ****
  			key = PyObject_CallFunctionObjArgs(keyfunc, value, 
  							   NULL);
! 			if (key == NULL)
  				goto dsu_fail;
  			kvpair = build_sortwrapper(key, value);
  			if (kvpair == NULL)
--- 1877,1889 ----
  			key = PyObject_CallFunctionObjArgs(keyfunc, value, 
  							   NULL);
! 			if (key == NULL) {
! 				for (i=i-1 ; i>=0 ; i--) {
! 					kvpair = PyList_GET_ITEM(self, i);
! 					value = sortwrapper_getvalue(kvpair);
! 					PyList_SET_ITEM(self, i, value);
! 					Py_DECREF(kvpair);
! 				}
  				goto dsu_fail;
+ 			}
  			kvpair = build_sortwrapper(key, value);
  			if (kvpair == NULL)
***************
*** 1886,1890 ****
  	}
  
! 	/* Reverse sort stability achieved by initialially reversing the list,
  	applying a stable forward sort, then reversing the final result. */
  	if (reverse && self->ob_size > 1)
--- 1893,1897 ----
  	}
  
! 	/* Reverse sort stability achieved by initially reversing the list,
  	applying a stable forward sort, then reversing the final result. */
  	if (reverse && self->ob_size > 1)





More information about the Python-checkins mailing list