@@ -118,6 +118,21 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
118
118
#define SIGN_NEGATIVE 2
119
119
#define NON_SIZE_BITS 3
120
120
121
+ /* The functions _PyLong_IsCompact and _PyLong_CompactValue are defined
122
+ * in Include/cpython/longobject.h, since they need to be inline.
123
+ *
124
+ * "Compact" values have at least one bit to spare,
125
+ * so that addition and subtraction can be performed on the values
126
+ * without risk of overflow.
127
+ *
128
+ * The inline functions need tag bits.
129
+ * For readability, rather than do `#define SIGN_MASK _PyLong_SIGN_MASK`
130
+ * we define them to the numbers in both places and then assert that
131
+ * they're the same.
132
+ */
133
+ static_assert (SIGN_MASK == _PyLong_SIGN_MASK );
134
+ static_assert (NON_SIZE_BITS == _PyLong_NON_SIZE_BITS );
135
+
121
136
/* All *compact" values are guaranteed to fit into
122
137
* a Py_ssize_t with at least one bit to spare.
123
138
* In other words, for 64 bit machines, compact
@@ -131,13 +146,6 @@ _PyLong_IsNonNegativeCompact(const PyLongObject* op) {
131
146
return op -> long_value .lv_tag <= (1 << NON_SIZE_BITS );
132
147
}
133
148
134
- static inline int
135
- _PyLong_IsCompact (const PyLongObject * op ) {
136
- assert (PyLong_Check (op ));
137
- return op -> long_value .lv_tag < (2 << NON_SIZE_BITS );
138
- }
139
-
140
- #define PyUnstable_Int_IsCompact _PyLong_IsCompact
141
149
142
150
static inline int
143
151
_PyLong_BothAreCompact (const PyLongObject * a , const PyLongObject * b ) {
@@ -146,23 +154,6 @@ _PyLong_BothAreCompact(const PyLongObject* a, const PyLongObject* b) {
146
154
return (a -> long_value .lv_tag | b -> long_value .lv_tag ) < (2 << NON_SIZE_BITS );
147
155
}
148
156
149
- /* Returns a *compact* value, iff `_PyLong_IsCompact` is true for `op`.
150
- *
151
- * "Compact" values have at least one bit to spare,
152
- * so that addition and subtraction can be performed on the values
153
- * without risk of overflow.
154
- */
155
- static inline Py_ssize_t
156
- _PyLong_CompactValue (const PyLongObject * op )
157
- {
158
- assert (PyLong_Check (op ));
159
- assert (_PyLong_IsCompact (op ));
160
- Py_ssize_t sign = 1 - (op -> long_value .lv_tag & SIGN_MASK );
161
- return sign * (Py_ssize_t )op -> long_value .ob_digit [0 ];
162
- }
163
-
164
- #define PyUnstable_Int_CompactValue _PyLong_CompactValue
165
-
166
157
static inline bool
167
158
_PyLong_IsZero (const PyLongObject * op )
168
159
{
0 commit comments