[Python-checkins] python/dist/src/Modules _heapqmodule.c,1.3,1.4

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Jun 13 11:37:13 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10613

Modified Files:
	_heapqmodule.c 
Log Message:
Fixup error exits in nlargest() and nsmallest().

Index: _heapqmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_heapqmodule.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** _heapqmodule.c	13 Jun 2004 05:26:33 -0000	1.3
--- _heapqmodule.c	13 Jun 2004 15:36:56 -0000	1.4
***************
*** 231,241 ****
  
  	heap = PyList_New(0);
! 	if (it == NULL)
  		goto fail;
  
  	for (i=0 ; i<n ; i++ ){
  		elem = PyIter_Next(it);
! 		if (elem == NULL)
! 			goto sortit;
  		if (PyList_Append(heap, elem) == -1) {
  			Py_DECREF(elem);
--- 231,245 ----
  
  	heap = PyList_New(0);
! 	if (heap == NULL)
  		goto fail;
  
  	for (i=0 ; i<n ; i++ ){
  		elem = PyIter_Next(it);
! 		if (elem == NULL) {
! 			if (PyErr_Occurred())
! 				goto fail;
! 			else
! 				goto sortit;
! 		}
  		if (PyList_Append(heap, elem) == -1) {
  			Py_DECREF(elem);
***************
*** 272,280 ****
  	}
  sortit:
- 	Py_DECREF(it);
  	if (PyList_Sort(heap) == -1)
  		goto fail;
  	if (PyList_Reverse(heap) == -1)
  		goto fail;
  	return heap;
  
--- 276,284 ----
  	}
  sortit:
  	if (PyList_Sort(heap) == -1)
  		goto fail;
  	if (PyList_Reverse(heap) == -1)
  		goto fail;
+ 	Py_DECREF(it);
  	return heap;
  
***************
*** 386,396 ****
  
  	heap = PyList_New(0);
! 	if (it == NULL)
  		goto fail;
  
  	for (i=0 ; i<n ; i++ ){
  		elem = PyIter_Next(it);
! 		if (elem == NULL)
! 			goto sortit;
  		if (PyList_Append(heap, elem) == -1) {
  			Py_DECREF(elem);
--- 390,404 ----
  
  	heap = PyList_New(0);
! 	if (heap == NULL)
  		goto fail;
  
  	for (i=0 ; i<n ; i++ ){
  		elem = PyIter_Next(it);
! 		if (elem == NULL) {
! 			if (PyErr_Occurred())
! 				goto fail;
! 			else
! 				goto sortit;
! 		}
  		if (PyList_Append(heap, elem) == -1) {
  			Py_DECREF(elem);
***************
*** 430,436 ****
  
  sortit:
- 	Py_DECREF(it);
  	if (PyList_Sort(heap) == -1)
  		goto fail;
  	return heap;
  
--- 438,444 ----
  
  sortit:
  	if (PyList_Sort(heap) == -1)
  		goto fail;
+ 	Py_DECREF(it);
  	return heap;
  




More information about the Python-checkins mailing list