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

/Include/methodobject.h

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