-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PyLong_GetNumBits() function #28
Comments
Actually, if the number has more than |
Right for 64-bit platforms (most common platforms). But on 32-bit platforms, the OverflowError "only" requires a single number of 273 MiB which is quick to create. Well, IMO Python is not designed to manage such "big integers", so we should not bother much about it. My first proposition was |
I propose to return |
In updating to Python 3.13 in PyO3 I replaced |
pywin32 uses _PyLong_Sign() and _PyLong_NumBits() to decide how to encode a Python int to Windows COM ABI: https://github.com/mhammond/pywin32/blob/ad5779b23b42653c9fa5dfbb18dd2a8fe5691d0d/com/win32com/src/oleargs.cpp#L139-L209. IMO _PyLong_NumBits() remains relevant even with panda3d uses |
Seems to me like pywin32 could use |
What is the C API Working Group call on this API? Should we add it, or should we guide 3rd party C extensions towards See also #31: "Add public function PyLong_GetDigits()". |
I'd say guide them toward |
Ok, let's do that. I close the issue. |
In Python 3.13 alpha 1, I removed the private
_PyLong_NumBits()
function, but it's used by 3 big/popular projects: pywin32, MariaDB and panda3d.I propose adding a public function to replace this private API:
-1
on error.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. On overflow, it's recommended to call theint.bit_length()
method which is not limited toPy_ssize_t
.In the meanwhile, the private
_PyLong_NumBits()
function was restored in the 3.13 and main branches.See also the proposed PyLong_GetSign() function.
The text was updated successfully, but these errors were encountered: