Commit f8019bb
committed
[3.6] 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 87c5024 commit f8019bb
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 | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 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 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
115 | 143 | | |
116 | 144 | | |
117 | 145 | | |
| |||
120 | 148 | | |
121 | 149 | | |
122 | 150 | | |
123 | | - | |
124 | | - | |
| 151 | + | |
| 152 | + | |
125 | 153 | | |
126 | | - | |
127 | | - | |
128 | | - | |
| 154 | + | |
| 155 | + | |
129 | 156 | | |
130 | | - | |
131 | | - | |
| 157 | + | |
| 158 | + | |
132 | 159 | | |
133 | | - | |
134 | | - | |
135 | | - | |
| 160 | + | |
| 161 | + | |
136 | 162 | | |
137 | 163 | | |
138 | 164 | | |
139 | | - | |
140 | 165 | | |
141 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
142 | 169 | | |
143 | 170 | | |
144 | 171 | | |
145 | 172 | | |
146 | 173 | | |
147 | | - | |
| 174 | + | |
148 | 175 | | |
149 | 176 | | |
150 | 177 | | |
151 | 178 | | |
152 | 179 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
156 | 183 | | |
157 | 184 | | |
158 | 185 | | |
159 | | - | |
| 186 | + | |
160 | 187 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
164 | 191 | | |
165 | | - | |
| 192 | + | |
166 | 193 | | |
167 | | - | |
168 | | - | |
| 194 | + | |
| 195 | + | |
169 | 196 | | |
170 | 197 | | |
171 | 198 | | |
172 | 199 | | |
173 | 200 | | |
174 | 201 | | |
175 | 202 | | |
176 | | - | |
| 203 | + | |
177 | 204 | | |
178 | 205 | | |
179 | 206 | | |
| |||
196 | 223 | | |
197 | 224 | | |
198 | 225 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
203 | 230 | | |
204 | 231 | | |
205 | 232 | | |
| |||
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 | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
253 | 318 | | |
254 | 319 | | |
255 | 320 | | |
| |||
1926 | 1991 | | |
1927 | 1992 | | |
1928 | 1993 | | |
1929 | | - | |
| 1994 | + | |
1930 | 1995 | | |
1931 | | - | |
| 1996 | + | |
1932 | 1997 | | |
1933 | 1998 | | |
1934 | 1999 | | |
| |||
0 commit comments