diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2019-09-25 03:38:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-25 03:38:44 (GMT) |
commit | 12f209eccb1587e8c98057d9c5f865c21f4a16c1 (patch) | |
tree | 7df70abd0d35e4652a0780201ad13462d1c7e717 /Lib/ctypes/test | |
parent | 221fd84703c545408bbb4a6e0b58459651331f5c (diff) | |
download | cpython-12f209eccb1587e8c98057d9c5f865c21f4a16c1.zip cpython-12f209eccb1587e8c98057d9c5f865c21f4a16c1.tar.gz cpython-12f209eccb1587e8c98057d9c5f865c21f4a16c1.tar.bz2 |
bpo-22273: Update ctypes to correctly handle arrays in small structur… (GH-15839)
Diffstat (limited to 'Lib/ctypes/test')
-rw-r--r-- | Lib/ctypes/test/test_structures.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index fda1045..11c194b 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -477,6 +477,47 @@ class StructureTestCase(unittest.TestCase): self.assertEqual(s.first, got.first) self.assertEqual(s.second, got.second) + def test_array_in_struct(self): + # See bpo-22273 + + # These should mirror the structures in Modules/_ctypes/_ctypes_test.c + class Test2(Structure): + _fields_ = [ + ('data', c_ubyte * 16), + ] + + class Test3(Structure): + _fields_ = [ + ('data', c_double * 2), + ] + + s = Test2() + expected = 0 + for i in range(16): + s.data[i] = i + expected += i + dll = CDLL(_ctypes_test.__file__) + func = dll._testfunc_array_in_struct1 + func.restype = c_int + func.argtypes = (Test2,) + result = func(s) + self.assertEqual(result, expected) + # check the passed-in struct hasn't changed + for i in range(16): + self.assertEqual(s.data[i], i) + + s = Test3() + s.data[0] = 3.14159 + s.data[1] = 2.71828 + expected = 3.14159 + 2.71828 + func = dll._testfunc_array_in_struct2 + func.restype = c_double + func.argtypes = (Test3,) + result = func(s) + self.assertEqual(result, expected) + # check the passed-in struct hasn't changed + self.assertEqual(s.data[0], 3.14159) + self.assertEqual(s.data[1], 2.71828) class PointerMemberTestCase(unittest.TestCase): |