Closed
Description
Feature or enhancement
In Python 3.13 alpha1, I removed the private _PyLong_NumBits() function. It seems like this function is used by pywin32 and MariaDB projects: see issue gh-119336.
I propose to add a public function to replace it:
Py_ssize_t _PyLong_GetNumBits(PyObject *obj);
- Return the number of bits on success: greater than or equal to zero.
- Set an exception and return
-1
on error. - Set an
OverflowError
exception, and return-1
if the number of bits doesn't fit intoPy_ssize_t
.
The C function is similar to the Python int.bit_length()
method.
See also the proposed PyLong_GetSign() function.