blob: 887385d5e89825c60c72d41c4e386d3d41930502 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Method object interface */
3
Fred Drakeea9cb5a2000-07-09 00:20:36 +00004#ifndef Py_METHODOBJECT_H
5#define Py_METHODOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Mark Hammond91a681d2002-08-12 07:21:58 +000010PyAPI_DATA(PyTypeObject) PyCFunction_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000011
Guido van Rossumcaa63801995-01-12 11:45:45 +000012#define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000013
Tim Petersdbd9ba62000-07-09 03:09:57 +000014typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
15typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
16 PyObject *);
Jeremy Hylton910d7d42001-08-12 21:52:24 +000017typedef PyObject *(*PyNoArgsFunction)(PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000018
Mark Hammond91a681d2002-08-12 07:21:58 +000019PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
20PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
21PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000022
Guido van Rossum92233511998-07-10 15:21:55 +000023/* Macros for direct access to these values. Type checks are *not*
24 done, so use with care. */
25#define PyCFunction_GET_FUNCTION(func) \
26 (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
27#define PyCFunction_GET_SELF(func) \
28 (((PyCFunctionObject *)func) -> m_self)
29#define PyCFunction_GET_FLAGS(func) \
30 (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
Mark Hammond91a681d2002-08-12 07:21:58 +000031PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
Guido van Rossum92233511998-07-10 15:21:55 +000032
Guido van Rossumcaa63801995-01-12 11:45:45 +000033struct PyMethodDef {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000034 char *ml_name;
35 PyCFunction ml_meth;
36 int ml_flags;
37 char *ml_doc;
Guido van Rossum3f5da241990-12-20 15:06:42 +000038};
Guido van Rossumcaa63801995-01-12 11:45:45 +000039typedef struct PyMethodDef PyMethodDef;
Guido van Rossum3f5da241990-12-20 15:06:42 +000040
Mark Hammond91a681d2002-08-12 07:21:58 +000041PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, char *);
Guido van Rossum9dc8d0e1995-01-07 10:32:29 +000042
Jeremy Hylton4f0dcc92003-01-31 18:33:18 +000043#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
44PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
45 PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000046
Guido van Rossum5799b521995-01-04 19:06:22 +000047/* Flag passed to newmethodobject */
Andrew M. Kuchling767bf492000-08-03 02:28:54 +000048#define METH_OLDARGS 0x0000
Guido van Rossum5799b521995-01-04 19:06:22 +000049#define METH_VARARGS 0x0001
Guido van Rossumbebdc371995-07-26 17:58:29 +000050#define METH_KEYWORDS 0x0002
Fred Drake7bf97152002-03-28 05:33:33 +000051/* METH_NOARGS and METH_O must not be combined with the flags above. */
Jeremy Hylton910d7d42001-08-12 21:52:24 +000052#define METH_NOARGS 0x0004
53#define METH_O 0x0008
Guido van Rossum5799b521995-01-04 19:06:22 +000054
Fred Drake7bf97152002-03-28 05:33:33 +000055/* METH_CLASS and METH_STATIC are a little different; these control
56 the construction of methods for a class. These cannot be used for
57 functions in modules. */
58#define METH_CLASS 0x0010
59#define METH_STATIC 0x0020
60
Guido van Rossum69785031995-01-26 22:58:48 +000061typedef struct PyMethodChain {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000062 PyMethodDef *methods; /* Methods of this type */
63 struct PyMethodChain *link; /* NULL or base type */
Guido van Rossum69785031995-01-26 22:58:48 +000064} PyMethodChain;
65
Mark Hammond91a681d2002-08-12 07:21:58 +000066PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000067 char *);
Guido van Rossum69785031995-01-26 22:58:48 +000068
Guido van Rossum92233511998-07-10 15:21:55 +000069typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000070 PyObject_HEAD
71 PyMethodDef *m_ml;
72 PyObject *m_self;
Jeremy Hylton4f0dcc92003-01-31 18:33:18 +000073 PyObject *m_module;
Guido van Rossum92233511998-07-10 15:21:55 +000074} PyCFunctionObject;
75
Guido van Rossuma3309961993-07-28 09:05:47 +000076#ifdef __cplusplus
77}
78#endif
79#endif /* !Py_METHODOBJECT_H */