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:
Tim Peters 2004-08-08 07:17:39 +00:00
parent d976ab7caf
commit feec4533e2
3 changed files with 37 additions and 11 deletions

View file

@ -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)