blob: f715fe116012ea7ba3cc480a1ec5d97ce0fa6384 [file] [log] [blame]
Guido van Rossum32d34c82001-09-20 21:45:26 +00001/* Descriptors */
Martin v. Löwis522cf1f2002-03-30 08:57:12 +00002#ifndef Py_DESCROBJECT_H
3#define Py_DESCROBJECT_H
4#ifdef __cplusplus
5extern "C" {
6#endif
Tim Peters6d6c1a32001-08-02 04:15:00 +00007
8typedef PyObject *(*getter)(PyObject *, void *);
9typedef int (*setter)(PyObject *, PyObject *, void *);
10
Guido van Rossum32d34c82001-09-20 21:45:26 +000011typedef struct PyGetSetDef {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000012 char *name;
13 getter get;
14 setter set;
15 char *doc;
16 void *closure;
Guido van Rossum32d34c82001-09-20 21:45:26 +000017} PyGetSetDef;
Tim Peters6d6c1a32001-08-02 04:15:00 +000018
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000019#ifndef Py_LIMITED_API
Tim Peters6d6c1a32001-08-02 04:15:00 +000020typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000021 void *wrapped);
Tim Peters6d6c1a32001-08-02 04:15:00 +000022
Guido van Rossumc8e56452001-10-22 00:43:43 +000023typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000024 void *wrapped, PyObject *kwds);
Guido van Rossumc8e56452001-10-22 00:43:43 +000025
Tim Peters6d6c1a32001-08-02 04:15:00 +000026struct wrapperbase {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000027 char *name;
28 int offset;
29 void *function;
30 wrapperfunc wrapper;
31 char *doc;
32 int flags;
33 PyObject *name_strobj;
Tim Peters6d6c1a32001-08-02 04:15:00 +000034};
35
Guido van Rossumc8e56452001-10-22 00:43:43 +000036/* Flags for above struct */
37#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */
38
Guido van Rossumf4593e02001-10-03 12:09:30 +000039/* Various kinds of descriptor objects */
40
Guido van Rossumf4593e02001-10-03 12:09:30 +000041typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000042 PyObject_HEAD
43 PyTypeObject *d_type;
44 PyObject *d_name;
Guido van Rossumf4593e02001-10-03 12:09:30 +000045} PyDescrObject;
46
Alexandre Vassalotti2db046d2009-07-22 03:56:36 +000047#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 Rossumf4593e02001-10-03 12:09:30 +000052typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000053 PyDescr_COMMON;
54 PyMethodDef *d_method;
Guido van Rossumf4593e02001-10-03 12:09:30 +000055} PyMethodDescrObject;
56
57typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000058 PyDescr_COMMON;
59 struct PyMemberDef *d_member;
Guido van Rossumf4593e02001-10-03 12:09:30 +000060} PyMemberDescrObject;
61
62typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000063 PyDescr_COMMON;
64 PyGetSetDef *d_getset;
Guido van Rossumf4593e02001-10-03 12:09:30 +000065} PyGetSetDescrObject;
66
67typedef struct {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000068 PyDescr_COMMON;
69 struct wrapperbase *d_base;
70 void *d_wrapped; /* This can be any function pointer */
Guido van Rossumf4593e02001-10-03 12:09:30 +000071} PyWrapperDescrObject;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000072#endif /* Py_LIMITED_API */
Guido van Rossumf4593e02001-10-03 12:09:30 +000073
Christian Heimesa22e8bd2007-11-29 22:35:39 +000074PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
75PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
76PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
77PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
Mark Hammond91a681d2002-08-12 07:21:58 +000078PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
Christian Heimesa22e8bd2007-11-29 22:35:39 +000079PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
Guido van Rossumf4593e02001-10-03 12:09:30 +000080
Mark Hammond91a681d2002-08-12 07:21:58 +000081PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
Tim Petersbca1cbc2002-12-09 22:56:13 +000082PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000083struct PyMemberDef; /* forward declaration for following prototype */
Mark Hammond91a681d2002-08-12 07:21:58 +000084PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000085 struct PyMemberDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000086PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000087 struct PyGetSetDef *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000088#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000089PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000090 struct wrapperbase *, void *);
Christian Heimes90aa7642007-12-19 02:45:37 +000091#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000092#endif
Tim Peters6d6c1a32001-08-02 04:15:00 +000093
Mark Hammond91a681d2002-08-12 07:21:58 +000094PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
95PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
Guido van Rossum29a62dd2001-08-23 21:40:38 +000096
97
Mark Hammond91a681d2002-08-12 07:21:58 +000098PyAPI_DATA(PyTypeObject) PyProperty_Type;
Martin v. Löwis522cf1f2002-03-30 08:57:12 +000099#ifdef __cplusplus
100}
101#endif
102#endif /* !Py_DESCROBJECT_H */
103