From 5c58fe2f4a691306c5813dc1fecbe26034869994 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 19 Nov 2024 11:00:45 +0300 Subject: [PATCH] PEP 757: edit rejected ideas (mpz_import/export-like API) (#4126) --- peps/pep-0757.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/peps/pep-0757.rst b/peps/pep-0757.rst index bed1d7915..759bedb26 100644 --- a/peps/pep-0757.rst +++ b/peps/pep-0757.rst @@ -452,11 +452,17 @@ API example:: int PyLong_Export(PyLongObject *obj, PyLongLayout layout, void *buffer); PyLongObject *PyLong_Import(PyLongLayout layout, void *buffer); -This might work for the GMP, as this it has :c:func:`!mpz_limbs_read()` and -:c:func:`!mpz_limbs_write()` functions, that can provide required "buffers". +This might work for the GMP, as it has :c:func:`!mpz_limbs_read()` and +:c:func:`!mpz_limbs_write()` functions, that can provide required access to +internals of :c:struct:`!mpz_t`. Other libraries may require using temporary +bufferes and then mpz_import/export-like functions on their side. The major drawback of this approach is that it's much more complex on the -CPython side (i.e. actual conversion between different layouts). +CPython side (i.e. actual conversion between different layouts). For example, +implementation of the :c:func:`PyLong_FromNativeBytes()` and the +:c:func:`PyLong_AsNativeBytes()` (together provided restricted version of the +required API) in the CPython took ~500 LOC (c.f. ~100 LOC in the current +implementation). Discussions