Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Explicit cast to HANDLE for Read/WriteConsoleW calls #1342
We have a custom build of Python 2.7 which is built against MSVC 14. We found that Click's windows console functionality was degraded after making the switch the MSVC 14, hitting that explicit
I run into the error using
but run the two in sequence and they both fail:
I may be a very remote corner case, since the MSVC 9 build of Python 2.7.16 and the MSVC 14 build of Python 3.6.8 both work fine.
Stack for reference:
It's a Windows API type which is just a void pointer. The docs for WriteConsoleW/ReadConsoleW say the first argument should be a HANDLE.
If you step through the code
As for why or if it causes the specific behavior I ran into, I'm less sure about. I could wave my hands and say "undefined behavior" but I was hoping someone in the community could say with more conviction.
These are the builds that I tried, and they all seem to work with this patch:
See . The C call expects the first argument to be of type HANDLE. Most Python variants can directly and safely pass the int, but not all. This can cause click to raise OSError with errno 6 (invalid file handle).  https://docs.microsoft.com/en-us/windows/console/writeconsole