summaryrefslogtreecommitdiffstats
path: root/Include/methodobject.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-04-27 08:40:57 (GMT)
committerGitHub <noreply@github.com>2022-04-27 08:40:57 (GMT)
commit29e2245ad5d28b565fe0d0d667d283708c6e832c (patch)
tree8147203346a87146036c0087893f910409d886b0 /Include/methodobject.h
parentf882d33778ee2625ab32d90e28edb6878fb8af93 (diff)
downloadcpython-29e2245ad5d28b565fe0d0d667d283708c6e832c.zip
cpython-29e2245ad5d28b565fe0d0d667d283708c6e832c.tar.gz
cpython-29e2245ad5d28b565fe0d0d667d283708c6e832c.tar.bz2
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/methodobject.h')
-rw-r--r--Include/methodobject.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/Include/methodobject.h b/Include/methodobject.h
index 959e775..2046ab9 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -42,7 +42,9 @@ typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
// used to prevent a compiler warning. If the function has a single parameter,
// it triggers an undefined behavior when Python calls it with 2 parameters
// (bpo-33012).
-#define _PyCFunction_CAST(func) ((PyCFunction)(void(*)(void))(func))
+#define _PyCFunction_CAST(func) \
+ _Py_reinterpret_cast(PyCFunction, \
+ _Py_reinterpret_cast(void(*)(void), (func)))
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);