Guido van Rossum | 32d34c8 | 2001-09-20 21:45:26 +0000 | [diff] [blame] | 1 | /* Descriptors */ |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame] | 2 | #ifndef Py_DESCROBJECT_H |
| 3 | #define Py_DESCROBJECT_H |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 7 | |
| 8 | typedef PyObject *(*getter)(PyObject *, void *); |
| 9 | typedef int (*setter)(PyObject *, PyObject *, void *); |
| 10 | |
Guido van Rossum | 32d34c8 | 2001-09-20 21:45:26 +0000 | [diff] [blame] | 11 | typedef struct PyGetSetDef { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 12 | char *name; |
| 13 | getter get; |
| 14 | setter set; |
| 15 | char *doc; |
| 16 | void *closure; |
Guido van Rossum | 32d34c8 | 2001-09-20 21:45:26 +0000 | [diff] [blame] | 17 | } PyGetSetDef; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 18 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 19 | #ifndef Py_LIMITED_API |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 20 | typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 21 | void *wrapped); |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | c8e5645 | 2001-10-22 00:43:43 +0000 | [diff] [blame] | 23 | typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 24 | void *wrapped, PyObject *kwds); |
Guido van Rossum | c8e5645 | 2001-10-22 00:43:43 +0000 | [diff] [blame] | 25 | |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 26 | struct wrapperbase { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 27 | char *name; |
| 28 | int offset; |
| 29 | void *function; |
| 30 | wrapperfunc wrapper; |
| 31 | char *doc; |
| 32 | int flags; |
| 33 | PyObject *name_strobj; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Guido van Rossum | c8e5645 | 2001-10-22 00:43:43 +0000 | [diff] [blame] | 36 | /* Flags for above struct */ |
| 37 | #define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */ |
| 38 | |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 39 | /* Various kinds of descriptor objects */ |
| 40 | |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 41 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 42 | PyObject_HEAD |
| 43 | PyTypeObject *d_type; |
| 44 | PyObject *d_name; |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 45 | } PyDescrObject; |
| 46 | |
Alexandre Vassalotti | 2db046d | 2009-07-22 03:56:36 +0000 | [diff] [blame] | 47 | #define PyDescr_COMMON PyDescrObject d_common |
| 48 | |
| 49 | #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) |
| 50 | #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) |
| 51 | |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 52 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 53 | PyDescr_COMMON; |
| 54 | PyMethodDef *d_method; |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 55 | } PyMethodDescrObject; |
| 56 | |
| 57 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 58 | PyDescr_COMMON; |
| 59 | struct PyMemberDef *d_member; |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 60 | } PyMemberDescrObject; |
| 61 | |
| 62 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 63 | PyDescr_COMMON; |
| 64 | PyGetSetDef *d_getset; |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 65 | } PyGetSetDescrObject; |
| 66 | |
| 67 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 | PyDescr_COMMON; |
| 69 | struct wrapperbase *d_base; |
| 70 | void *d_wrapped; /* This can be any function pointer */ |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 71 | } PyWrapperDescrObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 72 | #endif /* Py_LIMITED_API */ |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 73 | |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 74 | PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type; |
| 75 | PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type; |
| 76 | PyAPI_DATA(PyTypeObject) PyMemberDescr_Type; |
| 77 | PyAPI_DATA(PyTypeObject) PyMethodDescr_Type; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 78 | PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type; |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 79 | PyAPI_DATA(PyTypeObject) PyDictProxy_Type; |
Guido van Rossum | f4593e0 | 2001-10-03 12:09:30 +0000 | [diff] [blame] | 80 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 81 | PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *); |
Tim Peters | bca1cbc | 2002-12-09 22:56:13 +0000 | [diff] [blame] | 82 | PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 83 | struct PyMemberDef; /* forward declaration for following prototype */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 84 | PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 85 | struct PyMemberDef *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 86 | PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 87 | struct PyGetSetDef *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 88 | #ifndef Py_LIMITED_API |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 89 | PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 90 | struct wrapperbase *, void *); |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 91 | #define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 92 | #endif |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 93 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 94 | PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *); |
| 95 | PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *); |
Guido van Rossum | 29a62dd | 2001-08-23 21:40:38 +0000 | [diff] [blame] | 96 | |
| 97 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 98 | PyAPI_DATA(PyTypeObject) PyProperty_Type; |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame] | 99 | #ifdef __cplusplus |
| 100 | } |
| 101 | #endif |
| 102 | #endif /* !Py_DESCROBJECT_H */ |
| 103 | |