@@ -112,6 +112,34 @@ class Complete(Structure):
112
112
# This table contains format strings as they look on little endian
113
113
# machines. The test replaces '<' with '>' on big endian machines.
114
114
#
115
+
116
+ # Platform-specific type codes
117
+ s_bool = {1 : '?' , 2 : 'H' , 4 : 'L' , 8 : 'Q' }[sizeof (c_bool )]
118
+ s_short = {2 : 'h' , 4 : 'l' , 8 : 'q' }[sizeof (c_short )]
119
+ s_ushort = {2 : 'H' , 4 : 'L' , 8 : 'Q' }[sizeof (c_ushort )]
120
+ s_int = {2 : 'h' , 4 : 'i' , 8 : 'q' }[sizeof (c_int )]
121
+ s_uint = {2 : 'H' , 4 : 'I' , 8 : 'Q' }[sizeof (c_uint )]
122
+ s_long = {4 : 'l' , 8 : 'q' }[sizeof (c_long )]
123
+ s_ulong = {4 : 'L' , 8 : 'Q' }[sizeof (c_ulong )]
124
+ s_longlong = "q"
125
+ s_ulonglong = "Q"
126
+ s_float = "f"
127
+ s_double = "d"
128
+ s_longdouble = "g"
129
+
130
+ # Alias definitions in ctypes/__init__.py
131
+ if c_int is c_long :
132
+ s_int = s_long
133
+ if c_uint is c_ulong :
134
+ s_uint = s_ulong
135
+ if c_longlong is c_long :
136
+ s_longlong = s_long
137
+ if c_ulonglong is c_ulong :
138
+ s_ulonglong = s_ulong
139
+ if c_longdouble is c_double :
140
+ s_longdouble = s_double
141
+
142
+
115
143
native_types = [
116
144
# type format shape calc itemsize
117
145
@@ -120,60 +148,59 @@ class Complete(Structure):
120
148
(c_char , "<c" , (), c_char ),
121
149
(c_byte , "<b" , (), c_byte ),
122
150
(c_ubyte , "<B" , (), c_ubyte ),
123
- (c_short , "<h" , (), c_short ),
124
- (c_ushort , "<H" , (), c_ushort ),
151
+ (c_short , "<" + s_short , (), c_short ),
152
+ (c_ushort , "<" + s_ushort , (), c_ushort ),
125
153
126
- # c_int and c_uint may be aliases to c_long
127
- #(c_int, "<i", (), c_int),
128
- #(c_uint, "<I", (), c_uint),
154
+ (c_int , "<" + s_int , (), c_int ),
155
+ (c_uint , "<" + s_uint , (), c_uint ),
129
156
130
- (c_long , "<l" , (), c_long ),
131
- (c_ulong , "<L" , (), c_ulong ),
157
+ (c_long , "<" + s_long , (), c_long ),
158
+ (c_ulong , "<" + s_ulong , (), c_ulong ),
132
159
133
- # c_longlong and c_ulonglong are aliases on 64-bit platforms
134
- #(c_longlong, "<q", None, c_longlong),
135
- #(c_ulonglong, "<Q", None, c_ulonglong),
160
+ (c_longlong , "<" + s_longlong , (), c_longlong ),
161
+ (c_ulonglong , "<" + s_ulonglong , (), c_ulonglong ),
136
162
137
163
(c_float , "<f" , (), c_float ),
138
164
(c_double , "<d" , (), c_double ),
139
- # c_longdouble may be an alias to c_double
140
165
141
- (c_bool , "<?" , (), c_bool ),
166
+ (c_longdouble , "<" + s_longdouble , (), c_longdouble ),
167
+
168
+ (c_bool , "<" + s_bool , (), c_bool ),
142
169
(py_object , "<O" , (), py_object ),
143
170
144
171
## pointers
145
172
146
173
(POINTER (c_byte ), "&<b" , (), POINTER (c_byte )),
147
- (POINTER (POINTER (c_long )), "&&<l" , (), POINTER (POINTER (c_long ))),
174
+ (POINTER (POINTER (c_long )), "&&<" + s_long , (), POINTER (POINTER (c_long ))),
148
175
149
176
## arrays and pointers
150
177
151
178
(c_double * 4 , "<d" , (4 ,), c_double ),
152
179
(c_float * 4 * 3 * 2 , "<f" , (2 ,3 ,4 ), c_float ),
153
- (POINTER (c_short ) * 2 , "&<h" , (2 ,), POINTER (c_short )),
154
- (POINTER (c_short ) * 2 * 3 , "&<h" , (3 ,2 ,), POINTER (c_short )),
155
- (POINTER (c_short * 2 ), "&(2)<h" , (), POINTER (c_short )),
180
+ (POINTER (c_short ) * 2 , "&<" + s_short , (2 ,), POINTER (c_short )),
181
+ (POINTER (c_short ) * 2 * 3 , "&<" + s_short , (3 ,2 ,), POINTER (c_short )),
182
+ (POINTER (c_short * 2 ), "&(2)<" + s_short , (), POINTER (c_short )),
156
183
157
184
## structures and unions
158
185
159
- (Point , "T{<l:x:<l:y:}" , (), Point ),
186
+ (Point , "T{<l:x:<l:y:}" . replace ( 'l' , s_long ), (), Point ),
160
187
# packed structures do not implement the pep
161
- (PackedPoint , "B" , (), PackedPoint ),
162
- (Point2 , "T{<l:x:<l:y:}" , (), Point2 ),
163
- (EmptyStruct , "T{}" , (), EmptyStruct ),
188
+ (PackedPoint , "B" , (), PackedPoint ),
189
+ (Point2 , "T{<l:x:<l:y:}" . replace ( 'l' , s_long ), (), Point2 ),
190
+ (EmptyStruct , "T{}" , (), EmptyStruct ),
164
191
# the pep does't support unions
165
- (aUnion , "B" , (), aUnion ),
192
+ (aUnion , "B" , (), aUnion ),
166
193
# structure with sub-arrays
167
- (StructWithArrays , "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}" , ( ), StructWithArrays ),
168
- (StructWithArrays * 3 , "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}" , (3 ,), StructWithArrays ),
194
+ (StructWithArrays , "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}" . replace ( 'l' , s_long ), (), StructWithArrays ),
195
+ (StructWithArrays * 3 , "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}" . replace ( 'l' , s_long ), (3 ,), StructWithArrays ),
169
196
170
197
## pointer to incomplete structure
171
198
(Incomplete , "B" , (), Incomplete ),
172
199
(POINTER (Incomplete ), "&B" , (), POINTER (Incomplete )),
173
200
174
201
# 'Complete' is a structure that starts incomplete, but is completed after the
175
202
# pointer type to it has been created.
176
- (Complete , "T{<l:a:}" , (), Complete ),
203
+ (Complete , "T{<l:a:}" . replace ( 'l' , s_long ), (), Complete ),
177
204
# Unfortunately the pointer format string is not fixed...
178
205
(POINTER (Complete ), "&B" , (), POINTER (Complete )),
179
206
@@ -196,10 +223,10 @@ class LEPoint(LittleEndianStructure):
196
223
# and little endian machines.
197
224
#
198
225
endian_types = [
199
- (BEPoint , "T{>l:x:>l:y:}" , (), BEPoint ),
200
- (LEPoint , "T{<l:x:<l:y:}" , (), LEPoint ),
201
- (POINTER (BEPoint ), "&T{>l:x:>l:y:}" , (), POINTER (BEPoint )),
202
- (POINTER (LEPoint ), "&T{<l:x:<l:y:}" , (), POINTER (LEPoint )),
226
+ (BEPoint , "T{>l:x:>l:y:}" . replace ( 'l' , s_long ), (), BEPoint ),
227
+ (LEPoint , "T{<l:x:<l:y:}" . replace ( 'l' , s_long ), (), LEPoint ),
228
+ (POINTER (BEPoint ), "&T{>l:x:>l:y:}" . replace ( 'l' , s_long ), (), POINTER (BEPoint )),
229
+ (POINTER (LEPoint ), "&T{<l:x:<l:y:}" . replace ( 'l' , s_long ), (), POINTER (LEPoint )),
203
230
]
204
231
205
232
if __name__ == "__main__" :
0 commit comments