Skip to content

Commit e295d86

Browse files
authored
pythonGH-101291: Avoid using macros with casts in low-level long API. (python#104742)
1 parent 151b6bf commit e295d86

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Include/cpython/longintrepr.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ _PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
104104
#define _PyLong_SIGN_MASK 3
105105
#define _PyLong_NON_SIZE_BITS 3
106106

107+
107108
static inline int
108109
_PyLong_IsCompact(const PyLongObject* op) {
109-
assert(PyLong_Check(op));
110+
assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
110111
return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
111112
}
112113

@@ -115,7 +116,7 @@ _PyLong_IsCompact(const PyLongObject* op) {
115116
static inline Py_ssize_t
116117
_PyLong_CompactValue(const PyLongObject *op)
117118
{
118-
assert(PyLong_Check(op));
119+
assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
119120
assert(PyUnstable_Long_IsCompact(op));
120121
Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
121122
return sign * (Py_ssize_t)op->long_value.ob_digit[0];

0 commit comments

Comments
 (0)