From 992436daca4dfe062415049ea84df78b25d4cddb Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Tue, 27 Sep 2022 15:33:03 +0800 Subject: [PATCH 01/10] gh-97588: Some tests to demonstrate the issue --- Lib/test/test_ctypes/test_bitfields.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index dad71a0ba7ee4a..1dc6b5000af426 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -236,6 +236,26 @@ class X(Structure): else: self.assertEqual(sizeof(X), sizeof(c_int) * 2) + def test_mixed_5(self): + class X(Structure): + _fields_ = [ + ('A', c_uint, 1), + ('B', c_ushort, 16)] + a = X() + a.A = 0 + a.B = 1 + self.assertEqual(1, a.B) + + def test_mixed_6(self): + class X(Structure): + _fields_ = [ + ('A', c_ulonglong, 1), + ('B', c_uint, 32)] + a = X() + a.A = 0 + a.B = 1 + self.assertEqual(1, a.B) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): From 6a468835f50637a2d85d043dc1710878c9172685 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 10:23:58 +0800 Subject: [PATCH 02/10] Mark expected failure --- Lib/test/test_ctypes/test_bitfields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 1dc6b5000af426..3909fcdff9bdb8 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -236,6 +236,7 @@ class X(Structure): else: self.assertEqual(sizeof(X), sizeof(c_int) * 2) + @unittest.expectedFailure def test_mixed_5(self): class X(Structure): _fields_ = [ @@ -246,6 +247,7 @@ class X(Structure): a.B = 1 self.assertEqual(1, a.B) + @unittest.expectedFailure def test_mixed_6(self): class X(Structure): _fields_ = [ From 3a03cb8183200417b56ae4fd31ab9fd9b68c4a2f Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 10:26:09 +0800 Subject: [PATCH 03/10] Mention the issue --- Lib/test/test_ctypes/test_bitfields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 3909fcdff9bdb8..6791c212b715bb 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -236,7 +236,7 @@ class X(Structure): else: self.assertEqual(sizeof(X), sizeof(c_int) * 2) - @unittest.expectedFailure + @unittest.expectedFailure # gh-97588 def test_mixed_5(self): class X(Structure): _fields_ = [ @@ -247,7 +247,7 @@ class X(Structure): a.B = 1 self.assertEqual(1, a.B) - @unittest.expectedFailure + @unittest.expectedFailure # gh-97588 def test_mixed_6(self): class X(Structure): _fields_ = [ From 0aa3a000979c797ba2aa0867f041a8ccd4cdc32a Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 11:11:50 +0800 Subject: [PATCH 04/10] Doesn't fail on Windows --- Lib/test/test_ctypes/test_bitfields.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 6791c212b715bb..29202eaa35fdfa 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -3,6 +3,7 @@ from test import support import unittest import os +import sys import _ctypes_test @@ -236,6 +237,7 @@ class X(Structure): else: self.assertEqual(sizeof(X), sizeof(c_int) * 2) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") @unittest.expectedFailure # gh-97588 def test_mixed_5(self): class X(Structure): @@ -247,6 +249,7 @@ class X(Structure): a.B = 1 self.assertEqual(1, a.B) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") @unittest.expectedFailure # gh-97588 def test_mixed_6(self): class X(Structure): From f41e7cceb3b13eeb0bf3fc3e8e3f5c006dc66b44 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 13:17:22 +0800 Subject: [PATCH 05/10] Test for alignment boundary --- Lib/test/test_ctypes/test_bitfields.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 29202eaa35fdfa..2008f10563dc88 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -261,6 +261,16 @@ class X(Structure): a.B = 1 self.assertEqual(1, a.B) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") + @unittest.expectedFailure # gh-97588 + def test_mixed_7(self): + class X(Structure): + _fields_ = [ + ("_", c_uint), + ('A', c_uint, 20), + ('B', c_ulonglong, 24)] + self.assertEqual(16, sizeof(X)) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): From a77b849dee6816077d277483f2cb1135c7d56eb5 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 13:17:48 +0800 Subject: [PATCH 06/10] Rename variables --- Lib/test/test_ctypes/test_bitfields.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 2008f10563dc88..22d8d49c5704bf 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -266,9 +266,9 @@ class X(Structure): def test_mixed_7(self): class X(Structure): _fields_ = [ - ("_", c_uint), - ('A', c_uint, 20), - ('B', c_ulonglong, 24)] + ("A", c_uint), + ('B', c_uint, 20), + ('C', c_ulonglong, 24)] self.assertEqual(16, sizeof(X)) def test_anon_bitfields(self): From 923d1efe3d6e550749e91eccd09ed37c39efd15c Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 13:33:56 +0800 Subject: [PATCH 07/10] More failures --- Lib/test/test_ctypes/test_bitfields.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 22d8d49c5704bf..067f25842caf5b 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -271,6 +271,24 @@ class X(Structure): ('C', c_ulonglong, 24)] self.assertEqual(16, sizeof(X)) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") + @unittest.expectedFailure # gh-97588 + def test_mixed_8(self): + class Foo(Structure): + _fields_ = [ + ("A", c_uint), + ("B", c_uint, 32), + ("C", c_ulonglong, 1), + ] + + class Bar(Structure): + _fields_ = [ + ("A", c_uint), + ("B", c_uint), + ("C", c_ulonglong, 1), + ] + self.assertEqual(sizeof(Foo), sizeof(Bar)) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): From dd7ddd48f48e40c00a04dea7834493cb4b7bf30e Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 13:43:11 +0800 Subject: [PATCH 08/10] More failures --- Lib/test/test_ctypes/test_bitfields.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 067f25842caf5b..347a73dad65263 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -289,6 +289,16 @@ class Bar(Structure): ] self.assertEqual(sizeof(Foo), sizeof(Bar)) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") + @unittest.expectedFailure # gh-97588 + def test_mixed_9(self): + class X(Structure): + _fields_ = [ + ("A", c_uint8), + ("B", c_uint, 1), + ] + self.assertEqual(4, sizeof(X)) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure): From e5dfe884a0bf4959a87c743cd4eb58e6bfd16f9d Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 30 Sep 2022 07:16:02 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/C API/2022-09-30-07-16-00.gh-issue-97588.yQFteB.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/C API/2022-09-30-07-16-00.gh-issue-97588.yQFteB.rst diff --git a/Misc/NEWS.d/next/C API/2022-09-30-07-16-00.gh-issue-97588.yQFteB.rst b/Misc/NEWS.d/next/C API/2022-09-30-07-16-00.gh-issue-97588.yQFteB.rst new file mode 100644 index 00000000000000..e781a475fcc796 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-09-30-07-16-00.gh-issue-97588.yQFteB.rst @@ -0,0 +1 @@ +Add failing tests to document problems with ctypes structs. From ed2e932acf8e426f724d041c69da342691e73422 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Fri, 30 Sep 2022 20:42:40 +0800 Subject: [PATCH 10/10] More failures --- Lib/test/test_ctypes/test_bitfields.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_ctypes/test_bitfields.py b/Lib/test/test_ctypes/test_bitfields.py index 347a73dad65263..a5d1e2645c2631 100644 --- a/Lib/test/test_ctypes/test_bitfields.py +++ b/Lib/test/test_ctypes/test_bitfields.py @@ -299,6 +299,17 @@ class X(Structure): ] self.assertEqual(4, sizeof(X)) + @unittest.skipIf(sys.platform == 'win32', "Doesn't fail on Windows") + @unittest.expectedFailure # gh-97588 + def test_mixed_10(self): + class X(Structure): + _fields_ = [ + ("A", c_uint32, 1), + ("B", c_uint64, 1), + ] + self.assertEqual(8, alignment(X)) + self.assertEqual(8, sizeof(X)) + def test_anon_bitfields(self): # anonymous bit-fields gave a strange error message class X(Structure):