[Python-Dev] Re: [snake-farm] test test_slice failed -- [9, 7, 5, 3, 1] == [0] (original) (raw)

Michael Hudson mwh@python.net
06 Nov 2002 13:56:54 +0000


Neal Norwitz <neal@metaslash.com> writes:

On Wed, Nov 06, 2002 at 11:04:57AM +0000, Michael Hudson wrote: > > So you suggest changing PySliceGetIndicesEx(), right?

Yes. But based on Guido's comments and some thinking, I don't think the API should change to longs. Your solution below make sense, but didn't work.

Nuts.

> I think the better idea is to call PyEvalSliceIndex for the step > element of the slice too. And maybe change the latter from > > else if (x < -INTMAX)_ _> x = 0; > > to > > else if (x < -INTMAX)_ _> x = -INTMAX; > > Can you test this on a 64 bit platform or shall I just check it in?

Tested on SF compile farm (ssh to compile.sf.net), they have a very fast Alpha. Here's the trimmed down diff: Index: Python/ceval.c (in PyEvalSliceIndex) @@ -3507,7 +3507,7 @@ else if (x < -INTMAX)_ _- x = 0;_ _+ x = -INTMAX;_ _*pi = x;_ _Index: Objects/sliceobject.c_ _@@ -119,7 +119,7 @@_ _if (r->step == PyNone) { *step = 1; } else { - *step = PyIntAsLong(r->step); + if (!PyEvalSliceIndex(r->step, step)) return -1; if (*step == -1 && PyErrOccurred()) { return -1; But this didn't produce the correct results: >>> range(10)[::sys.maxint-1] []

Wierd. Shall dig.

Nice how you get warnings from the system header files on that alpha isn't it?

...

Works for me!

mwh@usf-cf-alpha-linux-1:~/python$ ./python Python 2.3a0 (#2, Nov 6 2002, 05:44:13) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

range(10)[::sys.maxint - 2] Traceback (most recent call last): File "", line 1, in ? NameError: name 'sys' is not defined import sys range(10)[::sys.maxint - 2] [0]

Try again? Can you try playing with gdb to see what's going on?

Cheers, M.

-- -Dr. Olin Shivers, Ph.D., Cranberry-Melon School of Cucumber Science -- seen in comp.lang.scheme