1 | |
2 | /* Method object interface */ |
3 | |
4 | #ifndef Py_METHODOBJECT_H |
5 | #define Py_METHODOBJECT_H |
6 | #ifdef __cplusplus |
7 | extern "C" { |
8 | #endif |
9 | |
10 | /* This is about the type 'builtin_function_or_method', |
11 | not Python methods in user-defined classes. See classobject.h |
12 | for the latter. */ |
13 | |
14 | PyAPI_DATA(PyTypeObject) PyCFunction_Type; |
15 | |
16 | #define PyCFunction_CheckExact(op) Py_IS_TYPE(op, &PyCFunction_Type) |
17 | #define PyCFunction_Check(op) PyObject_TypeCheck(op, &PyCFunction_Type) |
18 | |
19 | typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); |
20 | typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t); |
21 | typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, |
22 | PyObject *); |
23 | typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *, |
24 | PyObject *const *, Py_ssize_t, |
25 | PyObject *); |
26 | typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, |
27 | size_t, PyObject *); |
28 | |
29 | PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); |
30 | PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); |
31 | PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); |
32 | |
33 | Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); |
34 | |
35 | struct PyMethodDef { |
36 | const char *ml_name; /* The name of the built-in function/method */ |
37 | PyCFunction ml_meth; /* The C function that implements it */ |
38 | int ml_flags; /* Combination of METH_xxx flags, which mostly |
39 | describe the args expected by the C func */ |
40 | const char *ml_doc; /* The __doc__ attribute, or NULL */ |
41 | }; |
42 | typedef struct PyMethodDef PyMethodDef; |
43 | |
44 | /* PyCFunction_New is declared as a function for stable ABI (declaration is |
45 | * needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro |
46 | * that calls PyCFunction_NewEx. */ |
47 | PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *); |
48 | #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) |
49 | |
50 | /* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */ |
51 | PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, |
52 | PyObject *); |
53 | |
54 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 |
55 | #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL) |
56 | PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, |
57 | PyObject *, PyTypeObject *); |
58 | #endif |
59 | |
60 | |
61 | /* Flag passed to newmethodobject */ |
62 | /* #define METH_OLDARGS 0x0000 -- unsupported now */ |
63 | #define METH_VARARGS 0x0001 |
64 | #define METH_KEYWORDS 0x0002 |
65 | /* METH_NOARGS and METH_O must not be combined with the flags above. */ |
66 | #define METH_NOARGS 0x0004 |
67 | #define METH_O 0x0008 |
68 | |
69 | /* METH_CLASS and METH_STATIC are a little different; these control |
70 | the construction of methods for a class. These cannot be used for |
71 | functions in modules. */ |
72 | #define METH_CLASS 0x0010 |
73 | #define METH_STATIC 0x0020 |
74 | |
75 | /* METH_COEXIST allows a method to be entered even though a slot has |
76 | already filled the entry. When defined, the flag allows a separate |
77 | method, "__contains__" for example, to coexist with a defined |
78 | slot like sq_contains. */ |
79 | |
80 | #define METH_COEXIST 0x0040 |
81 | |
82 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000 |
83 | # define METH_FASTCALL 0x0080 |
84 | #endif |
85 | |
86 | /* This bit is preserved for Stackless Python */ |
87 | #ifdef STACKLESS |
88 | # define METH_STACKLESS 0x0100 |
89 | #else |
90 | # define METH_STACKLESS 0x0000 |
91 | #endif |
92 | |
93 | /* METH_METHOD means the function stores an |
94 | * additional reference to the class that defines it; |
95 | * both self and class are passed to it. |
96 | * It uses PyCMethodObject instead of PyCFunctionObject. |
97 | * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC. |
98 | */ |
99 | |
100 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 |
101 | #define METH_METHOD 0x0200 |
102 | #endif |
103 | |
104 | |
105 | #ifndef Py_LIMITED_API |
106 | |
107 | #define Py_CPYTHON_METHODOBJECT_H |
108 | #include "cpython/methodobject.h" |
109 | #undef Py_CPYTHON_METHODOBJECT_H |
110 | |
111 | #endif |
112 | |
113 | #ifdef __cplusplus |
114 | } |
115 | #endif |
116 | #endif /* !Py_METHODOBJECT_H */ |
117 | |