Commit 6a922372 authored by Thomas Wouters's avatar Thomas Wouters

_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.
parent 15d4929a
...@@ -500,8 +500,8 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky) ...@@ -500,8 +500,8 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky)
int sizediff; int sizediff;
v = (PyTupleObject *) *pv; v = (PyTupleObject *) *pv;
if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1 || if (v == NULL || !PyTuple_Check(v) || last_is_sticky ||
last_is_sticky) { (v->ob_size != 0 && v->ob_refcnt != 1)) {
*pv = 0; *pv = 0;
Py_XDECREF(v); Py_XDECREF(v);
PyErr_BadInternalCall(); PyErr_BadInternalCall();
...@@ -511,6 +511,15 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky) ...@@ -511,6 +511,15 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky)
if (sizediff == 0) if (sizediff == 0)
return 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 */ /* XXX UNREF/NEWREF interface should be more symmetrical */
#ifdef Py_REF_DEBUG #ifdef Py_REF_DEBUG
--_Py_RefTotal; --_Py_RefTotal;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment