@@ -79,16 +79,53 @@ typedef long stwodigits; /* signed variant of twodigits */
79
79
aware that ints abuse ob_size's sign bit.
80
80
*/
81
81
82
- struct _longobject {
83
- PyObject_VAR_HEAD
82
+ typedef struct _PyLongValue {
83
+ uintptr_t lv_tag ; /* Number of digits, sign and flags */
84
84
digit ob_digit [1 ];
85
+ } _PyLongValue ;
86
+
87
+ struct _longobject {
88
+ PyObject_HEAD
89
+ _PyLongValue long_value ;
85
90
};
86
91
87
92
PyAPI_FUNC (PyLongObject * ) _PyLong_New (Py_ssize_t );
88
93
89
94
/* Return a copy of src. */
90
95
PyAPI_FUNC (PyObject * ) _PyLong_Copy (PyLongObject * src );
91
96
97
+ PyAPI_FUNC (PyLongObject * )
98
+ _PyLong_FromDigits (int negative , Py_ssize_t digit_count , digit * digits );
99
+
100
+
101
+ /* Inline some internals for speed. These should be in pycore_long.h
102
+ * if user code didn't need them inlined. */
103
+
104
+ #define _PyLong_SIGN_MASK 3
105
+ #define _PyLong_NON_SIZE_BITS 3
106
+
107
+
108
+ static inline int
109
+ _PyLong_IsCompact (const PyLongObject * op ) {
110
+ assert (PyType_HasFeature ((op )-> ob_base .ob_type , Py_TPFLAGS_LONG_SUBCLASS ));
111
+ return op -> long_value .lv_tag < (2 << _PyLong_NON_SIZE_BITS );
112
+ }
113
+
114
+ #define PyUnstable_Long_IsCompact _PyLong_IsCompact
115
+
116
+ static inline Py_ssize_t
117
+ _PyLong_CompactValue (const PyLongObject * op )
118
+ {
119
+ Py_ssize_t sign ;
120
+ assert (PyType_HasFeature ((op )-> ob_base .ob_type , Py_TPFLAGS_LONG_SUBCLASS ));
121
+ assert (PyUnstable_Long_IsCompact (op ));
122
+ sign = 1 - (op -> long_value .lv_tag & _PyLong_SIGN_MASK );
123
+ return sign * (Py_ssize_t )op -> long_value .ob_digit [0 ];
124
+ }
125
+
126
+ #define PyUnstable_Long_CompactValue _PyLong_CompactValue
127
+
128
+
92
129
#ifdef __cplusplus
93
130
}
94
131
#endif
0 commit comments