jpayne@69
|
1
|
jpayne@69
|
2 /* Method object interface */
|
jpayne@69
|
3
|
jpayne@69
|
4 #ifndef Py_METHODOBJECT_H
|
jpayne@69
|
5 #define Py_METHODOBJECT_H
|
jpayne@69
|
6 #ifdef __cplusplus
|
jpayne@69
|
7 extern "C" {
|
jpayne@69
|
8 #endif
|
jpayne@69
|
9
|
jpayne@69
|
10 /* This is about the type 'builtin_function_or_method',
|
jpayne@69
|
11 not Python methods in user-defined classes. See classobject.h
|
jpayne@69
|
12 for the latter. */
|
jpayne@69
|
13
|
jpayne@69
|
14 PyAPI_DATA(PyTypeObject) PyCFunction_Type;
|
jpayne@69
|
15
|
jpayne@69
|
16 #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
|
jpayne@69
|
17
|
jpayne@69
|
18 typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
|
jpayne@69
|
19 typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);
|
jpayne@69
|
20 typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
|
jpayne@69
|
21 PyObject *);
|
jpayne@69
|
22 typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,
|
jpayne@69
|
23 PyObject *const *, Py_ssize_t,
|
jpayne@69
|
24 PyObject *);
|
jpayne@69
|
25 typedef PyObject *(*PyNoArgsFunction)(PyObject *);
|
jpayne@69
|
26
|
jpayne@69
|
27 PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
|
jpayne@69
|
28 PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
|
jpayne@69
|
29 PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
|
jpayne@69
|
30
|
jpayne@69
|
31 /* Macros for direct access to these values. Type checks are *not*
|
jpayne@69
|
32 done, so use with care. */
|
jpayne@69
|
33 #ifndef Py_LIMITED_API
|
jpayne@69
|
34 #define PyCFunction_GET_FUNCTION(func) \
|
jpayne@69
|
35 (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
|
jpayne@69
|
36 #define PyCFunction_GET_SELF(func) \
|
jpayne@69
|
37 (((PyCFunctionObject *)func) -> m_ml -> ml_flags & METH_STATIC ? \
|
jpayne@69
|
38 NULL : ((PyCFunctionObject *)func) -> m_self)
|
jpayne@69
|
39 #define PyCFunction_GET_FLAGS(func) \
|
jpayne@69
|
40 (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
|
jpayne@69
|
41 #endif
|
jpayne@69
|
42 PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
|
jpayne@69
|
43
|
jpayne@69
|
44 #ifndef Py_LIMITED_API
|
jpayne@69
|
45 PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func,
|
jpayne@69
|
46 PyObject *const *args,
|
jpayne@69
|
47 Py_ssize_t nargs,
|
jpayne@69
|
48 PyObject *kwargs);
|
jpayne@69
|
49 #endif
|
jpayne@69
|
50
|
jpayne@69
|
51 struct PyMethodDef {
|
jpayne@69
|
52 const char *ml_name; /* The name of the built-in function/method */
|
jpayne@69
|
53 PyCFunction ml_meth; /* The C function that implements it */
|
jpayne@69
|
54 int ml_flags; /* Combination of METH_xxx flags, which mostly
|
jpayne@69
|
55 describe the args expected by the C func */
|
jpayne@69
|
56 const char *ml_doc; /* The __doc__ attribute, or NULL */
|
jpayne@69
|
57 };
|
jpayne@69
|
58 typedef struct PyMethodDef PyMethodDef;
|
jpayne@69
|
59
|
jpayne@69
|
60 #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
|
jpayne@69
|
61 PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
|
jpayne@69
|
62 PyObject *);
|
jpayne@69
|
63
|
jpayne@69
|
64 /* Flag passed to newmethodobject */
|
jpayne@69
|
65 /* #define METH_OLDARGS 0x0000 -- unsupported now */
|
jpayne@69
|
66 #define METH_VARARGS 0x0001
|
jpayne@69
|
67 #define METH_KEYWORDS 0x0002
|
jpayne@69
|
68 /* METH_NOARGS and METH_O must not be combined with the flags above. */
|
jpayne@69
|
69 #define METH_NOARGS 0x0004
|
jpayne@69
|
70 #define METH_O 0x0008
|
jpayne@69
|
71
|
jpayne@69
|
72 /* METH_CLASS and METH_STATIC are a little different; these control
|
jpayne@69
|
73 the construction of methods for a class. These cannot be used for
|
jpayne@69
|
74 functions in modules. */
|
jpayne@69
|
75 #define METH_CLASS 0x0010
|
jpayne@69
|
76 #define METH_STATIC 0x0020
|
jpayne@69
|
77
|
jpayne@69
|
78 /* METH_COEXIST allows a method to be entered even though a slot has
|
jpayne@69
|
79 already filled the entry. When defined, the flag allows a separate
|
jpayne@69
|
80 method, "__contains__" for example, to coexist with a defined
|
jpayne@69
|
81 slot like sq_contains. */
|
jpayne@69
|
82
|
jpayne@69
|
83 #define METH_COEXIST 0x0040
|
jpayne@69
|
84
|
jpayne@69
|
85 #ifndef Py_LIMITED_API
|
jpayne@69
|
86 #define METH_FASTCALL 0x0080
|
jpayne@69
|
87 #endif
|
jpayne@69
|
88
|
jpayne@69
|
89 /* This bit is preserved for Stackless Python */
|
jpayne@69
|
90 #ifdef STACKLESS
|
jpayne@69
|
91 #define METH_STACKLESS 0x0100
|
jpayne@69
|
92 #else
|
jpayne@69
|
93 #define METH_STACKLESS 0x0000
|
jpayne@69
|
94 #endif
|
jpayne@69
|
95
|
jpayne@69
|
96 #ifndef Py_LIMITED_API
|
jpayne@69
|
97 typedef struct {
|
jpayne@69
|
98 PyObject_HEAD
|
jpayne@69
|
99 PyMethodDef *m_ml; /* Description of the C function to call */
|
jpayne@69
|
100 PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
|
jpayne@69
|
101 PyObject *m_module; /* The __module__ attribute, can be anything */
|
jpayne@69
|
102 PyObject *m_weakreflist; /* List of weak references */
|
jpayne@69
|
103 vectorcallfunc vectorcall;
|
jpayne@69
|
104 } PyCFunctionObject;
|
jpayne@69
|
105
|
jpayne@69
|
106 PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallDict(
|
jpayne@69
|
107 PyMethodDef *method,
|
jpayne@69
|
108 PyObject *self,
|
jpayne@69
|
109 PyObject *const *args,
|
jpayne@69
|
110 Py_ssize_t nargs,
|
jpayne@69
|
111 PyObject *kwargs);
|
jpayne@69
|
112
|
jpayne@69
|
113 PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallKeywords(
|
jpayne@69
|
114 PyMethodDef *method,
|
jpayne@69
|
115 PyObject *self,
|
jpayne@69
|
116 PyObject *const *args,
|
jpayne@69
|
117 Py_ssize_t nargs,
|
jpayne@69
|
118 PyObject *kwnames);
|
jpayne@69
|
119 #endif
|
jpayne@69
|
120
|
jpayne@69
|
121 PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
|
jpayne@69
|
122
|
jpayne@69
|
123 #ifndef Py_LIMITED_API
|
jpayne@69
|
124 PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out);
|
jpayne@69
|
125 PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out);
|
jpayne@69
|
126 #endif
|
jpayne@69
|
127
|
jpayne@69
|
128 #ifdef __cplusplus
|
jpayne@69
|
129 }
|
jpayne@69
|
130 #endif
|
jpayne@69
|
131 #endif /* !Py_METHODOBJECT_H */
|