[Python-Dev] ssize_t branch merged (original) (raw)

Tim Peters tim.peters at gmail.com
Sat Feb 18 04:37:21 CET 2006


[Travis Oliphant]

Maybe I have the wrong version of code. In my pyport.h (checked out from svn trunk) I have.

#define PYSSIZETMAX ((Pyssizet)(((sizet)-1)>>1)) What is sizet?

size_t is an unsigned integral type defined by, required by, and used all over the place in standard C. What exactly is the compiler message you get, and exactly which compiler are you using (note that nobody else is having problems with this, so there's something unique in your setup)?

Is this supposed to be sizeof(sizet)?

No. (size_t)-1 casts -1 to the unsigned integral type size_t, which creates a "solid string of 1 bits" with the width of the size_t type. ">> 1" then shifts that right one bit, clearing the sign bit but leaving the rest of the integer "all 1s". Then that's cast to type Py_ssize_t, which is a signed integral type with the same width as the standard size_t. In the end, you get the largest positive signed integer with the same width as size_t, and that's the intent.

I get a syntax error when I actually use PYSSIZETMAX somewhere in the code.

Nobody else does (PY_SSIZE_T_MAX is referenced in a few places already), so you need to give more information.

Is it simply that you neglected to include Python.h in some extension module? The definition of size_t must be (according to the C standard) supplied by stdlib.h, and Python.h includes stdlib.h.

It's also possible the some core Python C code doesn't #include enough stuff to get the platform's size_t definition.



More information about the Python-Dev mailing list