-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
[C API] Add PyLong_FromInt64() and PyLong_ToInt64() #120389
Comments
This conflicts with the interface of other There are some design questions:
See also #117031. |
We can use
They must fail with ValueError (or OverflowError).
Raise a OverflowError.
New API should follow new guidelines: 0 on success, -1 on error: https://devguide.python.org/developer-workflow/c-api/index.html#guidelines-for-expanding-changing-the-public-api |
bikeshedding: We have |
I was going to suggest the same. Or include
Then we will end with two sets of functions with the same signature, but opposite meaning of the returned value. I am going to propose to make |
I renamed the functions to |
Add new functions to convert C <stdint.h> numbers from/to Python int: * PyLong_FromInt32() * PyLong_FromUInt32() * PyLong_FromInt64() * PyLong_FromUInt64() * PyLong_ToInt32() * PyLong_ToUInt32() * PyLong_ToInt64() * PyLong_ToUInt64()
Add new functions to convert C <stdint.h> numbers from/to Python int: * PyLong_FromInt32() * PyLong_FromUInt32() * PyLong_FromInt64() * PyLong_FromUInt64() * PyLong_ToInt32() * PyLong_ToUInt32() * PyLong_ToInt64() * PyLong_ToUInt64()
You can now check #120390 implementation, especially the test suite, to get answers to your questions. |
I created capi-workgroup/decisions#32 "Add PyLong_FromInt64() and PyLong_ToInt64()" in the C API WG Decisions project. |
Add new functions to convert C <stdint.h> numbers from/to Python int: * PyLong_FromInt32() * PyLong_FromUInt32() * PyLong_FromInt64() * PyLong_FromUInt64() * PyLong_AsInt32() * PyLong_AsUInt32() * PyLong_AsInt64() * PyLong_AsUInt64()
Feature or enhancement
I propose to add functions to convert <stdint.h> integers to/from Python int objects:
Notes:
UInt
toUint
since there are two words: Unsigned INTeger.To
functions don't return the result, but a status: 0 on success, -1 on error (with an exception set). It's to solve the C API Problem #1: "Ambiguous return values". PyLong_AsLong() returns -1 on success and on error (with an exception set).Related discussion: Avoid C-specific Types.
Linked PRs
The text was updated successfully, but these errors were encountered: