Skip to content

Commit acf5809

Browse files
authored
PEP 757: PyLong_Export() can fail (#4025)
gmpy2: mpz_set_PyLong() now returns -1 on error.
1 parent 68413fa commit acf5809

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

peps/pep-0757.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ Export API
147147
On success, set *\*export_long* and return 0.
148148
On error, set an exception and return -1.
149149
150-
This function always succeeds if *obj* is a Python :class:`int` object or a
151-
subclass.
152-
153150
If *export_long->digits* is not ``NULL``, :c:func:`PyLong_FreeExport` must be
154151
called when the export is no longer needed.
155152
@@ -264,12 +261,15 @@ Export: :c:func:`PyLong_Export()` with gmpy2
264261
265262
Code::
266263
267-
static void
264+
static int
268265
mpz_set_PyLong(mpz_t z, PyObject *obj)
269266
{
270267
static PyLongExport long_export;
271268
272-
PyLong_Export(obj, &long_export);
269+
if (PyLong_Export(obj, &long_export) < 0) {
270+
return -1;
271+
}
272+
273273
if (long_export.digits) {
274274
mpz_import(z, long_export.ndigits, int_digits_order, int_digit_size,
275275
int_endianness, int_nails, long_export.digits);
@@ -295,6 +295,7 @@ Code::
295295
}
296296
}
297297
}
298+
return 0;
298299
}
299300
300301
Reference code: `mpz_set_PyLong() in the gmpy2 master for commit 9177648

0 commit comments

Comments
 (0)