How can we access PY_SSIZE_T_MAX value from python?
Asked Answered
J

1

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

Janeljanela answered 14/3, 2017 at 4:23 Comment(0)
I
10

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

Impartible answered 14/3, 2017 at 4:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.