Issue 27848: C function calls: use Py_ssize_t rather than C int for number of arguments (original) (raw)
I recently added new functions to call functions in C, especially _PyObject_FastCallDict(). I started with the C int type for the number of positional arguments: "int nargs".
But slowly, when I started to patch code to use _PyObject_FastCallDict(), I used more and more Py_ssize_t variables for the number of arguments, variable downcasted to int to call _PyObject_FastCallDict().
It is similar to the old issue #18295.
I propose to avoid any risk of integer overflow by using Py_ssize_t everywhere. It might produce more efficient machine code, since "i++" may require extra code to handle overflow when the int rather is used. But I'm not sure that Py_ssize_t is better, especially when -fwrapv option of the GCC compiler is used.
Attached patch implements this idea.
The patch also uses Py_ssize_t for some BUILD_xxx opcodes like BUILD_LIST_UNPACK. The change is not directly related. I wrote it in the hope that machine code could be more efficient, and avoid having to ask myself if types could overflow or not.