-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PEP 757: Answer open questions #3980
Conversation
Add "Don't add PyLong_GetNativeLayout() function" to Rejected Ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think difference of PyLong_GetNativeLayout() vs PyLong_GetInfo() is a minor question and we don't need to rush here.
Currently, all required information for :class:`int` import/export is | ||
already available via :c:func:`PyLong_GetInfo()` or | ||
:data:`sys.int_info`. Native endianness of "digits" and current order | ||
of digits (least significant digit first) --- is a common denominator of | ||
all libraries for aribitrary precision integer arithmetic. | ||
|
||
The problem is that this API is for the stable ABI and not only for | ||
CPython, but for any Python implementation. For example, the JVM based | ||
GraalPy uses Java's ``BigDecimal`` for "big" integers, which has | ||
compatible internal representation: 4 bytes per digit, big-endian, most | ||
significant byte is in the zeroth element. | ||
|
||
People relying on CPython implementation details may assume CPython's | ||
:c:struct:`PyLongLayout` without even querying it and will just use the | ||
other APIs. Providing a convenient :c:func:`PyLong_GetNativeLayout` | ||
function is a way to reduce the risk of relying on CPython | ||
implementation details. By the way, the CPython native layout can also | ||
evolve in future Python versions. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, all required information for :class:`int` import/export is | |
already available via :c:func:`PyLong_GetInfo()` or | |
:data:`sys.int_info`. Native endianness of "digits" and current order | |
of digits (least significant digit first) --- is a common denominator of | |
all libraries for aribitrary precision integer arithmetic. | |
The problem is that this API is for the stable ABI and not only for | |
CPython, but for any Python implementation. For example, the JVM based | |
GraalPy uses Java's ``BigDecimal`` for "big" integers, which has | |
compatible internal representation: 4 bytes per digit, big-endian, most | |
significant byte is in the zeroth element. | |
People relying on CPython implementation details may assume CPython's | |
:c:struct:`PyLongLayout` without even querying it and will just use the | |
other APIs. Providing a convenient :c:func:`PyLong_GetNativeLayout` | |
function is a way to reduce the risk of relying on CPython | |
implementation details. By the way, the CPython native layout can also | |
evolve in future Python versions. | |
Currently, most required information for :class:`int` import/export is | |
already available via :c:func:`PyLong_GetInfo()` (and :data:`sys.int_info`). | |
We also can add more (like order of digits), this interface doesn't poses | |
any constraints on future evolution of the :type:`PyLongObject`. | |
The problem is that the :c:func:`PyLong_GetInfo()` returns a Python object, | |
:term:`named tuple`, not a convenient C structure and that might distract | |
people from using it in favor e.g. of current semi-private macros like :c:macro:`!PyLong_SHIFT` and :c:macro:`!PyLong_BASE`. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure if we should rush with this change. But if so, please take look on my edits.
I think the only arguments is: it's easy to use. (BTW, it seems (I did GH search) the PyLong_GetInfo() isn't used outside of CPython.)
I abandon my PR. |
Add "Don't add PyLong_GetNativeLayout() function" to Rejected Ideas.
📚 Documentation preview 📚: https://pep-previews--3980.org.readthedocs.build/