[Python-Dev] Type of range object members

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Aug 15 05:58:49 CEST 2006


On Aug 14, 2006, at 10:56 PM, Guido van Rossum wrote:

>
> Because the only way to create one (in 2.5 or before) is by passing it
> a Python int.
>

Is that true?

Python 2.4.2 (#2, Jan 13 2006, 12:00:38)
 >>> xrange(long(2))
xrange(2)


>
> But since the start and end come from a Python int, what advantage
> would it have to use Py_ssize_t instead? We know sizeof(long) <=
> sizeof(Py_ssize_t).

They don't have to come from a python int, they can come from a  
long.    I guess range_new would have to be changed to the 'n'  
conversion code instead of 'l' to do the proper conversion.    
Similarly, rangeiter_next will need to use PyInt_FromSsize_t .


>
> Blame the C standards committee -- they introduced ssize_t in C99.

I've checked in the Wiley's 2003 edition of "The C Standard" and it  
does not have ssize_t .  I could not find anything suggesting that it  
is in the C standard on google either.  Are you sure it is in C99?


>
>> On the second look, I've realized that it is signed
>> and started wondering why not ptrdiff_t.
>
> Because it is not used for the difference of pointers?

After being exposed to C++, ptrdiff_t (or more generally  
difference_type) is what I expect as an argument of a [] operator  
that allows negative indices (such as operator[] of C++ iterators).

>
> Frankly, you're about 6 months too late with naming concerns.

I know :-(  I'll shut up now.



More information about the Python-Dev mailing list