Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fca2866

Browse files
committed
merge 3.3 (#20946)
2 parents ffa1f27 + fda3355 commit fca2866

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

Lib/ctypes/test/test_bitfields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def test_mixed_2(self):
207207
class X(Structure):
208208
_fields_ = [("a", c_byte, 4),
209209
("b", c_int, 32)]
210-
self.assertEqual(sizeof(X), sizeof(c_int)*2)
210+
self.assertEqual(sizeof(X), alignment(c_int)+sizeof(c_int))
211211

212212
def test_mixed_3(self):
213213
class X(Structure):

Lib/ctypes/test/test_structures.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class X(Structure):
8383
class Y(Structure):
8484
_fields_ = [("x", c_char * 3),
8585
("y", c_int)]
86-
self.assertEqual(alignment(Y), calcsize("i"))
86+
self.assertEqual(alignment(Y), alignment(c_int))
8787
self.assertEqual(sizeof(Y), calcsize("3si"))
8888

8989
class SI(Structure):
@@ -175,23 +175,23 @@ class X(Structure):
175175
self.assertEqual(sizeof(X), 10)
176176
self.assertEqual(X.b.offset, 2)
177177

178+
import struct
179+
longlong_size = struct.calcsize("q")
180+
longlong_align = struct.calcsize("bq") - longlong_size
181+
178182
class X(Structure):
179183
_fields_ = [("a", c_byte),
180184
("b", c_longlong)]
181185
_pack_ = 4
182-
self.assertEqual(sizeof(X), 12)
183-
self.assertEqual(X.b.offset, 4)
184-
185-
import struct
186-
longlong_size = struct.calcsize("q")
187-
longlong_align = struct.calcsize("bq") - longlong_size
186+
self.assertEqual(sizeof(X), min(4, longlong_align) + longlong_size)
187+
self.assertEqual(X.b.offset, min(4, longlong_align))
188188

189189
class X(Structure):
190190
_fields_ = [("a", c_byte),
191191
("b", c_longlong)]
192192
_pack_ = 8
193193

194-
self.assertEqual(sizeof(X), longlong_align + longlong_size)
194+
self.assertEqual(sizeof(X), min(8, longlong_align) + longlong_size)
195195
self.assertEqual(X.b.offset, min(8, longlong_align))
196196

197197

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Tests
7272

7373
- Issue #20743: Fix a reference leak in test_tcl.
7474

75+
- Issue #20946: Correct alignment assumptions of some ctypes tests.
76+
7577
- Issue #20939: Fix test_geturl failure in test_urllibnet due to
7678
new redirect of http://www.python.org/ to https://www.python.org.
7779

Modules/_ctypes/cfield.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,9 +1640,9 @@ typedef struct { char c; void *x; } s_void_p;
16401640
/*
16411641
#define CHAR_ALIGN (sizeof(s_char) - sizeof(char))
16421642
#define SHORT_ALIGN (sizeof(s_short) - sizeof(short))
1643-
#define INT_ALIGN (sizeof(s_int) - sizeof(int))
16441643
#define LONG_ALIGN (sizeof(s_long) - sizeof(long))
16451644
*/
1645+
#define INT_ALIGN (sizeof(s_int) - sizeof(int))
16461646
#define FLOAT_ALIGN (sizeof(s_float) - sizeof(float))
16471647
#define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double))
16481648
#define LONGDOUBLE_ALIGN (sizeof(s_long_double) - sizeof(long double))
@@ -1684,8 +1684,8 @@ ffi_type ffi_type_sint8 = { 1, 1, FFI_TYPE_SINT8 };
16841684
ffi_type ffi_type_uint16 = { 2, 2, FFI_TYPE_UINT16 };
16851685
ffi_type ffi_type_sint16 = { 2, 2, FFI_TYPE_SINT16 };
16861686

1687-
ffi_type ffi_type_uint32 = { 4, 4, FFI_TYPE_UINT32 };
1688-
ffi_type ffi_type_sint32 = { 4, 4, FFI_TYPE_SINT32 };
1687+
ffi_type ffi_type_uint32 = { 4, INT_ALIGN, FFI_TYPE_UINT32 };
1688+
ffi_type ffi_type_sint32 = { 4, INT_ALIGN, FFI_TYPE_SINT32 };
16891689

16901690
ffi_type ffi_type_uint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_UINT64 };
16911691
ffi_type ffi_type_sint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_SINT64 };

0 commit comments

Comments
 (0)