blob: a45a80132ca24648a6ea167eb91e976d2f1b63ba [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 {
Tim Peters6d6c1a32001-08-02 04:15:00 +000012 char *name;
13 getter get;
14 setter set;
Guido van Rossum32d34c82001-09-20 21:45:26 +000015 char *doc;
Tim Peters6d6c1a32001-08-02 04:15:00 +000016 void *closure;
Guido van Rossum32d34c82001-09-20 21:45:26 +000017} PyGetSetDef;
Tim Peters6d6c1a32001-08-02 04:15:00 +000018
19typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
20 void *wrapped);
21
Guido van Rossumc8e56452001-10-22 00:43:43 +000022typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
23 void *wrapped, PyObject *kwds);
24
Tim Peters6d6c1a32001-08-02 04:15:00 +000025struct wrapperbase {
26 char *name;
Guido van Rossum6d204072001-10-21 00:44:31 +000027 int offset;
28 void *function;
Tim Peters6d6c1a32001-08-02 04:15:00 +000029 wrapperfunc wrapper;
30 char *doc;
Guido van Rossumc8e56452001-10-22 00:43:43 +000031 int flags;
Guido van Rossum6d204072001-10-21 00:44:31 +000032 PyObject *name_strobj;
Tim Peters6d6c1a32001-08-02 04:15:00 +000033};
34
Guido van Rossumc8e56452001-10-22 00:43:43 +000035/* Flags for above struct */
36#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */
37
Guido van Rossumf4593e02001-10-03 12:09:30 +000038/* Various kinds of descriptor objects */
39
40#define PyDescr_COMMON \
41 PyObject_HEAD \
42 PyTypeObject *d_type; \
43 PyObject *d_name
44
45typedef struct {
46 PyDescr_COMMON;
47} PyDescrObject;
48
49typedef struct {
50 PyDescr_COMMON;
51 PyMethodDef *d_method;
52} PyMethodDescrObject;
53
54typedef struct {
55 PyDescr_COMMON;
56 struct PyMemberDef *d_member;
57} PyMemberDescrObject;
58
59typedef struct {
60 PyDescr_COMMON;
61 PyGetSetDef *d_getset;
62} PyGetSetDescrObject;
63
64typedef struct {
65 PyDescr_COMMON;
66 struct wrapperbase *d_base;
67 void *d_wrapped; /* This can be any function pointer */
68} PyWrapperDescrObject;
69
Mark Hammond91a681d2002-08-12 07:21:58 +000070PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
Guido van Rossumf4593e02001-10-03 12:09:30 +000071
Mark Hammond91a681d2002-08-12 07:21:58 +000072PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
Tim Petersbca1cbc2002-12-09 22:56:13 +000073PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000074PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
Guido van Rossum6f799372001-09-20 20:46:19 +000075 struct PyMemberDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000076PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
Guido van Rossum32d34c82001-09-20 21:45:26 +000077 struct PyGetSetDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000078PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
Tim Peters6d6c1a32001-08-02 04:15:00 +000079 struct wrapperbase *, void *);
Martin v. Löwis9f2e3462007-07-21 17:22:18 +000080#define PyDescr_IsData(d) (Py_Type(d)->tp_descr_set != NULL)
Tim Peters6d6c1a32001-08-02 04:15:00 +000081
Mark Hammond91a681d2002-08-12 07:21:58 +000082PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
83PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
Guido van Rossum29a62dd2001-08-23 21:40:38 +000084
85
Mark Hammond91a681d2002-08-12 07:21:58 +000086PyAPI_DATA(PyTypeObject) PyProperty_Type;
Martin v. Löwis522cf1f2002-03-30 08:57:12 +000087#ifdef __cplusplus
88}
89#endif
90#endif /* !Py_DESCROBJECT_H */
91