]> granicus.if.org Git - python/commitdiff
Fix bad bug in structseq slicing (NULL pointers in result). Reported by
authorTim Peters <tim.peters@gmail.com>
Tue, 30 Oct 2001 23:20:46 +0000 (23:20 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 30 Oct 2001 23:20:46 +0000 (23:20 +0000)
Jack Jansen on python-dev.
Add simple test case.
Move vereq() from test_descr to test_support (it's handy!).

Lib/test/test_descr.py
Lib/test/test_structseq.py [new file with mode: 0644]
Lib/test/test_support.py
Objects/structseq.c

index 4fd11a5c0cfe59530dc30629a9c92b6fcca9aa56..ca09ca97e80720799f35c152edde8961ff5ed958 100644 (file)
@@ -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 (file)
index 0000000..33d3313
--- /dev/null
@@ -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
index bbae1be5fff09cbe477931daa40142d548897b0b..83bde3ee9f91c8caf9de87311f1cd69bf1366cd1 100644 (file)
@@ -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()
index 50448c24dd7b407a891add414908b191897f285d..7ad607b0e39da0ecc9758c8287ef41424ef6064a 100644 (file)
@@ -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;
 }