Michael Hudson wrote: > David Hopwood <[EMAIL PROTECTED]> writes: > >> Armin Rigo wrote: >>> Hi, >>> >>> There is an oversight in the design of __index__() that only just >>> surfaced :-( It is responsible for the following behavior, on a 32-bit >>> machine with >= 2GB of RAM: >>> >>> >>> s = 'x' * (2**100) # works! >>> >>> len(s) >>> 2147483647 >>> >>> This is because PySequence_Repeat(v, w) works by applying w.__index__ in >>> order to call v->sq_repeat. However, __index__ is defined to clip the >>> result to fit in a Py_ssize_t. >> Clipping the result sounds like it would *never* be a good idea. What was >> the rationale for that? It should throw an exception. > > Why would you expect range(10)[:2**32-1] and range(10)[:2**32] to do > different things?
In that case, I believe it is the slice object that should be suppressing the overflow error (via PyErr_Occurred and PyErr_Matches) when calculating the indices for a given length, rather than having silent clipping be part of the basic implementation of long.__index__(). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com