1
2/* Method object interface */
3
4#ifndef Py_METHODOBJECT_H
5#define Py_METHODOBJECT_H
6#ifdef __cplusplus
7extern "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
14PyAPI_DATA(PyTypeObject) PyCFunction_Type;
15
16#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
17
18typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
19typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
20 PyObject *);
21typedef PyObject *(*PyNoArgsFunction)(PyObject *);
22
23PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
24PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
25PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
26
27/* Macros for direct access to these values. Type checks are *not*
28 done, so use with care. */
29#ifndef Py_LIMITED_API
30#define PyCFunction_GET_FUNCTION(func) \
31 (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
32#define PyCFunction_GET_SELF(func) \
33 (((PyCFunctionObject *)func) -> m_ml -> ml_flags & METH_STATIC ? \
34 NULL : ((PyCFunctionObject *)func) -> m_self)
35#define PyCFunction_GET_FLAGS(func) \
36 (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
37#endif
38PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
39
40struct PyMethodDef {
41 const char *ml_name; /* The name of the built-in function/method */
42 PyCFunction ml_meth; /* The C function that implements it */
43 int ml_flags; /* Combination of METH_xxx flags, which mostly
44 describe the args expected by the C func */
45 const char *ml_doc; /* The __doc__ attribute, or NULL */
46};
47typedef struct PyMethodDef PyMethodDef;
48
49#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
50PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
51 PyObject *);
52
53/* Flag passed to newmethodobject */
54/* #define METH_OLDARGS 0x0000 -- unsupported now */
55#define METH_VARARGS 0x0001
56#define METH_KEYWORDS 0x0002
57/* METH_NOARGS and METH_O must not be combined with the flags above. */
58#define METH_NOARGS 0x0004
59#define METH_O 0x0008
60
61/* METH_CLASS and METH_STATIC are a little different; these control
62 the construction of methods for a class. These cannot be used for
63 functions in modules. */
64#define METH_CLASS 0x0010
65#define METH_STATIC 0x0020
66
67/* METH_COEXIST allows a method to be entered even though a slot has
68 already filled the entry. When defined, the flag allows a separate
69 method, "__contains__" for example, to coexist with a defined
70 slot like sq_contains. */
71
72#define METH_COEXIST 0x0040
73
74#ifndef Py_LIMITED_API
75typedef struct {
76 PyObject_HEAD
77 PyMethodDef *m_ml; /* Description of the C function to call */
78 PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
79 PyObject *m_module; /* The __module__ attribute, can be anything */
80 PyObject *m_weakreflist; /* List of weak references */
81} PyCFunctionObject;
82#endif
83
84PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
85
86#ifndef Py_LIMITED_API
87PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out);
88PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out);
89#endif
90
91#ifdef __cplusplus
92}
93#endif
94#endif /* !Py_METHODOBJECT_H */
95