mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-47164: Add _PyCFunction_CAST() macro (GH-32192)
Use the macro in C files of the Python/ directory.
This commit is contained in:
parent
c14d7e4b81
commit
f0bc694856
8 changed files with 57 additions and 36 deletions
|
@ -26,6 +26,24 @@ typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,
|
|||
typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
|
||||
size_t, PyObject *);
|
||||
|
||||
// Cast an function to the PyCFunction type to use it with PyMethodDef.
|
||||
//
|
||||
// This macro can be used to prevent compiler warnings if the first parameter
|
||||
// uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O
|
||||
// calling conventions).
|
||||
//
|
||||
// The macro can also be used for METH_FASTCALL and METH_VARARGS|METH_KEYWORDS
|
||||
// calling conventions to avoid compiler warnings because the function has more
|
||||
// than 2 parameters. The macro first casts the function to the
|
||||
// "void func(void)" type to prevent compiler warnings.
|
||||
//
|
||||
// If a function is declared with the METH_NOARGS calling convention, it must
|
||||
// have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be
|
||||
// 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))
|
||||
|
||||
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
|
||||
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
|
||||
PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue