Skip to content

Conversation

jkloth
Copy link
Contributor

@jkloth jkloth commented Mar 23, 2022

The second part of the fix for negative timeouts.

This PR should not be backported for the reasons I state here: #32079 (comment)
To further emphasize this, see the additional change required in this PR for use of -1 to denote INFINITE.

https://bugs.python.org/issue46716

@eryksun
Copy link
Contributor

eryksun commented Mar 24, 2022

Maybe we should start to gradually add test cases for _winapi in "Lib/test/test_os.py", even if it's only an internal module. For example:

@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
class Win32APITests(unittest.TestCase):

    def test_dword_convert_negative(self):
        with self.assertRaises(ValueError):
            for h in _winapi.CreatePipe(None, -1):
                _winapi.CloseHandle(h)

    def test_dword_convert_overflow(self):
        with self.assertRaises(OverflowError):
            for h in _winapi.CreatePipe(None, 1 << 32):
                _winapi.CloseHandle(h)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

The DWORD converter is also used in winreg.c and overlapped.c.

Comment on lines +212 to +213
class DWORD_converter(unsigned_long_converter):
type = 'DWORD'
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants