diff options
author | Victor Stinner <vstinner@python.org> | 2024-12-13 13:24:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-13 13:24:48 (GMT) |
commit | 6446408d426814bf2bc9d3911a91741f04d4bc4e (patch) | |
tree | 2da74eda8cbf6b90d3fefe09378374d1c1b354bc /Include | |
parent | d05a4e6a0d366b854a3103cae0c941811fd48c4c (diff) | |
download | cpython-6446408d426814bf2bc9d3911a91741f04d4bc4e.zip cpython-6446408d426814bf2bc9d3911a91741f04d4bc4e.tar.gz cpython-6446408d426814bf2bc9d3911a91741f04d4bc4e.tar.bz2 |
gh-102471, PEP 757: Add PyLong import and export API (#121339)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/longintrepr.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Include/cpython/longintrepr.h b/Include/cpython/longintrepr.h index c60ccc4..357477b 100644 --- a/Include/cpython/longintrepr.h +++ b/Include/cpython/longintrepr.h @@ -139,6 +139,44 @@ _PyLong_CompactValue(const PyLongObject *op) #define PyUnstable_Long_CompactValue _PyLong_CompactValue +/* --- Import/Export API -------------------------------------------------- */ + +typedef struct PyLongLayout { + uint8_t bits_per_digit; + uint8_t digit_size; + int8_t digits_order; + int8_t digit_endianness; +} PyLongLayout; + +PyAPI_FUNC(const PyLongLayout*) PyLong_GetNativeLayout(void); + +typedef struct PyLongExport { + int64_t value; + uint8_t negative; + Py_ssize_t ndigits; + const void *digits; + // Member used internally, must not be used for other purpose. + Py_uintptr_t _reserved; +} PyLongExport; + +PyAPI_FUNC(int) PyLong_Export( + PyObject *obj, + PyLongExport *export_long); +PyAPI_FUNC(void) PyLong_FreeExport( + PyLongExport *export_long); + + +/* --- PyLongWriter API --------------------------------------------------- */ + +typedef struct PyLongWriter PyLongWriter; + +PyAPI_FUNC(PyLongWriter*) PyLongWriter_Create( + int negative, + Py_ssize_t ndigits, + void **digits); +PyAPI_FUNC(PyObject*) PyLongWriter_Finish(PyLongWriter *writer); +PyAPI_FUNC(void) PyLongWriter_Discard(PyLongWriter *writer); + #ifdef __cplusplus } #endif |