Reputation: 10122
I'm in python code and need to check some value against PY_SSIZE_T_MAX
(defined in the C-API of python).
Can I access to PY_SSIZE_T_MAX
value directly ?
If not, is there a way to infer it thanks to python's behavior ?
Or could I safely deduce it from sizeof(ctypes.c_ssize_t)
(I'm thinking at the value: 2**(8 * sizeof(c_ssize_t) - 1)
)?
Upvotes: 6
Views: 1234
Reputation: 70107
You're looking for sys.maxsize
Here's the source which sets it: https://github.com/python/cpython/blob/9e52c907b5511393ab7e44321e9521fe0967e34d/Python/sysmodule.c#L1985-L1986
More information: https://docs.python.org/3/library/sys.html#sys.maxsize
Upvotes: 10