[Python-checkins] r73549 - in python/branches/release30-maint: Lib/test/test_builtin.py Misc/NEWS Objects/rangeobject.c
mark.dickinson
python-checkins at python.org
Wed Jun 24 21:22:42 CEST 2009
Author: mark.dickinson
Date: Wed Jun 24 21:22:42 2009
New Revision: 73549
Log:
Merged revisions 73547-73548 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r73547 | mark.dickinson | 2009-06-24 19:36:46 +0100 (Wed, 24 Jun 2009) | 1 line
Issue #6334: Fix buggy internal length calculation in builtin range function
........
r73548 | mark.dickinson | 2009-06-24 20:01:32 +0100 (Wed, 24 Jun 2009) | 1 line
Misc/NEWS entry for r73547
........
Modified:
python/branches/release30-maint/ (props changed)
python/branches/release30-maint/Lib/test/test_builtin.py
python/branches/release30-maint/Misc/NEWS
python/branches/release30-maint/Objects/rangeobject.c
Modified: python/branches/release30-maint/Lib/test/test_builtin.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_builtin.py (original)
+++ python/branches/release30-maint/Lib/test/test_builtin.py Wed Jun 24 21:22:42 2009
@@ -924,6 +924,24 @@
self.assertEqual(list(range(1, 10, 3)), [1, 4, 7])
#self.assertEqual(list(range(5, -5, -3)), [5, 2, -1, -4])
+ #issue 6334: the internal stored range length was being
+ #computed incorrectly in some cases involving large arguments.
+ x = range(10**20, 10**20+10, 3)
+ self.assertEqual(len(x), 4)
+ self.assertEqual(len(list(x)), 4)
+
+ x = range(10**20+10, 10**20, 3)
+ self.assertEqual(len(x), 0)
+ self.assertEqual(len(list(x)), 0)
+
+ x = range(10**20, 10**20+10, -3)
+ self.assertEqual(len(x), 0)
+ self.assertEqual(len(list(x)), 0)
+
+ x = range(10**20+10, 10**20, -3)
+ self.assertEqual(len(x), 4)
+ self.assertEqual(len(list(x)), 4)
+
""" XXX(nnorwitz):
# Now test range() with longs
self.assertEqual(list(range(-2**100)), [])
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Wed Jun 24 21:22:42 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #6334: Fix bug in range length calculation for ranges with
+ large arguments.
+
- Fixed SystemError triggered by "range([], 1, -1)".
- Issue #5924: On Windows, a large PYTHONPATH environment variable
Modified: python/branches/release30-maint/Objects/rangeobject.c
==============================================================================
--- python/branches/release30-maint/Objects/rangeobject.c (original)
+++ python/branches/release30-maint/Objects/rangeobject.c Wed Jun 24 21:22:42 2009
@@ -581,7 +581,6 @@
{
rangeobject *r = (rangeobject *)seq;
longrangeiterobject *it;
- PyObject *tmp, *len;
long lstart, lstop, lstep;
assert(PyRange_Check(seq));
@@ -612,15 +611,9 @@
it->len = it->index = NULL;
- /* Calculate length: (r->stop - r->start) / r->step */
- tmp = PyNumber_Subtract(r->stop, r->start);
- if (!tmp)
+ it->len = range_length_obj(r);
+ if (!it->len)
goto create_failure;
- len = PyNumber_FloorDivide(tmp, r->step);
- Py_DECREF(tmp);
- if (!len)
- goto create_failure;
- it->len = len;
it->index = PyLong_FromLong(0);
if (!it->index)
goto create_failure;
More information about the Python-checkins
mailing list