| #ifndef Py_LIMITED_API |
| #ifndef Py_LONGINTREPR_H |
| #define Py_LONGINTREPR_H |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
|
|
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #if PYLONG_BITS_IN_DIGIT == 30 |
| typedef uint32_t digit; |
| typedef int32_t sdigit; |
| typedef uint64_t twodigits; |
| typedef int64_t stwodigits; |
| #define PyLong_SHIFT 30 |
| #define _PyLong_DECIMAL_SHIFT 9 |
| #define _PyLong_DECIMAL_BASE ((digit)1000000000) |
| #elif PYLONG_BITS_IN_DIGIT == 15 |
| typedef unsigned short digit; |
| typedef short sdigit; |
| typedef unsigned long twodigits; |
| typedef long stwodigits; |
| #define PyLong_SHIFT 15 |
| #define _PyLong_DECIMAL_SHIFT 4 |
| #define _PyLong_DECIMAL_BASE ((digit)10000) |
| #else |
| #error "PYLONG_BITS_IN_DIGIT should be 15 or 30" |
| #endif |
| #define PyLong_BASE ((digit)1 << PyLong_SHIFT) |
| #define PyLong_MASK ((digit)(PyLong_BASE - 1)) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| typedef struct _PyLongValue { |
| uintptr_t lv_tag; |
| digit ob_digit[1]; |
| } _PyLongValue; |
|
|
| struct _longobject { |
| PyObject_HEAD |
| _PyLongValue long_value; |
| }; |
|
|
| Py_DEPRECATED(3.14) PyAPI_FUNC(PyLongObject*) _PyLong_New(Py_ssize_t); |
|
|
| |
| PyAPI_FUNC(PyObject*) _PyLong_Copy(PyLongObject *src); |
|
|
| Py_DEPRECATED(3.14) PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits( |
| int negative, |
| Py_ssize_t digit_count, |
| digit *digits); |
|
|
|
|
| |
| |
|
|
| #define _PyLong_SIGN_MASK 3 |
| #define _PyLong_NON_SIZE_BITS 3 |
|
|
|
|
| static inline int |
| _PyLong_IsCompact(const PyLongObject* op) { |
| assert(PyType_HasFeature(op->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS)); |
| return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS); |
| } |
|
|
| #define PyUnstable_Long_IsCompact _PyLong_IsCompact |
|
|
| static inline Py_ssize_t |
| _PyLong_CompactValue(const PyLongObject *op) |
| { |
| Py_ssize_t sign; |
| assert(PyType_HasFeature(op->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS)); |
| assert(PyUnstable_Long_IsCompact(op)); |
| sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK); |
| return sign * (Py_ssize_t)op->long_value.ob_digit[0]; |
| } |
|
|
| #define PyUnstable_Long_CompactValue _PyLong_CompactValue |
|
|
|
|
| |
|
|
| 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; |
| |
| Py_uintptr_t _reserved; |
| } PyLongExport; |
|
|
| PyAPI_FUNC(int) PyLong_Export( |
| PyObject *obj, |
| PyLongExport *export_long); |
| PyAPI_FUNC(void) PyLong_FreeExport( |
| PyLongExport *export_long); |
|
|
|
|
| |
|
|
| 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 |
| #endif |
| #endif |
|
|