[Python-checkins] CVS: python/dist/src/Objects tupleobject.c,2.49,2.50

Thomas Wouters twouters@users.sourceforge.net
Mon, 28 May 2001 06:11:04 -0700


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

Modified Files:
	tupleobject.c 
Log Message:

_PyTuple_Resize: take into account the empty tuple. There can be only one.
Instead of raising a SystemError, just create a new tuple of the desired
size.

This fixes (at least) SF bug #420343.



Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.49
retrieving revision 2.50
diff -C2 -r2.49 -r2.50
*** tupleobject.c	2001/05/15 20:12:59	2.49
--- tupleobject.c	2001/05/28 13:11:02	2.50
***************
*** 501,506 ****
  
  	v = (PyTupleObject *) *pv;
! 	if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1 ||
!              last_is_sticky) {
  		*pv = 0;
  		Py_XDECREF(v);
--- 501,506 ----
  
  	v = (PyTupleObject *) *pv;
! 	if (v == NULL || !PyTuple_Check(v) || last_is_sticky ||
! 	    (v->ob_size != 0 && v->ob_refcnt != 1)) {
  		*pv = 0;
  		Py_XDECREF(v);
***************
*** 511,514 ****
--- 511,523 ----
  	if (sizediff == 0)
  		return 0;
+ 
+ 	if (v->ob_size == 0) {
+ 		/* Empty tuples are often shared, so we should never 
+ 		   resize them in-place even if we do own the only
+ 		   (current) reference */
+ 		Py_DECREF(v);
+ 		*pv = PyTuple_New(newsize);
+ 		return 0;
+ 	}
  
  	/* XXX UNREF/NEWREF interface should be more symmetrical */