PEP 757: PyLong_Export() can fail (#4025)

gmpy2: mpz_set_PyLong() now returns -1 on error.
This commit is contained in:
Victor Stinner 2024-10-15 14:14:30 +02:00 committed by GitHub
parent 68413fa107
commit acf58098a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 5 deletions

View File

@ -147,9 +147,6 @@ Export API
On success, set *\*export_long* and return 0.
On error, set an exception and return -1.
This function always succeeds if *obj* is a Python :class:`int` object or a
subclass.
If *export_long->digits* is not ``NULL``, :c:func:`PyLong_FreeExport` must be
called when the export is no longer needed.
@ -264,12 +261,15 @@ Export: :c:func:`PyLong_Export()` with gmpy2
Code::
static void
static int
mpz_set_PyLong(mpz_t z, PyObject *obj)
{
static PyLongExport long_export;
PyLong_Export(obj, &long_export);
if (PyLong_Export(obj, &long_export) < 0) {
return -1;
}
if (long_export.digits) {
mpz_import(z, long_export.ndigits, int_digits_order, int_digit_size,
int_endianness, int_nails, long_export.digits);
@ -295,6 +295,7 @@ Code::
}
}
}
return 0;
}
Reference code: `mpz_set_PyLong() in the gmpy2 master for commit 9177648