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 | |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 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 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 14 | PyAPI_DATA(PyTypeObject) PyCFunction_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 15 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 16 | #define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 17 | |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 18 | typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); |
| 19 | typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, |
| 20 | PyObject *); |
Jeremy Hylton | 910d7d4 | 2001-08-12 21:52:24 +0000 | [diff] [blame] | 21 | typedef PyObject *(*PyNoArgsFunction)(PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 22 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 23 | PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); |
| 24 | PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); |
| 25 | PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 27 | /* Macros for direct access to these values. Type checks are *not* |
| 28 | done, so use with care. */ |
| 29 | #define PyCFunction_GET_FUNCTION(func) \ |
| 30 | (((PyCFunctionObject *)func) -> m_ml -> ml_meth) |
| 31 | #define PyCFunction_GET_SELF(func) \ |
| 32 | (((PyCFunctionObject *)func) -> m_self) |
| 33 | #define PyCFunction_GET_FLAGS(func) \ |
| 34 | (((PyCFunctionObject *)func) -> m_ml -> ml_flags) |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 35 | PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 37 | struct PyMethodDef { |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 38 | const char *ml_name; /* The name of the built-in function/method */ |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 39 | PyCFunction ml_meth; /* The C function that implements it */ |
| 40 | int ml_flags; /* Combination of METH_xxx flags, which mostly |
| 41 | describe the args expected by the C func */ |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 42 | const char *ml_doc; /* The __doc__ attribute, or NULL */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 43 | }; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 44 | typedef struct PyMethodDef PyMethodDef; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 45 | |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 46 | PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *); |
Guido van Rossum | 9dc8d0e | 1995-01-07 10:32:29 +0000 | [diff] [blame] | 47 | |
Jeremy Hylton | 4f0dcc9 | 2003-01-31 18:33:18 +0000 | [diff] [blame] | 48 | #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) |
| 49 | PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, |
| 50 | PyObject *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 52 | /* Flag passed to newmethodobject */ |
Andrew M. Kuchling | 767bf49 | 2000-08-03 02:28:54 +0000 | [diff] [blame] | 53 | #define METH_OLDARGS 0x0000 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 54 | #define METH_VARARGS 0x0001 |
Guido van Rossum | bebdc37 | 1995-07-26 17:58:29 +0000 | [diff] [blame] | 55 | #define METH_KEYWORDS 0x0002 |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 56 | /* 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] | 57 | #define METH_NOARGS 0x0004 |
| 58 | #define METH_O 0x0008 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 59 | |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 60 | /* 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 | |
Raymond Hettinger | 8f5cdaa | 2003-12-13 11:26:12 +0000 | [diff] [blame] | 66 | /* METH_COEXIST allows a method to be entered eventhough a slot has |
| 67 | 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 | |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 73 | typedef struct PyMethodChain { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 74 | PyMethodDef *methods; /* Methods of this type */ |
| 75 | struct PyMethodChain *link; /* NULL or base type */ |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 76 | } PyMethodChain; |
| 77 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 78 | PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *, |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 79 | const char *); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 80 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 81 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 82 | PyObject_HEAD |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 83 | PyMethodDef *m_ml; /* Description of the C function to call */ |
| 84 | PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ |
| 85 | PyObject *m_module; /* The __module__ attribute, can be anything */ |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 86 | } PyCFunctionObject; |
| 87 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
| 91 | #endif /* !Py_METHODOBJECT_H */ |