blob: 993bdae28930373685be1b4a0c9ea3e81d6237c3 [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
Mark Hammond91a681d2002-08-12 07:21:58 +000043PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000044
Guido van Rossum5799b521995-01-04 19:06:22 +000045/* Flag passed to newmethodobject */
Andrew M. Kuchling767bf492000-08-03 02:28:54 +000046#define METH_OLDARGS 0x0000
Guido van Rossum5799b521995-01-04 19:06:22 +000047#define METH_VARARGS 0x0001
Guido van Rossumbebdc371995-07-26 17:58:29 +000048#define METH_KEYWORDS 0x0002
Fred Drake7bf97152002-03-28 05:33:33 +000049/* METH_NOARGS and METH_O must not be combined with the flags above. */
Jeremy Hylton910d7d42001-08-12 21:52:24 +000050#define METH_NOARGS 0x0004
51#define METH_O 0x0008
Guido van Rossum5799b521995-01-04 19:06:22 +000052
Fred Drake7bf97152002-03-28 05:33:33 +000053/* METH_CLASS and METH_STATIC are a little different; these control
54 the construction of methods for a class. These cannot be used for
55 functions in modules. */
56#define METH_CLASS 0x0010
57#define METH_STATIC 0x0020
58
Guido van Rossum69785031995-01-26 22:58:48 +000059typedef struct PyMethodChain {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000060 PyMethodDef *methods; /* Methods of this type */
61 struct PyMethodChain *link; /* NULL or base type */
Guido van Rossum69785031995-01-26 22:58:48 +000062} PyMethodChain;
63
Mark Hammond91a681d2002-08-12 07:21:58 +000064PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000065 char *);
Guido van Rossum69785031995-01-26 22:58:48 +000066
Guido van Rossum92233511998-07-10 15:21:55 +000067typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000068 PyObject_HEAD
69 PyMethodDef *m_ml;
70 PyObject *m_self;
Guido van Rossum92233511998-07-10 15:21:55 +000071} PyCFunctionObject;
72
Guido van Rossuma3309961993-07-28 09:05:47 +000073#ifdef __cplusplus
74}
75#endif
76#endif /* !Py_METHODOBJECT_H */