Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
eb36d31b
Commit
eb36d31b
authored
Jun 24, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6334: Fix buggy internal length calculation in builtin range function
parent
eeb575f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+18
-0
Objects/rangeobject.c
Objects/rangeobject.c
+2
-9
No files found.
Lib/test/test_builtin.py
View file @
eb36d31b
...
...
@@ -924,6 +924,24 @@ class BuiltinTest(unittest.TestCase):
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)), [])
...
...
Objects/rangeobject.c
View file @
eb36d31b
...
...
@@ -581,7 +581,6 @@ range_iter(PyObject *seq)
{
rangeobject
*
r
=
(
rangeobject
*
)
seq
;
longrangeiterobject
*
it
;
PyObject
*
tmp
,
*
len
;
long
lstart
,
lstop
,
lstep
;
assert
(
PyRange_Check
(
seq
));
...
...
@@ -612,15 +611,9 @@ range_iter(PyObject *seq)
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment