Commit a8c7223
committed
[2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (pythonGH-31)
Ctypes currently produces wrong pep3118 type codes for several types.
E.g. memoryview(ctypes.c_long()).format gives "<l" on 64-bit platforms,
but it should be "<q" instead for sizeof(c_long) == 8
The problem is that the '<>' endian specification in the struct syntax
also turns on the "standard size" mode, which makes type characters have
a platform-independent meaning, which does not match with the codes used
internally in ctypes. The struct module format syntax also does not
allow specifying native-size non-native-endian items.
This commit adds a converter function that maps the internal ctypes
codes to appropriate struct module standard-size codes in the pep3118
format strings. The tests are modified to check for this..
(cherry picked from commit 07f1658)1 parent 20958e6 commit a8c7223
File tree
3 files changed
+123
-30
lines changed- Lib/ctypes/test
- Misc/NEWS.d/next/Library
- Modules/_ctypes
3 files changed
+123
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
112 | 140 | | |
113 | 141 | | |
114 | 142 | | |
| |||
117 | 145 | | |
118 | 146 | | |
119 | 147 | | |
120 | | - | |
121 | | - | |
| 148 | + | |
| 149 | + | |
122 | 150 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 151 | + | |
| 152 | + | |
126 | 153 | | |
127 | | - | |
128 | | - | |
| 154 | + | |
| 155 | + | |
129 | 156 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 157 | + | |
| 158 | + | |
133 | 159 | | |
134 | 160 | | |
135 | 161 | | |
136 | | - | |
137 | 162 | | |
138 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
139 | 166 | | |
140 | 167 | | |
141 | 168 | | |
142 | 169 | | |
143 | 170 | | |
144 | | - | |
| 171 | + | |
145 | 172 | | |
146 | 173 | | |
147 | 174 | | |
148 | 175 | | |
149 | 176 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
153 | 180 | | |
154 | 181 | | |
155 | 182 | | |
156 | | - | |
| 183 | + | |
157 | 184 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
161 | 188 | | |
162 | | - | |
| 189 | + | |
163 | 190 | | |
164 | | - | |
165 | | - | |
| 191 | + | |
| 192 | + | |
166 | 193 | | |
167 | 194 | | |
168 | 195 | | |
169 | 196 | | |
170 | 197 | | |
171 | 198 | | |
172 | 199 | | |
173 | | - | |
| 200 | + | |
174 | 201 | | |
175 | 202 | | |
176 | 203 | | |
| |||
193 | 220 | | |
194 | 221 | | |
195 | 222 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
200 | 227 | | |
201 | 228 | | |
202 | 229 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
295 | 360 | | |
296 | 361 | | |
297 | 362 | | |
| |||
1999 | 2064 | | |
2000 | 2065 | | |
2001 | 2066 | | |
2002 | | - | |
| 2067 | + | |
2003 | 2068 | | |
2004 | | - | |
| 2069 | + | |
2005 | 2070 | | |
2006 | 2071 | | |
2007 | 2072 | | |
| |||
0 commit comments