diff options
| author | Victor Stinner <vstinner@python.org> | 2022-04-27 10:40:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-27 10:40:57 +0200 |
| commit | 29e2245ad5d28b565fe0d0d667d283708c6e832c (patch) | |
| tree | 8147203346a87146036c0087893f910409d886b0 /Include/cpython/methodobject.h | |
| parent | f882d33778ee2625ab32d90e28edb6878fb8af93 (diff) | |
| download | cpython-git-29e2245ad5d28b565fe0d0d667d283708c6e832c.tar.gz | |
gh-91320: Add _Py_reinterpret_cast() macro (#91959)
Fix C++ compiler warnings about "old-style cast"
(g++ -Wold-style-cast) in the Python C API. Use C++
reinterpret_cast<> and static_cast<> casts when the Python C API is
used in C++.
Example of fixed warning:
Include/object.h:107:43: error: use of old-style cast to
‘PyObject*’ {aka ‘struct _object*’} [-Werror=old-style-cast]
#define _PyObject_CAST(op) ((PyObject*)(op))
Add _Py_reinterpret_cast() and _Py_static_cast() macros.
Diffstat (limited to 'Include/cpython/methodobject.h')
| -rw-r--r-- | Include/cpython/methodobject.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Include/cpython/methodobject.h b/Include/cpython/methodobject.h index 46d177793f..68cecfe05b 100644 --- a/Include/cpython/methodobject.h +++ b/Include/cpython/methodobject.h @@ -8,9 +8,11 @@ PyAPI_DATA(PyTypeObject) PyCMethod_Type; #define PyCMethod_Check(op) PyObject_TypeCheck(op, &PyCMethod_Type) #define _PyCFunctionObject_CAST(func) \ - (assert(PyCFunction_Check(func)), (PyCFunctionObject *)(func)) + (assert(PyCFunction_Check(func)), \ + _Py_reinterpret_cast(PyCFunctionObject*, (func))) #define _PyCMethodObject_CAST(func) \ - (assert(PyCMethod_Check(func)), (PyCMethodObject *)(func)) + (assert(PyCMethod_Check(func)), \ + _Py_reinterpret_cast(PyCMethodObject*, (func))) /* Macros for direct access to these values. Type checks are *not* done, so use with care. */ |
