/Tools/unicode/python-mappings/diff/

with ctypes in error messages * change back from ctypes instance to ctype instance (cherry picked from commit 1bea762d9ec823544c530d567330a47f64d93d4f) --- Lib/ctypes/test/test_frombuffer.py | 9 +++++++++ Lib/ctypes/test/test_funcptr.py | 5 +++++ Lib/ctypes/test/test_parameters.py | 10 ++++++++++ Lib/ctypes/test/test_pointers.py | 5 +++++ Lib/ctypes/test/test_struct_fields.py | 24 ++++++++++++++++++++++++ Modules/_ctypes/_ctypes.c | 31 ++++++++++++++++++++++++------- Modules/_ctypes/cfield.c | 12 ++++++++++-- 7 files changed, 87 insertions(+), 9 deletions(-) diff --git a/Lib/ctypes/test/test_frombuffer.py b/Lib/ctypes/test/test_frombuffer.py index 7ab38f1..55c2443 100644 --- a/Lib/ctypes/test/test_frombuffer.py +++ b/Lib/ctypes/test/test_frombuffer.py @@ -121,12 +121,21 @@ class Test(unittest.TestCase): (c_int * 1).from_buffer_copy(a, 16 * sizeof(c_int)) def test_abstract(self): + from ctypes import _Pointer, _SimpleCData, _CFuncPtr + self.assertRaises(TypeError, Array.from_buffer, bytearray(10)) self.assertRaises(TypeError, Structure.from_buffer, bytearray(10)) self.assertRaises(TypeError, Union.from_buffer, bytearray(10)) + self.assertRaises(TypeError, _CFuncPtr.from_buffer, bytearray(10)) + self.assertRaises(TypeError, _Pointer.from_buffer, bytearray(10)) + self.assertRaises(TypeError, _SimpleCData.from_buffer, bytearray(10)) + self.assertRaises(TypeError, Array.from_buffer_copy, b"123") self.assertRaises(TypeError, Structure.from_buffer_copy, b"123") self.assertRaises(TypeError, Union.from_buffer_copy, b"123") + self.assertRaises(TypeError, _CFuncPtr.from_buffer_copy, b"123") + self.assertRaises(TypeError, _Pointer.from_buffer_copy, b"123") + self.assertRaises(TypeError, _SimpleCData.from_buffer_copy, b"123") if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_funcptr.py b/Lib/ctypes/test/test_funcptr.py index f34734b..e0b9b54 100644 --- a/Lib/ctypes/test/test_funcptr.py +++ b/Lib/ctypes/test/test_funcptr.py @@ -123,5 +123,10 @@ class CFuncPtrTestCase(unittest.TestCase): self.assertEqual(strtok(None, b"\n"), b"c") self.assertEqual(strtok(None, b"\n"), None) + def test_abstract(self): + from ctypes import _CFuncPtr + + self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid") + if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py index a61f1c7..e4c25fd 100644 --- a/Lib/ctypes/test/test_parameters.py +++ b/Lib/ctypes/test/test_parameters.py @@ -170,6 +170,16 @@ class SimpleTypesTestCase(unittest.TestCase): # ArgumentError: argument 1: ValueError: 99 self.assertRaises(ArgumentError, func, 99) + def test_abstract(self): + from ctypes import (Array, Structure, Union, _Pointer, + _SimpleCData, _CFuncPtr) + + self.assertRaises(TypeError, Array.from_param, 42) + self.assertRaises(TypeError, Structure.from_param, 42) + self.assertRaises(TypeError, Union.from_param, 42) + self.assertRaises(TypeError, _CFuncPtr.from_param, 42) + self.assertRaises(TypeError, _Pointer.from_param, 42) + self.assertRaises(TypeError, _SimpleCData.from_param, 42) @test.support.cpython_only def test_issue31311(self): diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py index 751f85f..e975158 100644 --- a/Lib/ctypes/test/test_pointers.