Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Lib/ctypes/test/test_pep3118.py

Issue 10744: ctypes arrays have incorrect buffer information (PEP-3118)
Patch Set: Created 5 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/_ctypes/_ctypes.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 from ctypes import * 2 from ctypes import *
3 import re, struct, sys 3 import re, struct, sys
4 4
5 if sys.byteorder == "little": 5 if sys.byteorder == "little":
6 THIS_ENDIAN = "<" 6 THIS_ENDIAN = "<"
7 OTHER_ENDIAN = ">" 7 OTHER_ENDIAN = ">"
8 else: 8 else:
9 THIS_ENDIAN = ">" 9 THIS_ENDIAN = ">"
10 OTHER_ENDIAN = "<" 10 OTHER_ENDIAN = "<"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 class Point2(Structure): 89 class Point2(Structure):
90 pass 90 pass
91 Point2._fields_ = [("x", c_long), ("y", c_long)] 91 Point2._fields_ = [("x", c_long), ("y", c_long)]
92 92
93 class EmptyStruct(Structure): 93 class EmptyStruct(Structure):
94 _fields_ = [] 94 _fields_ = []
95 95
96 class aUnion(Union): 96 class aUnion(Union):
97 _fields_ = [("a", c_int)] 97 _fields_ = [("a", c_int)]
98
99 class StructWithArrays(Structure):
100 _fields_ = [("x", c_long * 3 * 2), ("y", Point * 4)]
98 101
99 class Incomplete(Structure): 102 class Incomplete(Structure):
100 pass 103 pass
101 104
102 class Complete(Structure): 105 class Complete(Structure):
103 pass 106 pass
104 PComplete = POINTER(Complete) 107 PComplete = POINTER(Complete)
105 Complete._fields_ = [("a", c_long)] 108 Complete._fields_ = [("a", c_long)]
106 109
107 ################################################################ 110 ################################################################
(...skipping 30 matching lines...) Expand all
138 (c_bool, "<?", (), c_bool), 141 (c_bool, "<?", (), c_bool),
139 (py_object, "<O", (), py_object) , 142 (py_object, "<O", (), py_object) ,
140 143
141 ## pointers 144 ## pointers
142 145
143 (POINTER(c_byte), "&<b", (), POINTER(c_ byte)), 146 (POINTER(c_byte), "&<b", (), POINTER(c_ byte)),
144 (POINTER(POINTER(c_long)), "&&<l", (), POINTER(PO INTER(c_long))), 147 (POINTER(POINTER(c_long)), "&&<l", (), POINTER(PO INTER(c_long))),
145 148
146 ## arrays and pointers 149 ## arrays and pointers
147 150
148 (c_double * 4, "(4)<d", (4,), c_double ), 151 (c_double * 4, "<d", (4,), c_double ),
149 (c_float * 4 * 3 * 2, "(2,3,4)<f", (2,3,4), c_float) , 152 (c_float * 4 * 3 * 2, "<f", (2,3,4), c_float) ,
150 (POINTER(c_short) * 2, "(2)&<h", (2,), POINTER( c_short)), 153 (POINTER(c_short) * 2, "&<h", (2,), POINTER( c_short)),
151 (POINTER(c_short) * 2 * 3, "(3,2)&<h", (3,2,), POINTER( c_short)), 154 (POINTER(c_short) * 2 * 3, "&<h", (3,2,), POINTER( c_short)),
152 (POINTER(c_short * 2), "&(2)<h", (), POINTER(c_ short)), 155 (POINTER(c_short * 2), "&(2)<h", (), POINTER(c_ short)),
153 156
154 ## structures and unions 157 ## structures and unions
155 158
156 (Point, "T{<l:x:<l:y:}", (), Point), 159 (Point, "T{<l:x:<l:y:}", (), Point),
157 # packed structures do not implement the pep 160 # packed structures do not implement the pep
158 (PackedPoint, "B", (), PackedPoin t), 161 (PackedPoint, "B", (), PackedPoin t),
159 (Point2, "T{<l:x:<l:y:}", (), Point2), 162 (Point2, "T{<l:x:<l:y:}", (), Point2),
160 (EmptyStruct, "T{}", (), EmptyStruc t), 163 (EmptyStruct, "T{}", (), EmptyStruc t),
161 # the pep does't support unions 164 # the pep does't support unions
162 (aUnion, "B", (), aUnion), 165 (aUnion, "B", (), aUnion),
166 # structure with sub-arrays
167 (StructWithArrays, "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}", (), StructW ithArrays),
168 (StructWithArrays * 3, "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}", (3,), Struc tWithArrays),
163 169
164 ## pointer to incomplete structure 170 ## pointer to incomplete structure
165 (Incomplete, "B", (), Incomplete ), 171 (Incomplete, "B", (), Incomplete ),
166 (POINTER(Incomplete), "&B", (), POINTER(In complete)), 172 (POINTER(Incomplete), "&B", (), POINTER(In complete)),
167 173
168 # 'Complete' is a structure that starts incomplete, but is completed after t he 174 # 'Complete' is a structure that starts incomplete, but is completed after t he
169 # pointer type to it has been created. 175 # pointer type to it has been created.
170 (Complete, "T{<l:a:}", (), Complete), 176 (Complete, "T{<l:a:}", (), Complete),
171 # Unfortunately the pointer format string is not fixed... 177 # Unfortunately the pointer format string is not fixed...
172 (POINTER(Complete), "&B", (), POINTER(Co mplete)), 178 (POINTER(Complete), "&B", (), POINTER(Co mplete)),
(...skipping 18 matching lines...) Expand all
191 # 197 #
192 endian_types = [ 198 endian_types = [
193 (BEPoint, "T{>l:x:>l:y:}", (), BEPoint), 199 (BEPoint, "T{>l:x:>l:y:}", (), BEPoint),
194 (LEPoint, "T{<l:x:<l:y:}", (), LEPoint), 200 (LEPoint, "T{<l:x:<l:y:}", (), LEPoint),
195 (POINTER(BEPoint), "&T{>l:x:>l:y:}", (), POINTER(BE Point)), 201 (POINTER(BEPoint), "&T{>l:x:>l:y:}", (), POINTER(BE Point)),
196 (POINTER(LEPoint), "&T{<l:x:<l:y:}", (), POINTER(LE Point)), 202 (POINTER(LEPoint), "&T{<l:x:<l:y:}", (), POINTER(LE Point)),
197 ] 203 ]
198 204
199 if __name__ == "__main__": 205 if __name__ == "__main__":
200 unittest.main() 206 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | Modules/_ctypes/_ctypes.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+