mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
6b59e662fa
commit
5e437fb872
10 changed files with 144 additions and 125 deletions
|
@ -13,10 +13,10 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
/* The full definition is in iomodule. We reproduce
|
||||
enough here to get the handle, which is all we want. */
|
||||
enough here to get the fd, which is all we want. */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
HANDLE handle;
|
||||
int fd;
|
||||
} winconsoleio;
|
||||
|
||||
|
||||
|
@ -67,7 +67,10 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
|
|||
prec->Event.KeyEvent.uChar.UnicodeChar = *p;
|
||||
}
|
||||
|
||||
HANDLE hInput = ((winconsoleio*)file)->handle;
|
||||
HANDLE hInput = _Py_get_osfhandle(((winconsoleio*)file)->fd);
|
||||
if (hInput == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
DWORD total = 0;
|
||||
while (total < size) {
|
||||
DWORD wrote;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue