[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (ctypes)

victor.stinner python-checkins at python.org
Wed Jul 29 14:36:17 CEST 2015


https://hg.python.org/cpython/rev/803a83dd3c9c
changeset: 97121:803a83dd3c9c
parent: 97118:1f4ef305b658
parent: 97120:883d2443941e
user: Victor Stinner <victor.stinner at gmail.com>
date: Wed Jul 29 14:36:03 2015 +0200
summary:
 Merge 3.5 (ctypes)
files:
 Lib/ctypes/test/test_bitfields.py | 28 +++++++++++++++++++
 Misc/NEWS | 3 ++
 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
--- a/Lib/ctypes/test/test_bitfields.py
+++ b/Lib/ctypes/test/test_bitfields.py
@@ -259,5 +259,33 @@
 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()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 Library
 -------
 
+- Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
+ written by Matthieu Gautier.
+
 - Issue #19450: Update Windows and OS X installer builds to use SQLite 3.8.11.
 
 - Issue #23254: Document how to close the TCPServer listening socket.
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -765,6 +765,7 @@
 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));
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /