-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyatomic_gcc.h with GCC discards const qualifier #120593
Comments
For the record, this is not the only place where const qualifiers are lost. If you compile cpython with // pyatomic_gcc.h
static inline void *
_Py_atomic_load_ptr_relaxed(const void *obj)
-{ return (void *)__atomic_load_n((void **)obj, __ATOMIC_RELAXED); }
+{ return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_RELAXED); } As you can see you lose constness twice, namely when calling // pyatomic_std.h
static inline void *
_Py_atomic_load_ptr_relaxed(const void *obj)
{
_Py_USING_STD;
return atomic_load_explicit((const _Atomic(void*)*)obj,
memory_order_relaxed);
} As you can see, the cast here is essentially using a EDIT: I edited my comment in order to reflect the real signature of |
Yes, I'd like to clarify that this is specifically not about compiling CPython, it's about including Python.h only. |
Yes, I understood that from the other issue but since you only mentioned 2 lines, I wanted to 1) give a way to fix it 2) say that it's not just 2 lines that are affected but a lot of calls. |
Remove the 'const' qualifier of the argument of functions: * _Py_atomic_load_ptr() * _Py_atomic_load_ptr_relaxed() * _Py_atomic_load_ptr_acquire()
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));
(cherry picked from commit 9cd2dcb) Co-authored-by: Victor Stinner <vstinner@python.org>
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));
Check the usage of the 'const' qualifier in the Python C API in test_cext.
Check the usage of the 'const' qualifier in the Python C API in test_cext.
…n#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));
Check the usage of the 'const' qualifier in the Python C API in test_cext.
…n#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));
Check the usage of the 'const' qualifier in the Python C API in test_cext.
I don't think weakening the type of calls that should be |
…n#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));
Check the usage of the 'const' qualifier in the Python C API in test_cext.
Change _PyLong_IsCompact() and _PyLong_CompactValue() parameter type from 'PyObject*' to 'const PyObject*'. Avoid the Py_TYPE() macro which does not support const parameter.
If you're talking about _PyLong_CompactValue(): I wrote PR gh-122367 to restore the const modifier. If you're talking about something else, please elaborate which function/code you are referring to. |
Change _PyLong_IsCompact() and _PyLong_CompactValue() parameter type from 'PyObject*' to 'const PyObject*'. Avoid the Py_TYPE() macro which does not support const parameter.
Bug report
Bug description:
Hi,
including Python.h with gcc and -Wcast-qual raises the following issue (Regression from 3.12):
This is a follow-up to #120293
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: