summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-30 23:20:46 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-30 23:20:46 (GMT)
commitc2fe618575aaf58ddf36d04d96431d6dc819ef31 (patch)
treef083f6119e71555915d02a04de993e97d7d36ffc
parent5ded1bf5c7773b7a13e1907e3cfb4826c402d7b2 (diff)
downloadcpython-c2fe618575aaf58ddf36d04d96431d6dc819ef31.zip
cpython-c2fe618575aaf58ddf36d04d96431d6dc819ef31.tar.gz
cpython-c2fe618575aaf58ddf36d04d96431d6dc819ef31.tar.bz2
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Jack Jansen on python-dev. Add simple test case. Move vereq() from test_descr to test_support (it's handy!).
-rw-r--r--Lib/test/test_descr.py6
-rw-r--r--Lib/test/test_structseq.py16
-rw-r--r--Lib/test/test_support.py4
-rw-r--r--Objects/structseq.c2
4 files changed, 22 insertions, 6 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 4fd11a5..ca09ca9 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1,12 +1,8 @@
# Test enhancements related to descriptors and new-style classes
-from test_support import verify, verbose, TestFailed, TESTFN
+from test_support import verify, vereq, verbose, TestFailed, TESTFN
from copy import deepcopy
-def vereq(a, b):
- if not (a == b):
- raise TestFailed, "%r == %r" % (a, b)
-
def veris(a, b):
if a is not b:
raise TestFailed, "%r is %r" % (a, b)
diff --git a/Lib/test/test_structseq.py b/Lib/test/test_structseq.py
new file mode 100644
index 0000000..33d3313
--- /dev/null
+++ b/Lib/test/test_structseq.py
@@ -0,0 +1,16 @@
+from test_support import vereq
+
+import time
+
+t = time.gmtime()
+astuple = tuple(t)
+vereq(len(t), len(astuple))
+vereq(t, astuple)
+
+# Check that slicing works the same way; at one point, slicing t[i:j] with
+# 0 < i < j could produce NULLs in the result.
+for i in range(-len(t), len(t)):
+ for j in range(-len(t), len(t)):
+ vereq(t[i:j], astuple[i:j])
+
+XXX more needed
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index bbae1be..83bde3e 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -117,6 +117,10 @@ def verify(condition, reason='test failed'):
if not condition:
raise TestFailed(reason)
+def vereq(a, b):
+ if not (a == b):
+ raise TestFailed, "%r == %r" % (a, b)
+
def sortdict(dict):
"Like repr(dict), but in sorted order."
items = dict.items()
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 50448c2..7ad607b 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -75,7 +75,7 @@ structseq_slice(PyStructSequence *obj, int low, int high)
for(i = low; i < high; ++i) {
PyObject *v = obj->ob_item[i];
Py_INCREF(v);
- PyTuple_SET_ITEM(np, i, v);
+ PyTuple_SET_ITEM(np, i-low, v);
}
return (PyObject *) np;
}