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

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


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

Modified Files:
      Tag: release21-maint
	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.48
retrieving revision 2.48.4.1
diff -C2 -r2.48 -r2.48.4.1
*** tupleobject.c	2001/01/18 00:00:53	2.48
--- tupleobject.c	2001/05/28 13:04:33	2.48.4.1
***************
*** 500,505 ****
  
  	v = (PyTupleObject *) *pv;
! 	if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1 ||
!              last_is_sticky) {
  		*pv = 0;
  		Py_XDECREF(v);
--- 500,505 ----
  
  	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);
***************
*** 510,513 ****
--- 510,522 ----
  	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 */