Skip to content

gh-60580: Fix a wrong type of ctypes.wintypes.BYTE #97579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/ctypes/wintypes.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_ctypes/test_wintypes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,6 +41,22 @@ def test_variant_bool(self):
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()
Original file line number Diff line number Diff line change
@@ -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.