Skip to content

bpo-46716: Use strict unsigned long conversion for DWORD values #32081

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Lib/test/libregrtest/win_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ def close(self, kill=True):
def __del__(self,
# localize module access to prevent shutdown errors
_wait=_winapi.WaitForSingleObject,
_timeout=_winapi.INFINITE,
_close=_winapi.CloseHandle,
_signal=_overlapped.SetEvent):
if self._running is not None:
# tell the update thread to quit
_signal(self._running)
# wait for the update thread to signal done
_wait(self._stopped, -1)
_wait(self._stopped, _timeout)
# cleanup events
_close(self._running)
_close(self._stopped)
Expand Down
6 changes: 4 additions & 2 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ create_converter('LPSECURITY_ATTRIBUTES', '" F_POINTER "')
create_converter('LPCVOID', '" F_POINTER "')

create_converter('BOOL', 'i') # F_BOOL used previously (always 'i')
create_converter('DWORD', 'k') # F_DWORD is always "k" (which is much shorter)
create_converter('LPCTSTR', 's')
create_converter('UINT', 'I') # F_UINT used previously (always 'I')

Expand All @@ -210,6 +209,9 @@ class HANDLE_return_converter(CReturnConverter):
data.return_conversion.append(
'return_value = HANDLE_TO_PYNUM(_return_value);\n')

class DWORD_converter(unsigned_long_converter):
type = 'DWORD'
Comment on lines +212 to +213
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use DWORD(bitwise=True) instead of DWORD in places where you want to keep the old behavior.

Or you can define non-strict by default completely compatible converter:

class DWORD_converter(unsigned_long_converter):
    type = 'DWORD'

    def converter_init(self, *, bitwise: bool = True) -> None:
        super().converter_init(bitwise=bitwise)

and use DWORD(bitwise=False) if you need a strict conversion.


class DWORD_return_converter(CReturnConverter):
type = 'DWORD'

Expand All @@ -228,7 +230,7 @@ class LPVOID_return_converter(CReturnConverter):
data.return_conversion.append(
'return_value = HANDLE_TO_PYNUM(_return_value);\n')
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=011ee0c3a2244bfe]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=84937c7280ba273d]*/

#include "clinic/_winapi.c.h"

Expand Down
59 changes: 31 additions & 28 deletions Modules/clinic/_winapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.