bpo-30555: Fix WindowsConsoleIO fails in the presence of fd redirection (GH-1927)
This works by not caching the handle and instead getting the handle from
the file descriptor each time, so that if the actual handle changes by
fd redirection closing/opening the console handle beneath our feet, we
will keep working correctly.
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index 143b41f..e5e2fb1 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -249,10 +249,8 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
if (!Py_LegacyWindowsStdioFlag && sys_stdin == stdin) {
HANDLE hStdIn, hStdErr;
- _Py_BEGIN_SUPPRESS_IPH
- hStdIn = (HANDLE)_get_osfhandle(fileno(sys_stdin));
- hStdErr = (HANDLE)_get_osfhandle(fileno(stderr));
- _Py_END_SUPPRESS_IPH
+ hStdIn = _Py_get_osfhandle_noraise(fileno(sys_stdin));
+ hStdErr = _Py_get_osfhandle_noraise(fileno(stderr));
if (_get_console_type(hStdIn) == 'r') {
fflush(sys_stdout);