From bf6f2d4d233c8a48fc25188c9c038041ac89518e Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 3 Dec 2024 17:22:07 +0300 Subject: [PATCH] PEP 757: address gpshead's review (#4144) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- peps/pep-0757.rst | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/peps/pep-0757.rst b/peps/pep-0757.rst index 2c5820e0f..6b72ae358 100644 --- a/peps/pep-0757.rst +++ b/peps/pep-0757.rst @@ -79,7 +79,7 @@ functions. - ``1`` for most significant digit first - ``-1`` for least significant digit first - .. c:member:: int8_t endianness + .. c:member:: int8_t digit_endianness Digit endianness: @@ -177,19 +177,20 @@ create a Python :class:`int` object from a digits array. Create a :c:type:`PyLongWriter`. - On success, set *\*digits* and return a writer. + On success, allocate *\*digits* and return a writer. On error, set an exception and return ``NULL``. *negative* is ``1`` if the number is negative, or ``0`` otherwise. - *ndigits* is the number of digits in the *digits* array. It must be - greater than or equal to 0. + *ndigits* is the number of digits in the *digits* array. It must be + greater than 0. - The caller can either initialize the array of digits *digits* and then call - :c:func:`PyLongWriter_Finish` to get a Python :class:`int`, or call + The caller can either initialize the array of digits *digits* and then + either call :c:func:`PyLongWriter_Finish` to get a Python :class:`int` or :c:func:`PyLongWriter_Discard` to destroy the writer instance. Digits must - be in the range [``0``; ``(1 << sys.int_info.bits_per_digit) - 1``]. Unused - digits must be set to ``0``. + be in the range [``0``; ``(1 << bits_per_digit) - 1``] (where the + :c:struct:`~PyLongLayout.bits_per_digit` is the number of bits per digit). + The unused most-significant digits must be set to ``0``. On CPython 3.14, the :c:func:`PyLongWriter_Create` implementation is a thin @@ -206,11 +207,15 @@ wrapper to the private :c:func:`!_PyLong_New()` function. The function takes care of normalizing the digits and converts the object to a compact integer if needed. + The writer instance is invalid after the call. + .. c:function:: void PyLongWriter_Discard(PyLongWriter *writer) Discard a :c:type:`PyLongWriter` created by :c:func:`PyLongWriter_Create`. + The writer instance is invalid after the call. + Optimize import for small integers ================================== @@ -252,7 +257,7 @@ Code:: int int_digits_order = layout->digits_order; size_t int_bits_per_digit = layout->bits_per_digit; size_t int_nails = int_digit_size*8 - int_bits_per_digit; - int int_endianness = layout->endianness; + int int_endianness = layout->digit_endianness; Export: :c:func:`PyLong_Export()` with gmpy2