]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053)
authorVictor Stinner <vstinner@python.org>
Wed, 26 Jun 2024 18:11:21 +0000 (20:11 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2024 18:11:21 +0000 (20:11 +0200)
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));

Include/cpython/longintrepr.h
Include/internal/pycore_long.h
Objects/longobject.c

index 66623780ca93e01f532c69856f59b98a286749cf..d841c043f37fc4926619fe81cffffd6aa7d457ce 100644 (file)
@@ -119,7 +119,7 @@ PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
 
 
 static inline int
-_PyLong_IsCompact(const PyLongObject* op) {
+_PyLong_IsCompact(PyLongObject* op) {
     assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
     return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
 }
@@ -127,7 +127,7 @@ _PyLong_IsCompact(const PyLongObject* op) {
 #define PyUnstable_Long_IsCompact _PyLong_IsCompact
 
 static inline Py_ssize_t
-_PyLong_CompactValue(const PyLongObject *op)
+_PyLong_CompactValue(PyLongObject *op)
 {
     Py_ssize_t sign;
     assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
index 8513695c22e703eb6138b2111d5d5b32a8629396..2bf6ff459ddc961ec2624198473e12b20f567a5f 100644 (file)
@@ -240,7 +240,7 @@ static inline int
 _PyLong_CompactSign(const PyLongObject *op)
 {
     assert(PyLong_Check(op));
-    assert(_PyLong_IsCompact(op));
+    assert(_PyLong_IsCompact((PyLongObject *)op));
     return 1 - (op->long_value.lv_tag & SIGN_MASK);
 }
 
@@ -248,7 +248,7 @@ static inline int
 _PyLong_NonCompactSign(const PyLongObject *op)
 {
     assert(PyLong_Check(op));
-    assert(!_PyLong_IsCompact(op));
+    assert(!_PyLong_IsCompact((PyLongObject *)op));
     return 1 - (op->long_value.lv_tag & SIGN_MASK);
 }
 
index a3a59a20f0bb97781c56971b3d3b604636c72dc0..86afec9a414134153831392ce28f68cd318bd587 100644 (file)
@@ -6672,12 +6672,12 @@ _PyLong_FiniTypes(PyInterpreterState *interp)
 
 int
 PyUnstable_Long_IsCompact(const PyLongObject* op) {
-    return _PyLong_IsCompact(op);
+    return _PyLong_IsCompact((PyLongObject*)op);
 }
 
 #undef PyUnstable_Long_CompactValue
 
 Py_ssize_t
 PyUnstable_Long_CompactValue(const PyLongObject* op) {
-    return _PyLong_CompactValue(op);
+    return _PyLong_CompactValue((PyLongObject*)op);
 }