summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Iarygin <oleg@arhadthedev.net>2023-01-26 14:16:27 (GMT)
committerGitHub <noreply@github.com>2023-01-26 14:16:27 (GMT)
commit409f5337a3e466a5ef673797575cbd1745d27ca9 (patch)
tree0c9ffc5b555865b423a0a7bf45a0f43271ec964b
parentf2ac9510a5aa4f71d468f486140eae60f46833ad (diff)
downloadcpython-409f5337a3e466a5ef673797575cbd1745d27ca9.zip
cpython-409f5337a3e466a5ef673797575cbd1745d27ca9.tar.gz
cpython-409f5337a3e466a5ef673797575cbd1745d27ca9.tar.bz2
gh-60580: Fix a wrong type of `ctypes.wintypes.BYTE` (#97579)
Created from a patch file attached to an issue, by Anatoly Techtonik.
-rw-r--r--Lib/ctypes/wintypes.py2
-rw-r--r--Lib/test/test_ctypes/test_wintypes.py19
-rw-r--r--Misc/NEWS.d/next/Library/2022-09-26-21-18-47.gh-issue-60580.0hBgde.rst3
3 files changed, 23 insertions, 1 deletions
diff --git a/Lib/ctypes/wintypes.py b/Lib/ctypes/wintypes.py
index c619d27..9c4e721 100644
--- a/Lib/ctypes/wintypes.py
+++ b/Lib/ctypes/wintypes.py
@@ -1,7 +1,7 @@
# The most useful windows datatypes
import ctypes
-BYTE = ctypes.c_byte
+BYTE = ctypes.c_ubyte
WORD = ctypes.c_ushort
DWORD = ctypes.c_ulong
diff --git a/Lib/test/test_ctypes/test_wintypes.py b/Lib/test/test_ctypes/test_wintypes.py
index 243d596..a01b9b1 100644
--- a/Lib/test/test_ctypes/test_wintypes.py
+++ b/Lib/test/test_ctypes/test_wintypes.py
@@ -1,3 +1,6 @@
+# See <https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types>
+# for reference.
+
import unittest
# also work on POSIX
@@ -38,6 +41,22 @@ class WinTypesTest(unittest.TestCase):
vb.value = []
self.assertIs(vb.value, False)
+ def assertIsSigned(self, ctype):
+ self.assertLess(ctype(-1).value, 0)
+
+ def assertIsUnsigned(self, ctype):
+ self.assertGreater(ctype(-1).value, 0)
+
+ def test_signedness(self):
+ for ctype in (wintypes.BYTE, wintypes.WORD, wintypes.DWORD,
+ wintypes.BOOLEAN, wintypes.UINT, wintypes.ULONG):
+ with self.subTest(ctype=ctype):
+ self.assertIsUnsigned(ctype)
+
+ for ctype in (wintypes.BOOL, wintypes.INT, wintypes.LONG):
+ with self.subTest(ctype=ctype):
+ self.assertIsSigned(ctype)
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2022-09-26-21-18-47.gh-issue-60580.0hBgde.rst b/Misc/NEWS.d/next/Library/2022-09-26-21-18-47.gh-issue-60580.0hBgde.rst
new file mode 100644
index 0000000..630e56c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-09-26-21-18-47.gh-issue-60580.0hBgde.rst
@@ -0,0 +1,3 @@
+:data:`ctypes.wintypes.BYTE` definition changed from
+:data:`~ctypes.c_byte` to :data:`~ctypes.c_ubyte` to match Windows
+SDK. Patch by Anatoly Techtonik and Oleg Iarygin.