处理uint64_t长度转换为Py_ssize_t

时间:2022-12-27 04:15:23

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

我正在阅读二进制数据格式,其中包含使用cython的unsigned long long类型的长度字段。

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

读取此值后,我将其转换为Py_ssize_t变量以返回到用于索引的python空间。

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

由于Py_ssize_t是有符号的,因此它的最大正范围必须低于无符号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?

是否有一般检查我读取的值是否可以存储在Py_ssize_t中?或者换一种说法:有没有办法获得Py_ssize_t的最大正值?

1 个解决方案

#1


1  

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

您可以与sys.maxsize进行比较,这是Py_ssize_t可以采用的最大值(取自此答案)

#1


1  

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

您可以与sys.maxsize进行比较,这是Py_ssize_t可以采用的最大值(取自此答案)