Currently, PyMemberDef supports fields for all standard C integer types -- from char to long long, signed and unsigned. But some structures in external C API (e.g in ioctl and fcntl calls) are defined in terms of integer types having specified widths (like int32_t) or C or Posix types (like size_t, off_t or pid_t). We could define Py_T_INT32, Py_T_SIZE, Py_T_OFF, etc as aliases of existing constants Py_T_INT, Py_T_LONG, etc, but it is a repetition of complex preprocessor code for each integer type. @encukou proposed to encode the size and the signedness directly in the type code and add a macro Py_T_INTEGER(type) to generate a type code for arbitrary integer type.
It can be defined as:
#define Py_T_INTEGER(type) ((sizeof(type) << 8) | (_Py_IS_TYPE_SIGNED(type) ? 1 : 2))
Discussion: python/cpython#117031
Implementation: python/cpython#132550
Vote:
Currently,
PyMemberDefsupports fields for all standard C integer types -- from char to long long, signed and unsigned. But some structures in external C API (e.g inioctlandfcntlcalls) are defined in terms of integer types having specified widths (likeint32_t) or C or Posix types (likesize_t,off_torpid_t). We could define Py_T_INT32, Py_T_SIZE, Py_T_OFF, etc as aliases of existing constants Py_T_INT, Py_T_LONG, etc, but it is a repetition of complex preprocessor code for each integer type. @encukou proposed to encode the size and the signedness directly in the type code and add a macroPy_T_INTEGER(type)to generate a type code for arbitrary integer type.It can be defined as:
Discussion: python/cpython#117031
Implementation: python/cpython#132550
Vote: