1 /**
2   Mirror _descrobject.h
3   */
4 module deimos.python.descrobject;
5 
6 import deimos.python.pyport;
7 import deimos.python.object;
8 import deimos.python.methodobject;
9 import deimos.python.structmember;
10 
11 extern(C):
12 // Python-header-file: Include/descrobject.h:
13 
14 /// _
15 alias PyObject* function(PyObject*, void*) getter;
16 /// _
17 alias int function(PyObject*, PyObject*, void*) setter;
18 
19 /// _
20 struct PyGetSetDef {
21     /// _
22     char* name;
23     /// ditto
24     getter get;
25     /// ditto
26     setter set;
27     /// ditto
28     char* doc;
29     /// ditto
30     void* closure;
31 }
32 
33 /// _
34 alias PyObject* function(PyObject*, PyObject*, void*) wrapperfunc;
35 /// _
36 alias PyObject* function(PyObject*, PyObject*, void*, PyObject*) wrapperfunc_kwds;
37 
38 /// _
39 struct wrapperbase {
40     /// _
41     char* name;
42     /// ditto
43     int offset;
44     /// ditto
45     void* function_;
46     /// ditto
47     wrapperfunc wrapper;
48     /// ditto
49     char* doc;
50     /// ditto
51     int flags;
52     /// ditto
53     PyObject* name_strobj;
54 }
55 
56 /// _
57 enum PyWrapperFlag_KEYWORDS = 1;
58 
59 /// _
60 template PyDescr_COMMON() {
61     version(Python_3_0_Or_Later) {
62         /// _
63         PyDescrObject d_common;
64     }else{
65         mixin PyObject_HEAD;
66         /// _
67         PyTypeObject* d_type;
68         /// _
69         PyObject* d_name;
70     }
71 }
72 
73 /// subclass of PyObject.
74 struct PyDescrObject {
75     version(Python_3_0_Or_Later) {
76         mixin PyObject_HEAD;
77         /// _
78         PyTypeObject* d_type;
79         /// _
80         PyObject* d_name;
81     }else{
82         mixin PyDescr_COMMON;
83     }
84 }
85 
86 /// introduced in python 3, but looks generally useful.
87 PyTypeObject* PyDescr_TYPE(T)(T* x)
88 if(     is(T == PyDescrObject) ||
89         is(T == PyMethodDescrObject) ||
90         is(T == PyMemberDescrObject) ||
91         is(T == PyGetSetDescrObject) ||
92         is(T == PyWrapperDescrObject))
93 {
94     return ((cast(PyDescrObject*)x).d_type);
95 }
96 
97 /// introduced in python 3, but looks generally useful.
98 PyObject* PyDescr_NAME(T)(T* x)
99 if(     is(T == PyDescrObject) ||
100         is(T == PyMethodDescrObject) ||
101         is(T == PyMemberDescrObject) ||
102         is(T == PyGetSetDescrObject) ||
103         is(T == PyWrapperDescrObject))
104 {
105     return ((cast(PyDescrObject*)x).d_name);
106 }
107 
108 /// subclass of PyDescrObject
109 struct PyMethodDescrObject {
110     mixin PyDescr_COMMON;
111     /// _
112     PyMethodDef* d_method;
113 }
114 
115 /// subclass of PyDescrObject
116 struct PyMemberDescrObject {
117     mixin PyDescr_COMMON;
118     /// _
119     PyMemberDef* d_member;
120 }
121 
122 /// subclass of PyDescrObject
123 struct PyGetSetDescrObject {
124     mixin PyDescr_COMMON;
125     /// _
126     PyGetSetDef* d_getset;
127 }
128 
129 /// subclass of PyDescrObject
130 struct PyWrapperDescrObject {
131     mixin PyDescr_COMMON;
132     /// _
133     wrapperbase* d_base;
134     /** This can be any function pointer */
135     void* d_wrapped;
136 }
137 
138 /// _
139 mixin(PyAPI_DATA!"PyTypeObject PyWrapperDescr_Type");
140 version(Python_2_6_Or_Later) {
141     /// Availability: >= 2.6
142     mixin(PyAPI_DATA!"PyTypeObject PyDictProxy_Type");
143     /// Availability: >= 2.6
144     mixin(PyAPI_DATA!"PyTypeObject PyGetSetDescr_Type");
145     /// Availability: >= 2.6
146     mixin(PyAPI_DATA!"PyTypeObject PyMemberDescr_Type");
147 }
148 version(Python_3_0_Or_Later) {
149     /// Availability: 3.2
150     mixin(PyAPI_DATA!"PyTypeObject PyClassMethodDescr_Type");
151     /// Availability: 3.2
152     mixin(PyAPI_DATA!"PyTypeObject PyMethodDescr_Type");
153     /// Availability: 3.2
154     mixin(PyAPI_DATA!"PyTypeObject _PyMethodWrapper_Type");
155 }
156 
157 /// _
158 PyObject* PyDescr_NewMethod(PyTypeObject*, PyMethodDef*);
159 /// _
160 PyObject* PyDescr_NewClassMethod(PyTypeObject*, PyMethodDef*);
161 /// _
162 PyObject* PyDescr_NewMember(PyTypeObject*, PyMemberDef*);
163 /// _
164 PyObject* PyDescr_NewGetSet(PyTypeObject*, PyGetSetDef*);
165 /// _
166 PyObject* PyDescr_NewWrapper(PyTypeObject*, wrapperbase*, void*);
167 /// _
168 PyObject* PyDictProxy_New(PyObject*);
169 /// _
170 PyObject* PyWrapper_New(PyObject*, PyObject*);
171 
172 /// _
173 mixin(PyAPI_DATA!"PyTypeObject PyProperty_Type");
174 
175