mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Bug 1003935: xrange overflows
Added XXX comment about why the undocumented PyRange_New() API function is too broken to be worth the considerable pain of repairing. Changed range_new() to stop using PyRange_New(). This fixes a variety of bogus errors. Nothing in the core uses PyRange_New() now. Documented that xrange() is intended to be simple and fast, and that CPython restricts its arguments, and length of its result sequence, to native C longs. Added some tests that failed before the patch, and repaired a test that relied on a bogus OverflowError getting raised.
This commit is contained in:
parent
d976ab7caf
commit
feec4533e2
3 changed files with 37 additions and 11 deletions
|
@ -48,10 +48,15 @@ class XrangeTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, xrange, 0, "spam")
|
||||
self.assertRaises(TypeError, xrange, 0, 42, "spam")
|
||||
|
||||
self.assertRaises(OverflowError, xrange, 0, sys.maxint, sys.maxint-1)
|
||||
self.assertEqual(len(xrange(0, sys.maxint, sys.maxint-1)), 2)
|
||||
|
||||
self.assertRaises(OverflowError, xrange, -sys.maxint, sys.maxint)
|
||||
self.assertRaises(OverflowError, xrange, 0, 2*sys.maxint)
|
||||
|
||||
self.assertEqual(len(xrange(-sys.maxint, sys.maxint, 2)),
|
||||
sys.maxint)
|
||||
self.assertRaises(OverflowError, xrange, -sys.maxint-1, sys.maxint, 2)
|
||||
|
||||
def test_main():
|
||||
test.test_support.run_unittest(XrangeTest)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue