The endless 460020 bug.

Disable t[:], t*0, t*1 optimizations when t is of a tuple subclass type.
This commit is contained in:
Tim Peters 2001-09-11 19:48:03 +00:00
parent f0b0f680fe
commit 7b07a41e9f
2 changed files with 18 additions and 6 deletions

View file

@ -298,8 +298,7 @@ tupleslice(register PyTupleObject *a, register int ilow, register int ihigh)
ihigh = a->ob_size;
if (ihigh < ilow)
ihigh = ilow;
if (ilow == 0 && ihigh == a->ob_size) {
/* XXX can only do this if tuples are immutable! */
if (ilow == 0 && ihigh == a->ob_size && PyTuple_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
@ -366,10 +365,14 @@ tuplerepeat(PyTupleObject *a, int n)
if (n < 0)
n = 0;
if (a->ob_size == 0 || n == 1) {
/* Since tuples are immutable, we can return a shared
copy in this case */
Py_INCREF(a);
return (PyObject *)a;
if (PyTuple_CheckExact(a)) {
/* Since tuples are immutable, we can return a shared
copy in this case */
Py_INCREF(a);
return (PyObject *)a;
}
if (a->ob_size == 0)
return PyTuple_New(0);
}
size = a->ob_size * n;
if (size/a->ob_size != n)