Skip to content

Commit bbf3d03

Browse files
vstinnerestyxx
authored andcommitted
pythongh-120593: Fix const qualifier in _PyLong_CompactValue() (python#121053)
Remove the const qualifier of the argument of functions: * _PyLong_IsCompact() * _PyLong_CompactValue() Py_TYPE() argument is not const. Fix the compiler warning: Include/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’: Include/pyport.h:19:31: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual] (...) Include/cpython/longintrepr.h:133:30: note: in expansion of macro ‘Py_TYPE’ assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
1 parent 76cb488 commit bbf3d03

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Include/cpython/longintrepr.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
119119

120120

121121
static inline int
122-
_PyLong_IsCompact(const PyLongObject* op) {
122+
_PyLong_IsCompact(PyLongObject* op) {
123123
assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
124124
return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
125125
}
126126

127127
#define PyUnstable_Long_IsCompact _PyLong_IsCompact
128128

129129
static inline Py_ssize_t
130-
_PyLong_CompactValue(const PyLongObject *op)
130+
_PyLong_CompactValue(PyLongObject *op)
131131
{
132132
Py_ssize_t sign;
133133
assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));

Include/internal/pycore_long.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ static inline int
240240
_PyLong_CompactSign(const PyLongObject *op)
241241
{
242242
assert(PyLong_Check(op));
243-
assert(_PyLong_IsCompact(op));
243+
assert(_PyLong_IsCompact((PyLongObject *)op));
244244
return 1 - (op->long_value.lv_tag & SIGN_MASK);
245245
}
246246

247247
static inline int
248248
_PyLong_NonCompactSign(const PyLongObject *op)
249249
{
250250
assert(PyLong_Check(op));
251-
assert(!_PyLong_IsCompact(op));
251+
assert(!_PyLong_IsCompact((PyLongObject *)op));
252252
return 1 - (op->long_value.lv_tag & SIGN_MASK);
253253
}
254254

Objects/longobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6672,12 +6672,12 @@ _PyLong_FiniTypes(PyInterpreterState *interp)
66726672

66736673
int
66746674
PyUnstable_Long_IsCompact(const PyLongObject* op) {
6675-
return _PyLong_IsCompact(op);
6675+
return _PyLong_IsCompact((PyLongObject*)op);
66766676
}
66776677

66786678
#undef PyUnstable_Long_CompactValue
66796679

66806680
Py_ssize_t
66816681
PyUnstable_Long_CompactValue(const PyLongObject* op) {
6682-
return _PyLong_CompactValue(op);
6682+
return _PyLong_CompactValue((PyLongObject*)op);
66836683
}

0 commit comments

Comments
 (0)