@@ -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 , "SIGN_MASK does not match _PyLong_SIGN_MASK" );
134
+ static_assert (NON_SIZE_BITS == _PyLong_NON_SIZE_BITS , "NON_SIZE_BITS does not match _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,11 +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
149
140
150
static inline int
141
151
_PyLong_BothAreCompact (const PyLongObject * a , const PyLongObject * b ) {
@@ -144,21 +154,6 @@ _PyLong_BothAreCompact(const PyLongObject* a, const PyLongObject* b) {
144
154
return (a -> long_value .lv_tag | b -> long_value .lv_tag ) < (2 << NON_SIZE_BITS );
145
155
}
146
156
147
- /* Returns a *compact* value, iff `_PyLong_IsCompact` is true for `op`.
148
- *
149
- * "Compact" values have at least one bit to spare,
150
- * so that addition and subtraction can be performed on the values
151
- * without risk of overflow.
152
- */
153
- static inline Py_ssize_t
154
- _PyLong_CompactValue (const PyLongObject * op )
155
- {
156
- assert (PyLong_Check (op ));
157
- assert (_PyLong_IsCompact (op ));
158
- Py_ssize_t sign = 1 - (op -> long_value .lv_tag & SIGN_MASK );
159
- return sign * (Py_ssize_t )op -> long_value .ob_digit [0 ];
160
- }
161
-
162
157
static inline bool
163
158
_PyLong_IsZero (const PyLongObject * op )
164
159
{
0 commit comments