mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
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.
This commit is contained in:
parent
f882d33778
commit
29e2245ad5
10 changed files with 42 additions and 17 deletions
|
@ -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 *);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue