aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Include/cpython/longintrepr.h
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committerDaniil Cherednik <dcherednik@ydb.tech>2024-02-14 14:26:16 +0000
commit31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch)
treec1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Include/cpython/longintrepr.h
parentfe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff)
downloadydb-31f2a419764a8ba77c2a970cfc80056c6cd06756.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Include/cpython/longintrepr.h')
-rw-r--r--contrib/tools/python3/src/Include/cpython/longintrepr.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/contrib/tools/python3/src/Include/cpython/longintrepr.h b/contrib/tools/python3/src/Include/cpython/longintrepr.h
index 6d52427508..692c69ba76 100644
--- a/contrib/tools/python3/src/Include/cpython/longintrepr.h
+++ b/contrib/tools/python3/src/Include/cpython/longintrepr.h
@@ -79,9 +79,14 @@ typedef long stwodigits; /* signed variant of twodigits */
aware that ints abuse ob_size's sign bit.
*/
-struct _longobject {
- PyObject_VAR_HEAD
+typedef struct _PyLongValue {
+ uintptr_t lv_tag; /* Number of digits, sign and flags */
digit ob_digit[1];
+} _PyLongValue;
+
+struct _longobject {
+ PyObject_HEAD
+ _PyLongValue long_value;
};
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
@@ -89,6 +94,37 @@ PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
/* Return a copy of src. */
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
+PyAPI_FUNC(PyLongObject *)
+_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
+
+
+/* Inline some internals for speed. These should be in pycore_long.h
+ * if user code didn't need them inlined. */
+
+#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)
+{
+ assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
+ assert(PyUnstable_Long_IsCompact(op));
+ Py_ssize_t 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
+
+
#ifdef __cplusplus
}
#endif