summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-03-16 09:07:26 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-03-16 09:07:26 (GMT)
commitfda33559dcad6f9595eefec8afc326e5ac0c81c5 (patch)
tree5dfc87ec636c9fb5f18d44f222be0c75393e8f09 /Lib/ctypes
parent790bf0db77da018376b50c70b68a48a4a81cf444 (diff)
downloadcpython-fda33559dcad6f9595eefec8afc326e5ac0c81c5.zip
cpython-fda33559dcad6f9595eefec8afc326e5ac0c81c5.tar.gz
cpython-fda33559dcad6f9595eefec8afc326e5ac0c81c5.tar.bz2
fix ctypes test alignment assumptions (closes #20946)
Patch by Andreas Schwab.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/test/test_bitfields.py2
-rw-r--r--Lib/ctypes/test/test_structures.py16
2 files changed, 9 insertions, 9 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py
index c89ee34..77de606 100644
--- a/Lib/ctypes/test/test_bitfields.py
+++ b/Lib/ctypes/test/test_bitfields.py
@@ -207,7 +207,7 @@ class BitFieldTest(unittest.TestCase):
class X(Structure):
_fields_ = [("a", c_byte, 4),
("b", c_int, 32)]
- self.assertEqual(sizeof(X), sizeof(c_int)*2)
+ self.assertEqual(sizeof(X), alignment(c_int)+sizeof(c_int))
def test_mixed_3(self):
class X(Structure):
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index 61b9fe7..87613ad 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -83,7 +83,7 @@ class StructureTestCase(unittest.TestCase):
class Y(Structure):
_fields_ = [("x", c_char * 3),
("y", c_int)]
- self.assertEqual(alignment(Y), calcsize("i"))
+ self.assertEqual(alignment(Y), alignment(c_int))
self.assertEqual(sizeof(Y), calcsize("3si"))
class SI(Structure):
@@ -175,23 +175,23 @@ class StructureTestCase(unittest.TestCase):
self.assertEqual(sizeof(X), 10)
self.assertEqual(X.b.offset, 2)
+ import struct
+ longlong_size = struct.calcsize("q")
+ longlong_align = struct.calcsize("bq") - longlong_size
+
class X(Structure):
_fields_ = [("a", c_byte),
("b", c_longlong)]
_pack_ = 4
- self.assertEqual(sizeof(X), 12)
- self.assertEqual(X.b.offset, 4)
-
- import struct
- longlong_size = struct.calcsize("q")
- longlong_align = struct.calcsize("bq") - longlong_size
+ self.assertEqual(sizeof(X), min(4, longlong_align) + longlong_size)
+ self.assertEqual(X.b.offset, min(4, longlong_align))
class X(Structure):
_fields_ = [("a", c_byte),
("b", c_longlong)]
_pack_ = 8
- self.assertEqual(sizeof(X), longlong_align + longlong_size)
+ self.assertEqual(sizeof(X), min(8, longlong_align) + longlong_size)
self.assertEqual(X.b.offset, min(8, longlong_align))