diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-01-17 20:11:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-17 20:11:44 (GMT) |
commit | a735fea6b17c45b0dc0f650e59901770074176e1 (patch) | |
tree | 5fb51f984e61fb2ac36f554ae061af518d4c39b3 /Lib/test | |
parent | 01344cfe9e9646b8f53b0ba2a1053d343a66634c (diff) | |
download | cpython-a735fea6b17c45b0dc0f650e59901770074176e1.zip cpython-a735fea6b17c45b0dc0f650e59901770074176e1.tar.gz cpython-a735fea6b17c45b0dc0f650e59901770074176e1.tar.bz2 |
[3.12] gh-105102: Fix nested unions in structures when the system byteorder is the opposite (GH-105106) (GH-114204)
(cherry picked from commit 0b541f64c472976b2fee1ec9919bc7b02a798242)
Co-authored-by: Sheidan <37596668+Sh3idan@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ctypes/test_byteswap.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_ctypes/test_byteswap.py b/Lib/test/test_ctypes/test_byteswap.py index caefb77..44d32ff 100644 --- a/Lib/test/test_ctypes/test_byteswap.py +++ b/Lib/test/test_ctypes/test_byteswap.py @@ -352,5 +352,24 @@ class Test(unittest.TestCase): self.assertEqual(s.point.x, 1) self.assertEqual(s.point.y, 2) + def test_build_struct_union_opposite_system_byteorder(self): + # gh-105102 + if sys.byteorder == "little": + _Structure = BigEndianStructure + _Union = BigEndianUnion + else: + _Structure = LittleEndianStructure + _Union = LittleEndianUnion + + class S1(_Structure): + _fields_ = [("a", c_byte), ("b", c_byte)] + + class U1(_Union): + _fields_ = [("s1", S1), ("ab", c_short)] + + class S2(_Structure): + _fields_ = [("u1", U1), ("c", c_byte)] + + if __name__ == "__main__": unittest.main() |