0

I am reading a binary data format which contains a length field of type unsigned long long using cython.

After reading this value, I cast it to a Py_ssize_t variable to return to python space to be used in indexing.

Since Py_ssize_t is signed, it's maximum positive range must be lower than the maximum value unsigned long long.

Is there a general way of checking if the value I read can be stored in Py_ssize_t? Or put differently: Is there a way to obtain the maximum positive value of Py_ssize_t?

ARF
  • 7,420
  • 8
  • 45
  • 72

1 Answers1

1

You can compare to sys.maxsize which is the maximum value Py_ssize_t can take (taken from this answer)

Community
  • 1
  • 1
DavidW
  • 29,336
  • 6
  • 55
  • 86