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