6

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))?

vaab
  • 9,685
  • 7
  • 55
  • 60

1 Answers1

9

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

anthony sottile
  • 61,815
  • 15
  • 148
  • 207