[Python-Dev] Type of range object members (original) (raw)
Guido van Rossum guido at python.org
Tue Aug 15 04:56:55 CEST 2006
- Previous message: [Python-Dev] Type of range object members
- Next message: [Python-Dev] Type of range object members
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 8/14/06, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
On Aug 14, 2006, at 7:32 PM, Guido van Rossum wrote: > Methinks that as long as PyIntObject uses long (see intobject.h) > there's no point in changing this to long. I guess you meant "changing this to Pyssizet ".
Yup, sorry.
I don't understand why the type used by PyIntObject is relevant here.
Because the only way to create one (in 2.5 or before) is by passing it a Python int.
Range object's "start" is logically an index, but int object's "obival" is not. Since PyIntObject's is definition is exposed by Python.h, changing the type of obival will probably break a lot of code. This reasoning does not apply to the range object.
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).
Since on most platforms ssizet is the same as long, the choice between the two is just a matter of self-documenting code. Speaking of which, I find it unfortunate that the name Pyssizet was selected for the typedef. I would prefer Pyindext. The first time I saw Pyssizet, I did not notice the double 's' and thought it was an unsigned type.
Blame the C standards committee -- they introduced ssize_t in C99.
On the second look, I've realized that it is signed and started wondering why not ptrdifft.
Because it is not used for the difference of pointers?
Frankly, you're about 6 months too late with naming concerns. It's not going to change now. The PEP has been discussed and the code reviewed ad infinitum. We're only looking for bugs now, and so far the issue you've brought up decidedly falls in the category "non-bug".
I understand that ssizet is defined by POSIX as the return type of functions such as "read" that can return either size or -1 for error. I don't think POSIX mandates sizeof(sizet) == sizeof(ssizet), but I may be wrong. I would agree that ptrdifft, although standard C, is not a very intuitive name, but ssizet is even less clear.
Water under the bridge.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Type of range object members
- Next message: [Python-Dev] Type of range object members
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]