diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-07-29 12:35:12 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-07-29 12:35:12 (GMT) |
commit | 5ef6fde92c76df03455481bb1f4d6f2125c9e3ac (patch) | |
tree | cc58f12d5000ecb5477b7615ccf664171e8bc851 | |
parent | e0374c7a03a2876815f96e759bbf2093601b7207 (diff) | |
parent | 9c631a0f71a6c4beb5d29c10602a555e6a33fd12 (diff) | |
download | cpython-5ef6fde92c76df03455481bb1f4d6f2125c9e3ac.zip cpython-5ef6fde92c76df03455481bb1f4d6f2125c9e3ac.tar.gz cpython-5ef6fde92c76df03455481bb1f4d6f2125c9e3ac.tar.bz2 |
Merge 3.4 (ctypes)
-rw-r--r-- | Lib/ctypes/test/test_bitfields.py | 28 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 1 |
3 files changed, 32 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() @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch + written by Matthieu Gautier. + - Issue #23254: Document how to close the TCPServer listening socket. Patch from Martin Panter. diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 4bd022d..3c7a52a 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -765,6 +765,7 @@ I_set_sw(void *ptr, PyObject *value, Py_ssize_t size) if (get_ulong(value, &val) < 0) return NULL; memcpy(&field, ptr, sizeof(field)); + field = SWAP_INT(field); field = SET(unsigned int, field, (unsigned int)val, size); field = SWAP_INT(field); memcpy(ptr, &field, sizeof(field)); |