Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Method object interface */ |
| 3 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 4 | #ifndef Py_METHODOBJECT_H |
| 5 | #define Py_METHODOBJECT_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 10 | PyAPI_DATA(PyTypeObject) PyCFunction_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 12 | #define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 13 | |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 14 | typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); |
| 15 | typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, |
| 16 | PyObject *); |
Jeremy Hylton | 910d7d4 | 2001-08-12 21:52:24 +0000 | [diff] [blame] | 17 | typedef PyObject *(*PyNoArgsFunction)(PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 18 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 19 | PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); |
| 20 | PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); |
| 21 | PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 23 | /* 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 Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 31 | PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 33 | struct PyMethodDef { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 34 | char *ml_name; |
| 35 | PyCFunction ml_meth; |
| 36 | int ml_flags; |
| 37 | char *ml_doc; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 38 | }; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 39 | typedef struct PyMethodDef PyMethodDef; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 40 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 41 | PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, char *); |
Guido van Rossum | 9dc8d0e | 1995-01-07 10:32:29 +0000 | [diff] [blame] | 42 | |
Jeremy Hylton | 4f0dcc9 | 2003-01-31 18:33:18 +0000 | [diff] [blame] | 43 | #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) |
| 44 | PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, |
| 45 | PyObject *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 47 | /* Flag passed to newmethodobject */ |
Andrew M. Kuchling | 767bf49 | 2000-08-03 02:28:54 +0000 | [diff] [blame] | 48 | #define METH_OLDARGS 0x0000 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 49 | #define METH_VARARGS 0x0001 |
Guido van Rossum | bebdc37 | 1995-07-26 17:58:29 +0000 | [diff] [blame] | 50 | #define METH_KEYWORDS 0x0002 |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 51 | /* METH_NOARGS and METH_O must not be combined with the flags above. */ |
Jeremy Hylton | 910d7d4 | 2001-08-12 21:52:24 +0000 | [diff] [blame] | 52 | #define METH_NOARGS 0x0004 |
| 53 | #define METH_O 0x0008 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 54 | |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 55 | /* 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 Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 61 | typedef struct PyMethodChain { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 62 | PyMethodDef *methods; /* Methods of this type */ |
| 63 | struct PyMethodChain *link; /* NULL or base type */ |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 64 | } PyMethodChain; |
| 65 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 66 | PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *, |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 67 | char *); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 69 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 70 | PyObject_HEAD |
| 71 | PyMethodDef *m_ml; |
| 72 | PyObject *m_self; |
Jeremy Hylton | 4f0dcc9 | 2003-01-31 18:33:18 +0000 | [diff] [blame] | 73 | PyObject *m_module; |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 74 | } PyCFunctionObject; |
| 75 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 76 | #ifdef __cplusplus |
| 77 | } |
| 78 | #endif |
| 79 | #endif /* !Py_METHODOBJECT_H */ |