Bug 1969663 - Wcast-qual reported for /usr/include/python3.10/object.h
Summary: Wcast-qual reported for /usr/include/python3.10/object.h
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: python3.10
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Python Maintainers
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-08 21:12 UTC by Lukas Slebodnik
Modified: 2021-06-11 09:55 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-06-11 09:55:09 UTC
Type: Bug


Attachments (Terms of Use)

Description Lukas Slebodnik 2021-06-08 21:12:41 UTC
Description of problem:
I try to build projects with as many warnings enabled as possible.
But the recent update of python broke it

Version-Release number of selected component (if applicable):
sh-5.1# rpm -q python3-devel pkgconf-pkg-config gcc
python3-devel-3.10.0~b2-3.fc35.x86_64
pkgconf-pkg-config-1.7.3-6.fc34.x86_64
gcc-11.1.1-3.fc35.x86_64

How reproducible:
Deterministic

Steps to Reproduce:
1. dnf install -y python3-devel pkgconf-pkg-config gcc
2. printf '#include <Python.h>' > test.c
3. gcc -Wcast-qual -Werror -c test.c `pkg-config --cflags --libs python-3.10`

Actual results:
sh-5.1# gcc -Wcast-qual -Werror -c test.c `pkg-config --cflags --libs python-3.10`
In file included from /usr/include/python3.10/Python.h:78,
                 from test.c:1:
/usr/include/python3.10/object.h: In function ‘_Py_IS_TYPE’:
/usr/include/python3.10/object.h:112:29: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
  112 | #define _PyObject_CAST(op) ((PyObject*)(op))
      |                             ^
/usr/include/python3.10/object.h:137:34: note: in expansion of macro ‘_PyObject_CAST’
  137 | #define Py_TYPE(ob)             (_PyObject_CAST(ob)->ob_type)
      |                                  ^~~~~~~~~~~~~~
/usr/include/python3.10/object.h:144:12: note: in expansion of macro ‘Py_TYPE’
  144 |     return Py_TYPE(ob) == type;
      |            ^~~~~~~
cc1: all warnings being treated as errors

Expected results:

sh-5.1# gcc -Wcast-qual -Werror -c test.c `pkg-config --cflags --libs python-3.10`
sh-5.1# echo $?
0

Additional info:

Comment 1 Lukas Slebodnik 2021-06-08 21:26:47 UTC
Possible solution

sh-5.1$ diff -u /usr/include/python3.10/object.h.orig /usr/include/python3.10/object.h
--- /usr/include/python3.10/object.h.orig       2021-06-08 21:18:10.875000000 +0000
+++ /usr/include/python3.10/object.h    2021-06-08 21:23:20.477000000 +0000
@@ -135,13 +135,14 @@
 
 // bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
 #define Py_TYPE(ob)             (_PyObject_CAST(ob)->ob_type)
+#define Py_TYPE_CONST(ob)       (_PyObject_CAST_CONST(ob)->ob_type)
 
 // bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
 #define Py_SIZE(ob)             (_PyVarObject_CAST(ob)->ob_size)
 
 
 static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
-    return Py_TYPE(ob) == type;
+    return Py_TYPE_CONST(ob) == type;
 }
 #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)

Comment 2 Lukas Slebodnik 2021-06-10 12:33:21 UTC
Bump ^^

Comment 3 Miro Hrončok 2021-06-10 12:53:47 UTC
You've reported this 2 days ago. We have hundreds of Python 3.10 build failures to got rough and this is a warning. I don't think it requires a bump and a needinfo. If you need to move this forward fast, open an upstream issue and a pull request.

Comment 4 Miro Hrončok 2021-06-10 12:57:16 UTC
s/got rough/go trough/

Comment 5 Victor Stinner 2021-06-10 13:24:04 UTC
Alright, I reproduced the issue. I created https://bugs.python.org/issue44378 and https://github.com/python/cpython/pull/26644 to fix the compiler warning.

Comment 6 Lukas Slebodnik 2021-06-10 18:25:22 UTC
(In reply to Victor Stinner from comment #5)
> Alright, I reproduced the issue. I created
> https://bugs.python.org/issue44378 and
> https://github.com/python/cpython/pull/26644 to fix the compiler warning.

Thank you very much for PR. I am glad you were able to reproduce it and prepare fix

Comment 7 Victor Stinner 2021-06-11 09:47:06 UTC
It is now fixed in the 3.10 branch: https://github.com/python/cpython/commit/e6d28a1a6ad22125fc3a6df2d611d79aa8d6f67e

The fix will be part of the next Python 3.10.0 beta3 release, scheduled at: "3.10.0 beta 3: Thursday, 2021-06-17".
https://www.python.org/dev/peps/pep-0619/

Is it worth it to keep this issue open to track it?

Lukas Slebodnik's use case is: "I try to build projects with as many warnings enabled as possible."

Comment 8 Miro Hrončok 2021-06-11 09:55:09 UTC
We'll update to beta 3 as soon as it is out. Thanks fro the fix!


Note You need to log in before you can comment on or make changes to this bug.