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

Tim Peters tim.one@home.com
Mon, 28 May 2001 19:51:07 -0400


[Thomas Wouters]
> 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
> ===================================================================
> ...
> + 	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;
> + 	}

Almost, but not quite right:  PyTuple_New() can fail, so the return should
be

    return *pv ? 0 : -1;

instead.  Else the caller will believe a failing call succeeded, and go on
to wreak havoc with the NULL pointer stored into *pv.