diff options
author | Thomas Wouters <thomas@python.org> | 2001-05-28 13:04:33 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2001-05-28 13:04:33 (GMT) |
commit | fbed5be9e13144f80a30b90dbd670131fdaba51e (patch) | |
tree | c0d0e8c5534d2f60d187a421a3974a993a736ceb | |
parent | d9289f0c0b9421878cf020bc0fb5c7205d70db0b (diff) | |
download | cpython-fbed5be9e13144f80a30b90dbd670131fdaba51e.zip cpython-fbed5be9e13144f80a30b90dbd670131fdaba51e.tar.gz cpython-fbed5be9e13144f80a30b90dbd670131fdaba51e.tar.bz2 |
_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.
-rw-r--r-- | Objects/tupleobject.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index d40f947..461b325 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -499,8 +499,8 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky) int sizediff; v = (PyTupleObject *) *pv; - if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1 || - last_is_sticky) { + if (v == NULL || !PyTuple_Check(v) || last_is_sticky || + (v->ob_size != 0 && v->ob_refcnt != 1)) { *pv = 0; Py_XDECREF(v); PyErr_BadInternalCall(); @@ -510,6 +510,15 @@ _PyTuple_Resize(PyObject **pv, int newsize, int last_is_sticky) 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 */ #ifdef Py_REF_DEBUG --_Py_RefTotal; |