You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[cppyy] Disable warnings for invalid function casts
Some C++ functions defined in CPyCppyy are passed to CPython API, e.g.
to build Python methods that use some C++ functionality. This is done by
creating a instance of a PyMethodDef struct
(https://docs.python.org/3/c-api/structures.html#c.PyMethodDef). One
data member of this struct is of type PyCFunction
(https://docs.python.org/3/c-api/structures.html#c.PyCFunction), a
typedef of a function with signature
```
PyObject *PyCFunction(PyObject *self,
PyObject *args);
```
In many cases, the C++ functions that are used as the data member of the
PyMethodDef are not directly implemented as PyCFunction, thus need to be
cast. This cast is often invalid, since many of such functions do not
really respect the function signature prescribed by the API. This
pattern is actually encouraged for CPython extension implementations by
the official CPython docs
(https://docs.python.org/3/extending/extending.html#keyword-parameters-for-extension-functions).
As such, the compiler warnings that are generated becausee of the
invalid function casts, for example
```
root/bindings/pyroot/cppyy/CPyCppyy/src/Pythonize.cxx:1949:50: warning: cast from 'PyObject *(*)(PyObject *)' (aka '_object *(*)(_object *)') to 'PyCFunction' (aka '_object *(*)(_object *, _object *)') converts to incompatible function type [-Wcast-function-type-mismatch]
1949 | Utility::AddToClass(pyclass, "__repr__", (PyCFunction)ComplexRepr, METH_NOARGS);
```
cannot be avoided and have to be suppressed. This is also done upstream,
see wlav/CPyCppyy@33d4a6e
0 commit comments