blob: 7e67c0bf9aab716a46072b22148e72863c82fbaf [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
Armin Rigo89a39462004-10-28 16:32:00 +000010/* 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
Mark Hammond91a681d2002-08-12 07:21:58 +000014PyAPI_DATA(PyTypeObject) PyCFunction_Type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000015
Christian Heimes90aa7642007-12-19 02:45:37 +000016#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017
Tim Petersdbd9ba62000-07-09 03:09:57 +000018typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
19typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
20 PyObject *);
Jeremy Hylton910d7d42001-08-12 21:52:24 +000021typedef PyObject *(*PyNoArgsFunction)(PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000022
Mark Hammond91a681d2002-08-12 07:21:58 +000023PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
24PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
25PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000026
Guido van Rossum92233511998-07-10 15:21:55 +000027/* Macros for direct access to these values. Type checks are *not*
28 done, so use with care. */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000029#ifndef Py_LIMITED_API
Guido van Rossum92233511998-07-10 15:21:55 +000030#define PyCFunction_GET_FUNCTION(func) \
31 (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
32#define PyCFunction_GET_SELF(func) \
33 (((PyCFunctionObject *)func) -> m_self)
34#define PyCFunction_GET_FLAGS(func) \
35 (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000036#endif
Mark Hammond91a681d2002-08-12 07:21:58 +000037PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
Guido van Rossum92233511998-07-10 15:21:55 +000038
Guido van Rossumcaa63801995-01-12 11:45:45 +000039struct PyMethodDef {
Jeremy Hyltonaf68c872005-12-10 18:50:16 +000040 const char *ml_name; /* The name of the built-in function/method */
Armin Rigo89a39462004-10-28 16:32:00 +000041 PyCFunction ml_meth; /* The C function that implements it */
42 int ml_flags; /* Combination of METH_xxx flags, which mostly
43 describe the args expected by the C func */
Jeremy Hyltonaf68c872005-12-10 18:50:16 +000044 const char *ml_doc; /* The __doc__ attribute, or NULL */
Guido van Rossum3f5da241990-12-20 15:06:42 +000045};
Guido van Rossumcaa63801995-01-12 11:45:45 +000046typedef struct PyMethodDef PyMethodDef;
Guido van Rossum3f5da241990-12-20 15:06:42 +000047
Jeremy Hylton4f0dcc92003-01-31 18:33:18 +000048#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
49PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
50 PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000051
Guido van Rossum5799b521995-01-04 19:06:22 +000052/* Flag passed to newmethodobject */
Georg Brandlf2fc9342007-09-01 13:59:50 +000053/* #define METH_OLDARGS 0x0000 -- unsupported now */
Guido van Rossum5799b521995-01-04 19:06:22 +000054#define METH_VARARGS 0x0001
Guido van Rossumbebdc371995-07-26 17:58:29 +000055#define METH_KEYWORDS 0x0002
Fred Drake7bf97152002-03-28 05:33:33 +000056/* METH_NOARGS and METH_O must not be combined with the flags above. */
Jeremy Hylton910d7d42001-08-12 21:52:24 +000057#define METH_NOARGS 0x0004
58#define METH_O 0x0008
Guido van Rossum5799b521995-01-04 19:06:22 +000059
Fred Drake7bf97152002-03-28 05:33:33 +000060/* METH_CLASS and METH_STATIC are a little different; these control
61 the construction of methods for a class. These cannot be used for
62 functions in modules. */
63#define METH_CLASS 0x0010
64#define METH_STATIC 0x0020
65
Guido van Rossum50e9fb92006-08-17 05:42:55 +000066/* METH_COEXIST allows a method to be entered even though a slot has
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +000067 already filled the entry. When defined, the flag allows a separate
68 method, "__contains__" for example, to coexist with a defined
69 slot like sq_contains. */
70
71#define METH_COEXIST 0x0040
72
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000073#ifndef Py_LIMITED_API
Guido van Rossum92233511998-07-10 15:21:55 +000074typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000075 PyObject_HEAD
Armin Rigo89a39462004-10-28 16:32:00 +000076 PyMethodDef *m_ml; /* Description of the C function to call */
77 PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
78 PyObject *m_module; /* The __module__ attribute, can be anything */
Guido van Rossum92233511998-07-10 15:21:55 +000079} PyCFunctionObject;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000080#endif
Guido van Rossum92233511998-07-10 15:21:55 +000081
Christian Heimesa156e092008-02-16 07:38:31 +000082PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
83
Guido van Rossuma3309961993-07-28 09:05:47 +000084#ifdef __cplusplus
85}
86#endif
87#endif /* !Py_METHODOBJECT_H */