diff options
author | Victor Stinner <vstinner@python.org> | 2021-06-11 08:35:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 08:35:36 (GMT) |
commit | 304dfec8d3c0763734ea8b5fa2af1d9e1ce69ffa (patch) | |
tree | 77344bbbd948d0966a6964c53e5d7f11c8414cbd | |
parent | 3a7cccfd6cd3693e1a2ab65ee05d7f45f8501dfa (diff) | |
download | cpython-304dfec8d3c0763734ea8b5fa2af1d9e1ce69ffa.zip cpython-304dfec8d3c0763734ea8b5fa2af1d9e1ce69ffa.tar.gz cpython-304dfec8d3c0763734ea8b5fa2af1d9e1ce69ffa.tar.bz2 |
bpo-44378: Fix a compiler warning in Py_IS_TYPE() (GH-26644)
Py_IS_TYPE() no longer uses Py_TYPE() to avoid a compiler warning:
no longer cast "const PyObject*" to "PyObject*".
-rw-r--r-- | Include/object.h | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2021-06-10-15-22-31.bpo-44378.jGYakF.rst | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/Include/object.h b/Include/object.h index 4c06999..109f535 100644 --- a/Include/object.h +++ b/Include/object.h @@ -141,7 +141,9 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) { static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { - return Py_TYPE(ob) == type; + // bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const + // object. + return ob->ob_type == type; } #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) diff --git a/Misc/NEWS.d/next/C API/2021-06-10-15-22-31.bpo-44378.jGYakF.rst b/Misc/NEWS.d/next/C API/2021-06-10-15-22-31.bpo-44378.jGYakF.rst new file mode 100644 index 0000000..b620b49 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-06-10-15-22-31.bpo-44378.jGYakF.rst @@ -0,0 +1,3 @@ +:c:func:`Py_IS_TYPE` no longer uses :c:func:`Py_TYPE` to avoid a compiler +warning: no longer cast ``const PyObject*`` to ``PyObject*``. +Patch by Victor Stinner. |