mirror of
https://github.com/python/cpython.git
synced 2025-12-20 15:41:13 +00:00
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!).
This commit is contained in:
parent
5ded1bf5c7
commit
c2fe618575
4 changed files with 22 additions and 6 deletions
|
|
@ -1,12 +1,8 @@
|
||||||
# Test enhancements related to descriptors and new-style classes
|
# 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
|
from copy import deepcopy
|
||||||
|
|
||||||
def vereq(a, b):
|
|
||||||
if not (a == b):
|
|
||||||
raise TestFailed, "%r == %r" % (a, b)
|
|
||||||
|
|
||||||
def veris(a, b):
|
def veris(a, b):
|
||||||
if a is not b:
|
if a is not b:
|
||||||
raise TestFailed, "%r is %r" % (a, b)
|
raise TestFailed, "%r is %r" % (a, b)
|
||||||
|
|
|
||||||
16
Lib/test/test_structseq.py
Normal file
16
Lib/test/test_structseq.py
Normal file
|
|
@ -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
|
||||||
|
|
@ -117,6 +117,10 @@ def verify(condition, reason='test failed'):
|
||||||
if not condition:
|
if not condition:
|
||||||
raise TestFailed(reason)
|
raise TestFailed(reason)
|
||||||
|
|
||||||
|
def vereq(a, b):
|
||||||
|
if not (a == b):
|
||||||
|
raise TestFailed, "%r == %r" % (a, b)
|
||||||
|
|
||||||
def sortdict(dict):
|
def sortdict(dict):
|
||||||
"Like repr(dict), but in sorted order."
|
"Like repr(dict), but in sorted order."
|
||||||
items = dict.items()
|
items = dict.items()
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ structseq_slice(PyStructSequence *obj, int low, int high)
|
||||||
for(i = low; i < high; ++i) {
|
for(i = low; i < high; ++i) {
|
||||||
PyObject *v = obj->ob_item[i];
|
PyObject *v = obj->ob_item[i];
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
PyTuple_SET_ITEM(np, i, v);
|
PyTuple_SET_ITEM(np, i-low, v);
|
||||||
}
|
}
|
||||||
return (PyObject *) np;
|
return (PyObject *) np;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue