summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-07-29 12:33:52 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-07-29 12:33:52 (GMT)
commit9c631a0f71a6c4beb5d29c10602a555e6a33fd12 (patch)
tree96a14618aabd32bdc8e644ffaedf46d3abad6f2a /Lib/ctypes
parentbb1c079657fa8f8f9d7ec537f83b1fed1d9b413c (diff)
downloadcpython-9c631a0f71a6c4beb5d29c10602a555e6a33fd12.zip
cpython-9c631a0f71a6c4beb5d29c10602a555e6a33fd12.tar.gz
cpython-9c631a0f71a6c4beb5d29c10602a555e6a33fd12.tar.bz2
Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
written by Matthieu Gautier.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/test/test_bitfields.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py
index 9ca053d..b39d82c 100644
--- a/Lib/ctypes/test/test_bitfields.py
+++ b/Lib/ctypes/test/test_bitfields.py
@@ -259,5 +259,33 @@ class BitFieldTest(unittest.TestCase):
x.a = 0xFEDCBA9876543211
self.assertEqual(x.a, 0xFEDCBA9876543211)
+ @need_symbol('c_uint32')
+ def test_uint32_swap_little_endian(self):
+ # Issue #23319
+ class Little(LittleEndianStructure):
+ _fields_ = [("a", c_uint32, 24),
+ ("b", c_uint32, 4),
+ ("c", c_uint32, 4)]
+ b = bytearray(4)
+ x = Little.from_buffer(b)
+ x.a = 0xabcdef
+ x.b = 1
+ x.c = 2
+ self.assertEqual(b, b'\xef\xcd\xab\x21')
+
+ @need_symbol('c_uint32')
+ def test_uint32_swap_big_endian(self):
+ # Issue #23319
+ class Big(BigEndianStructure):
+ _fields_ = [("a", c_uint32, 24),
+ ("b", c_uint32, 4),
+ ("c", c_uint32, 4)]
+ b = bytearray(4)
+ x = Big.from_buffer(b)
+ x.a = 0xabcdef
+ x.b = 1
+ x.c = 2
+ self.assertEqual(b, b'\xab\xcd\xef\x12')
+
if __name__ == "__main__":
unittest.main()