1/* Method object interface */23#ifndef Py_METHODOBJECT_H4#define Py_METHODOBJECT_H5#ifdef __cplusplus6extern "C" {7#endif89/* This is about the type 'builtin_function_or_method',10not Python methods in user-defined classes. See classobject.h11for the latter. */1213PyAPI_DATA(PyTypeObject) PyCFunction_Type;1415#define PyCFunction_CheckExact(op) Py_IS_TYPE((op), &PyCFunction_Type)16#define PyCFunction_Check(op) PyObject_TypeCheck((op), &PyCFunction_Type)1718typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);19typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);20typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,21PyObject *);22typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,23PyObject *const *, Py_ssize_t,24PyObject *);25typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,26size_t, PyObject *);2728// Cast an function to the PyCFunction type to use it with PyMethodDef.29//30// This macro can be used to prevent compiler warnings if the first parameter31// uses a different pointer type than PyObject* (ex: METH_VARARGS and METH_O32// calling conventions).33//34// The macro can also be used for METH_FASTCALL and METH_VARARGS|METH_KEYWORDS35// calling conventions to avoid compiler warnings because the function has more36// than 2 parameters. The macro first casts the function to the37// "void func(void)" type to prevent compiler warnings.38//39// If a function is declared with the METH_NOARGS calling convention, it must40// have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be41// used to prevent a compiler warning. If the function has a single parameter,42// it triggers an undefined behavior when Python calls it with 2 parameters43// (bpo-33012).44#define _PyCFunction_CAST(func) \45_Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))4647PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);48PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);49PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);5051struct PyMethodDef {52const char *ml_name; /* The name of the built-in function/method */53PyCFunction ml_meth; /* The C function that implements it */54int ml_flags; /* Combination of METH_xxx flags, which mostly55describe the args expected by the C func */56const char *ml_doc; /* The __doc__ attribute, or NULL */57};5859/* PyCFunction_New is declared as a function for stable ABI (declaration is60* needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro61* that calls PyCFunction_NewEx. */62PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);63#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)6465/* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */66PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,67PyObject *);6869#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x0309000070#define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)71PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,72PyObject *, PyTypeObject *);73#endif747576/* Flag passed to newmethodobject */77/* #define METH_OLDARGS 0x0000 -- unsupported now */78#define METH_VARARGS 0x000179#define METH_KEYWORDS 0x000280/* METH_NOARGS and METH_O must not be combined with the flags above. */81#define METH_NOARGS 0x000482#define METH_O 0x00088384/* METH_CLASS and METH_STATIC are a little different; these control85the construction of methods for a class. These cannot be used for86functions in modules. */87#define METH_CLASS 0x001088#define METH_STATIC 0x00208990/* METH_COEXIST allows a method to be entered even though a slot has91already filled the entry. When defined, the flag allows a separate92method, "__contains__" for example, to coexist with a defined93slot like sq_contains. */9495#define METH_COEXIST 0x00409697#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a000098# define METH_FASTCALL 0x008099#endif100101/* This bit is preserved for Stackless Python */102#ifdef STACKLESS103# define METH_STACKLESS 0x0100104#else105# define METH_STACKLESS 0x0000106#endif107108/* METH_METHOD means the function stores an109* additional reference to the class that defines it;110* both self and class are passed to it.111* It uses PyCMethodObject instead of PyCFunctionObject.112* May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.113*/114115#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000116#define METH_METHOD 0x0200117#endif118119120#ifndef Py_LIMITED_API121# define Py_CPYTHON_METHODOBJECT_H122# include "cpython/methodobject.h"123# undef Py_CPYTHON_METHODOBJECT_H124#endif125126#ifdef __cplusplus127}128#endif129#endif /* !Py_METHODOBJECT_H */130131132