简体   繁体   中英

Dealing with uint64_t length conversion to Py_ssize_t

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 ?

您可以将sys.maxsizePy_ssize_t可以取的最大值进行比较(取自此答案

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM