You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide PyLong conversions with Py_(u)intptr_t #110863
Thanks for the propoal.
As we're forming a C-API working group to guide the evolution of the C-API, I'd prefer the proposal to be discussed on Discourse first.
Do we continue to add functions similar to the ones we already have, which are OK but could be improved, or should we switch to a new style now?
These functions have an ambiguous return value: when -1 is returned, the caller needs to check PyErr_Occurred. This is problematic, and against a proposed guideline. Of course, we make an exception in the name of consistency with the existing API -- but a discussion is in order.
We already have PyLong_{From,As}VoidPtr and PyLong_{From,As}[U]IntMax_t, which should be enough in practice. Is there a use case where these won't work? That would be a reason to add the API ASAP.
I'd argue that new API should use intptr_t directly, and the pre-C99 typedefs like Py_intptr_t should be phased out.
Activity
Lincoln-developer commentedon Oct 16, 2023
Hey, I would love to work on this if you don't mind.
pitrou commentedon Oct 16, 2023
@encukou Does this enhancement sound like a good idea? If so, @Lincoln-developer would like to work on it.
Lincoln-developer commentedon Oct 18, 2023
@pitrou , are we waiting for @encukou's response on this then I start working on the issue, just inquiring. Thanks
encukou commentedon Oct 18, 2023
Thanks for the propoal.
As we're forming a C-API working group to guide the evolution of the C-API, I'd prefer the proposal to be discussed on Discourse first.
Do we continue to add functions similar to the ones we already have, which are OK but could be improved, or should we switch to a new style now?
PyErr_Occurred. This is problematic, and against a proposed guideline. Of course, we make an exception in the name of consistency with the existing API -- but a discussion is in order.PyLong_{From,As}VoidPtrandPyLong_{From,As}[U]IntMax_t, which should be enough in practice. Is there a use case where these won't work? That would be a reason to add the API ASAP.intptr_tdirectly, and the pre-C99 typedefs likePy_intptr_tshould be phased out.vstinner commentedon Jan 27, 2025
Somehow related, Python 3.14 adds the following functions:
vstinner commentedon Jan 28, 2025
See also issue gh-62070 for PyLong_FromIntMax_t() and PyLong_FromUintMax_t().
encukou commentedon Jan 28, 2025
Since 3.13 you can use
PyLong_{From,To}NativeByteswithsizeof(intptr_t). Is that enough for your use case?encukou commentedon Feb 4, 2025
If not, please reopen :)