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 | |
scoder | 4c9ea09 | 2020-05-12 16:12:41 +0200 | [diff] [blame] | 16 | #define PyCFunction_CheckExact(op) Py_IS_TYPE(op, &PyCFunction_Type) |
| 17 | #define PyCFunction_Check(op) PyObject_TypeCheck(op, &PyCFunction_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 18 | |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 19 | typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 20 | typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t); |
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 *); |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 23 | typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *, |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 24 | PyObject *const *, Py_ssize_t, |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 25 | PyObject *); |
Petr Viktorin | e1becf4 | 2020-05-07 15:39:59 +0200 | [diff] [blame] | 26 | typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, |
| 27 | size_t, PyObject *); |
| 28 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 29 | PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); |
| 30 | PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); |
| 31 | PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 32 | |
Jeroen Demeyer | 7a6873c | 2019-09-11 13:01:01 +0200 | [diff] [blame] | 33 | Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 35 | struct PyMethodDef { |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 36 | const char *ml_name; /* The name of the built-in function/method */ |
| 37 | PyCFunction ml_meth; /* The C function that implements it */ |
| 38 | int ml_flags; /* Combination of METH_xxx flags, which mostly |
| 39 | describe the args expected by the C func */ |
| 40 | const char *ml_doc; /* The __doc__ attribute, or NULL */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 41 | }; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 42 | typedef struct PyMethodDef PyMethodDef; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 43 | |
Andrew Svetlov | 192b10b | 2012-12-26 22:52:04 +0200 | [diff] [blame] | 44 | #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 45 | PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, |
Eli Bendersky | 0069bab | 2012-04-05 06:42:48 +0300 | [diff] [blame] | 46 | PyObject *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 47 | |
Petr Viktorin | e1becf4 | 2020-05-07 15:39:59 +0200 | [diff] [blame] | 48 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 |
| 49 | #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL) |
| 50 | PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *, |
| 51 | PyObject *, PyTypeObject *); |
| 52 | #endif |
| 53 | |
| 54 | |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 55 | /* Flag passed to newmethodobject */ |
Georg Brandl | f2fc934 | 2007-09-01 13:59:50 +0000 | [diff] [blame] | 56 | /* #define METH_OLDARGS 0x0000 -- unsupported now */ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 57 | #define METH_VARARGS 0x0001 |
Guido van Rossum | bebdc37 | 1995-07-26 17:58:29 +0000 | [diff] [blame] | 58 | #define METH_KEYWORDS 0x0002 |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 59 | /* 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] | 60 | #define METH_NOARGS 0x0004 |
| 61 | #define METH_O 0x0008 |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 62 | |
Fred Drake | 7bf9715 | 2002-03-28 05:33:33 +0000 | [diff] [blame] | 63 | /* METH_CLASS and METH_STATIC are a little different; these control |
| 64 | the construction of methods for a class. These cannot be used for |
| 65 | functions in modules. */ |
| 66 | #define METH_CLASS 0x0010 |
| 67 | #define METH_STATIC 0x0020 |
| 68 | |
Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 69 | /* 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] | 70 | already filled the entry. When defined, the flag allows a separate |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 71 | method, "__contains__" for example, to coexist with a defined |
Raymond Hettinger | 8f5cdaa | 2003-12-13 11:26:12 +0000 | [diff] [blame] | 72 | slot like sq_contains. */ |
| 73 | |
| 74 | #define METH_COEXIST 0x0040 |
| 75 | |
Petr Viktorin | 0b9c4c6 | 2020-11-10 14:47:31 +0100 | [diff] [blame] | 76 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 77 | #define METH_FASTCALL 0x0080 |
Anselm Kruis | 9e33973 | 2017-11-02 23:54:57 +0100 | [diff] [blame] | 78 | #endif |
Victor Stinner | a9efb2f | 2016-09-09 17:40:22 -0700 | [diff] [blame] | 79 | |
Anselm Kruis | 9e33973 | 2017-11-02 23:54:57 +0100 | [diff] [blame] | 80 | /* This bit is preserved for Stackless Python */ |
| 81 | #ifdef STACKLESS |
| 82 | #define METH_STACKLESS 0x0100 |
| 83 | #else |
| 84 | #define METH_STACKLESS 0x0000 |
| 85 | #endif |
| 86 | |
Petr Viktorin | e1becf4 | 2020-05-07 15:39:59 +0200 | [diff] [blame] | 87 | /* METH_METHOD means the function stores an |
| 88 | * additional reference to the class that defines it; |
| 89 | * both self and class are passed to it. |
| 90 | * It uses PyCMethodObject instead of PyCFunctionObject. |
| 91 | * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC. |
| 92 | */ |
| 93 | |
| 94 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 |
| 95 | #define METH_METHOD 0x0200 |
| 96 | #endif |
| 97 | |
| 98 | |
Anselm Kruis | 9e33973 | 2017-11-02 23:54:57 +0100 | [diff] [blame] | 99 | #ifndef Py_LIMITED_API |
Petr Viktorin | e1becf4 | 2020-05-07 15:39:59 +0200 | [diff] [blame] | 100 | |
| 101 | #define Py_CPYTHON_METHODOBJECT_H |
| 102 | #include "cpython/methodobject.h" |
| 103 | #undef Py_CPYTHON_METHODOBJECT_H |
| 104 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 105 | #endif |
Guido van Rossum | 9223351 | 1998-07-10 15:21:55 +0000 | [diff] [blame] | 106 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 107 | #ifdef __cplusplus |
| 108 | } |
| 109 | #endif |
| 110 | #endif /* !Py_METHODOBJECT_H */ |