[Python-Dev] New PEP: Using ssize_t as the index type (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Thu Jan 5 21:41:08 CET 2006


Armin Rigo wrote:

This would do the right thing for <= 2.4, using ints everywhere; and the Python.h version 2.5 would detect the #define and assume it's a 2.5-compatible module, so it would override the #define with the real thing and turn on the ssizet interpretation of the '#' format character.

This would be very similar to the PY_SIZE_T_CLEAN approach, except that it would also help to detect spelling mistakes.

From an implementation point of view, the real challenge is to give PyArg_ParseTuple a different meaning; I do this be #defining it to PyArg_ParseTupleSsize_t (to preserve binary compatibility for the original interpretation of ParseTuple). Putting additional flags arguments in the entire code is also quite hackish.

I still don't like the idea of a magic #define that changes the behavior of '#include <Python.h>', but I admit I don't find any better solution. I suppose I'll just blame C.

More precisely, the printf style of function calling, and varargs functions. ISO C is pretty type safe, but with varargs functions, you lose that completely.

I still hope I can write a C parser some day that does ParseTuple/BuildValue checking.

Regards, Martin



More information about the Python-Dev mailing list