PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/Include/methodobject.h

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