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 | |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 16 | #define PyCFunction_Check(op) (Py_TYPE(op) == &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 *); |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 19 | typedef PyObject *(*_PyCFunctionFast) (PyObject *self, PyObject **args, |
| 20 | Py_ssize_t nargs, PyObject *kwnames); |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 21 | typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 22 | PyObject *); |
Jeremy Hylton | 910d7d4 | 2001-08-12 21:52:24 +0000 | [diff] [blame] | 23 | typedef PyObject *(*PyNoArgsFunction)(PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 24 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 25 | PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); |
| 26 | PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); |
| 27 | PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 29 | /* Macros for direct access to these values. Type checks are *not* |
| 30 | done, so use with care. */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 31 | #ifndef Py_LIMITED_API |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 32 | #define PyCFunction_GET_FUNCTION(func) \ |
| 33 | (((PyCFunctionObject *)func) -> m_ml -> ml_meth) |
| 34 | #define PyCFunction_GET_SELF(func) \ |
Antoine Pitrou | 5b62942 | 2011-12-23 12:40:16 +0100 | [diff] [blame] | 35 | (((PyCFunctionObject *)func) -> m_ml -> ml_flags & METH_STATIC ? \ |
| 36 | NULL : ((PyCFunctionObject *)func) -> m_self) |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 37 | #define PyCFunction_GET_FLAGS(func) \ |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 38 | (((PyCFunctionObject *)func) -> m_ml -> ml_flags) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 39 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 40 | PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 41 | |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 42 | #ifndef Py_LIMITED_API |
Victor Stinner | b900939 | 2016-08-22 23:15:44 +0200 | [diff] [blame] | 43 | PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func, |
Victor Stinner | 74319ae | 2016-08-25 00:04:09 +0200 | [diff] [blame] | 44 | PyObject **args, |
| 45 | Py_ssize_t nargs, |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 46 | PyObject *kwargs); |
Victor Stinner | ae8b69c | 2016-09-09 14:07:44 -0700 | [diff] [blame] | 47 | |
| 48 | PyAPI_FUNC(PyObject *) _PyCFunction_FastCallKeywords(PyObject *func, |
| 49 | PyObject **stack, |
| 50 | Py_ssize_t nargs, |
| 51 | PyObject *kwnames); |
Victor Stinner | 9be7e7b | 2016-08-19 16:11:43 +0200 | [diff] [blame] | 52 | #endif |
| 53 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 54 | struct PyMethodDef { |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 55 | const char *ml_name; /* The name of the built-in function/method */ |
| 56 | PyCFunction ml_meth; /* The C function that implements it */ |
| 57 | int ml_flags; /* Combination of METH_xxx flags, which mostly |
| 58 | describe the args expected by the C func */ |
| 59 | const char *ml_doc; /* The __doc__ attribute, or NULL */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 60 | }; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 61 | typedef struct PyMethodDef PyMethodDef; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 62 | |
Andrew Svetlov | 192b10b | 2012-12-26 22:52:04 +0200 | [diff] [blame] | 63 | #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 64 | PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 65 | PyObject *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 66 | |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 67 | /* Flag passed to newmethodobject */ |
Georg Brandl | f2fc934 | 2007-09-01 13:59:50 +0000 | [diff] [blame] | 68 | /* #define METH_OLDARGS 0x0000 -- unsupported now */ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 69 | #define METH_VARARGS 0x0001 |
Guido van Rossum | bebdc37 | 1995-07-26 17:58:29 +0000 | [diff] [blame] | 70 | #define METH_KEYWORDS 0x0002 |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 71 | /* 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] | 72 | #define METH_NOARGS 0x0004 |
| 73 | #define METH_O 0x0008 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 74 | |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 75 | /* METH_CLASS and METH_STATIC are a little different; these control |
| 76 | the construction of methods for a class. These cannot be used for |
| 77 | functions in modules. */ |
| 78 | #define METH_CLASS 0x0010 |
| 79 | #define METH_STATIC 0x0020 |
| 80 | |
Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 81 | /* METH_COEXIST allows a method to be entered even though a slot has |
Raymond Hettinger | 8f5cdaa | 2003-12-13 11:26:12 +0000 | [diff] [blame] | 82 | already filled the entry. When defined, the flag allows a separate |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 83 | method, "__contains__" for example, to coexist with a defined |
Raymond Hettinger | 8f5cdaa | 2003-12-13 11:26:12 +0000 | [diff] [blame] | 84 | slot like sq_contains. */ |
| 85 | |
| 86 | #define METH_COEXIST 0x0040 |
| 87 | |
Victor Stinner | 137f39a | 2016-09-12 15:55:21 +0200 | [diff] [blame] | 88 | #ifndef Py_LIMITED_API |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 89 | #define METH_FASTCALL 0x0080 |
| 90 | |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 91 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 92 | PyObject_HEAD |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 93 | PyMethodDef *m_ml; /* Description of the C function to call */ |
| 94 | PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ |
| 95 | PyObject *m_module; /* The __module__ attribute, can be anything */ |
Antoine Pitrou | b349e4c | 2014-08-06 19:31:40 -0400 | [diff] [blame] | 96 | PyObject *m_weakreflist; /* List of weak references */ |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 97 | } PyCFunctionObject; |
Victor Stinner | c525723 | 2017-01-18 10:38:09 +0100 | [diff] [blame] | 98 | |
| 99 | PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallDict( |
| 100 | PyMethodDef *method, |
| 101 | PyObject *self, |
| 102 | PyObject **args, |
| 103 | Py_ssize_t nargs, |
| 104 | PyObject *kwargs); |
INADA Naoki | 5566bbb | 2017-02-03 07:43:03 +0900 | [diff] [blame^] | 105 | |
| 106 | PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallKeywords( |
| 107 | PyMethodDef *method, |
| 108 | PyObject *self, |
| 109 | PyObject **args, |
| 110 | Py_ssize_t nargs, |
| 111 | PyObject *kwnames); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 112 | #endif |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 113 | |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 114 | PyAPI_FUNC(int) PyCFunction_ClearFreeList(void); |
| 115 | |
David Malcolm | 49526f4 | 2012-06-22 14:55:41 -0400 | [diff] [blame] | 116 | #ifndef Py_LIMITED_API |
| 117 | PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out); |
| 118 | PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out); |
| 119 | #endif |
| 120 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | #endif /* !Py_METHODOBJECT_H */ |