Skip to content

Commit 409f533

Browse files
authored
gh-60580: Fix a wrong type of ctypes.wintypes.BYTE (#97579)
Created from a patch file attached to an issue, by Anatoly Techtonik.
1 parent f2ac951 commit 409f533

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Lib/ctypes/wintypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The most useful windows datatypes
22
import ctypes
33

4-
BYTE = ctypes.c_byte
4+
BYTE = ctypes.c_ubyte
55
WORD = ctypes.c_ushort
66
DWORD = ctypes.c_ulong
77

Lib/test/test_ctypes/test_wintypes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# See <https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types>
2+
# for reference.
3+
14
import unittest
25

36
# also work on POSIX
@@ -38,6 +41,22 @@ def test_variant_bool(self):
3841
vb.value = []
3942
self.assertIs(vb.value, False)
4043

44+
def assertIsSigned(self, ctype):
45+
self.assertLess(ctype(-1).value, 0)
46+
47+
def assertIsUnsigned(self, ctype):
48+
self.assertGreater(ctype(-1).value, 0)
49+
50+
def test_signedness(self):
51+
for ctype in (wintypes.BYTE, wintypes.WORD, wintypes.DWORD,
52+
wintypes.BOOLEAN, wintypes.UINT, wintypes.ULONG):
53+
with self.subTest(ctype=ctype):
54+
self.assertIsUnsigned(ctype)
55+
56+
for ctype in (wintypes.BOOL, wintypes.INT, wintypes.LONG):
57+
with self.subTest(ctype=ctype):
58+
self.assertIsSigned(ctype)
59+
4160

4261
if __name__ == "__main__":
4362
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:data:`ctypes.wintypes.BYTE` definition changed from
2+
:data:`~ctypes.c_byte` to :data:`~ctypes.c_ubyte` to match Windows
3+
SDK. Patch by Anatoly Techtonik and Oleg Iarygin.

0 commit comments

Comments
 (0)