I am working on a CPython library that serializes Python objects to disk in
a custom format. I'm using _PyLong_NumBits() to determine whether
PyLong_AsLong(), PyLong_AsUnsignedLong(), PyLong_AsLongLong(), or
PyLong_AsUnsignedLongLong() should be used.

In Python 3.x, I'm able to determine how many bits are required to write an
int to disk without issue. However, in Python 2.7, _PyLong_NumBits()
segfaults when the type is a PyInt that has the value of 0xffffffff
(maximum unsigned 32-bit value). Additionally, _PyLong_NumBits() is not
accurate when the number is negative. My guess is that I can't use
_PyLong_NumBits() on a PyInt object. So, what is the correct way to
determine the number of bits required to represent a PyInt object in Python
2.7?

I'm using Python 2.7.6, x86-64 on Ubuntu.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to