summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-08-08 07:17:39 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-08-08 07:17:39 (GMT)
commitfeec4533e21a612e9a5b665c27b1a3eb84e04bb3 (patch)
treee721c83b44443f2cbda66a7acab7ddd4cd30a9d6 /Lib
parentd976ab7caf098eecf44173bbce8101f13ce79d86 (diff)
downloadcpython-feec4533e21a612e9a5b665c27b1a3eb84e04bb3.zip
cpython-feec4533e21a612e9a5b665c27b1a3eb84e04bb3.tar.gz
cpython-feec4533e21a612e9a5b665c27b1a3eb84e04bb3.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xrange.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_xrange.py b/Lib/test/test_xrange.py
index ce5284d..f33373e 100644
--- a/Lib/test/test_xrange.py
+++ b/Lib/test/test_xrange.py
@@ -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)