summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-11 19:48:03 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-11 19:48:03 (GMT)
commit7b07a41e9f078065b966a2414a24c0e5b7889ef7 (patch)
tree60d61099c526136f5b3674857ef0fb3651d3be22
parentf0b0f680fe2c8fb4af1c563c57efea29bec1bff6 (diff)
downloadcpython-7b07a41e9f078065b966a2414a24c0e5b7889ef7.zip
cpython-7b07a41e9f078065b966a2414a24c0e5b7889ef7.tar.gz
cpython-7b07a41e9f078065b966a2414a24c0e5b7889ef7.tar.bz2
The endless 460020 bug.
Disable t[:], t*0, t*1 optimizations when t is of a tuple subclass type.
-rw-r--r--Lib/test/test_descr.py9
-rw-r--r--Objects/tupleobject.c15
2 files changed, 18 insertions, 6 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 7095f0b..5c4db30 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1417,9 +1417,18 @@ def inherits():
a = madtuple((1,2,3,4,5))
verify(tuple(a) == (1,2,3,4,5))
verify(tuple(a).__class__ is tuple)
+ verify(a[:].__class__ is tuple)
+ verify((a * 1).__class__ is tuple)
+ verify((a * 0).__class__ is tuple)
+ verify((a + ()).__class__ is tuple)
a = madtuple(())
verify(tuple(a) == ())
verify(tuple(a).__class__ is tuple)
+ verify((a + a).__class__ is tuple)
+ verify((a * 0).__class__ is tuple)
+ verify((a * 1).__class__ is tuple)
+ verify((a * 2).__class__ is tuple)
+ verify(a[:].__class__ is tuple)
class madstring(str):
_rev = None
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index b07eb74..f371e1e 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -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)