[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-16 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Thanks, Antoine.  I'll investigate.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-16 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Looks like Benjamin already fixed the refleak in r76319, r76320.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-15 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

The fix was applied to py3k in r76292, but I bodged the commit and 
committed some extra (non-working) code by mistake.  That was removed in 
r76293, so all should be well now.

Merged to release31-maint in r76294.

trunk and the 2.6 maintenance branch also need some (but not all) of these 
fixes backporting.

--
versions: +Python 2.6, Python 2.7 -Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-15 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Backported the tests and some of the fixes to 2.x in r76295 (trunk) and 
r76296 (release26-maint).

2.x seems to have been producing correct results in all cases on my 
machine.  The only problem on 2.x was that the code depended on signed 
arithmetic wrapping modulo 2**width (undefined behaviour!  very bad!);  
now it only depends on unsigned - signed conversions wrapping modulo 
2**width, which still isn't guaranteed by the C standards, but it's 
merely implementation-defined behaviour rather than undefined behaviour, 
and all implementations that I'm aware of do this.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Not sure whether it's related, but there is now a sizeable refleak:

test_range
beginning 6 repetitions
123456
..
test_range leaked [150, 150, 150] references, sum=450

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-14 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

It looks like the PyLong version of reverse is broken too:

 list(range(10**100, 10**100-2, -2))
[1
]
 list(reversed(range(10**100, 10**100-2, -2)))
[9
998]

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-14 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

I've updated to patch to improve the tests, and fix the problems with the 
PyLong version of range.__reversed__.  (Also updated on Rietveld.)

--
Added file: http://bugs.python.org/file15329/issue7298_v2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-13 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Thanks for reviewing, Eric.  I'll work a bit more on the tests.

I'm also not sure what to do about 2.x:  here reversed(xrange(start, 
stop, step)) has some of the same problems for large numbers. (E.g., if 
step == LONG_MIN.)

The options are: (1) have reversed(x) raise ValueError for some extreme 
xrange instances x, or (2) rework the internals so that reversed(x) 
always works.

Given that this is a bugfix, I'm inclined to go for (1) for now;  we can 
always look at reworking xrange later on, for 2.7 and 3.2.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-13 Thread Eric Smith

Eric Smith e...@trueblade.com added the comment:

For 2.x, I'd just raise an exception. No one is going to be using a step
of LONG_MIN.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-11 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

and here's a patch (includes the earlier tests).

--
Added file: http://bugs.python.org/file15310/issue7298.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-11 Thread Mark Dickinson

Changes by Mark Dickinson dicki...@gmail.com:


--
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-11 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

I've uploaded this patch to Rietveld to make it easier to review:

http://codereview.appspot.com/154060/show

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-11 Thread Eric Smith

Eric Smith e...@trueblade.com added the comment:

I reviewed the issue on Rietveld, and it looks fine to me with the
exception of my comment about the tests. The comment is mostly a nit, so
if you don't agree don't worry about it.

I tested it with and without pydebug and the tests pass.

I think this should be committed and backported.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread ledave123

New submission from ledave123 ledave...@yahoo.fr:

On python 2.4.4, reversed(range()) is correct :
 list(reversed(range(12,-1,-1)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

However, on python 3.1.1 :
 list(reversed(range(12,-1,-1)))
[]
which is obviously wrong.

When step is positive, the result is okay on python 3.1.1 :
 list(reversed(range(13)))
[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

--
components: Interpreter Core
messages: 95104
nosy: ledave123
severity: normal
status: open
title: reversed(range(x, -1, -1)) is empty when x  1
type: behavior
versions: Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Nice catch!  Thanks for reporting this.

get_len_of_range in Objects/rangeobject.c only works for positive steps,
but is being called with a negative step here.

I think get_len_of_range should be changed to work with both positive
and negative steps.  It's only called from one other place, and that
place also has to deal with negative steps.  (And I'm not convinced that
this place is dealing with negative steps correctly either:  it uses
simply -step to negate the step, which can overflow if step == LONG_MIN.)

I'll put a patch together.

--
assignee:  - mark.dickinson
keywords: +easy
nosy: +mark.dickinson
priority:  - critical
versions: +Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

There's another problem with range_reverse:  it uses a short range (all
fields longs) if start, stop and step fit into a C long.  But it doesn't
check whether the length fits into a C long.  This leads to the following:

 list(reversed(range(-1, 2**63-1)))
[]

(this is on a 64-bit machine;  for a 32-bit machine the same failure
should occur with 2**31-1 in place of 2**63-1).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Further investigations show that range_iter has the same problem.  :-(

 for x in range(-1, 2**63-1): print(x)
...
(no output)

This really needs to be fixed.  Upgrading to release blocker, and
removing the easy flag.

--
keywords:  -easy
priority: critical - release blocker

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread Eric Smith

Changes by Eric Smith e...@trueblade.com:


--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7298] reversed(range(x, -1, -1)) is empty when x 1

2009-11-10 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Here are some tests.

--
keywords: +patch
stage:  - needs patch
Added file: http://bugs.python.org/file15306/issue7298_test.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com