Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we access PY_SSIZE_T_MAX value from python?

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

like image 268
vaab Avatar asked Mar 14 '17 04:03

vaab


1 Answers

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

like image 119
Anthony Sottile Avatar answered Nov 14 '22 05:11

Anthony Sottile