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
|
@ -1370,13 +1370,10 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
|||
*/
|
||||
if (fileno != -1 && fileno != 0) {
|
||||
/* Ensure that fileno is within the CRT's valid range */
|
||||
_Py_BEGIN_SUPPRESS_IPH
|
||||
fh = (HANDLE)_get_osfhandle(fileno);
|
||||
_Py_END_SUPPRESS_IPH
|
||||
if (fh==(HANDLE)-1) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
fh = _Py_get_osfhandle(fileno);
|
||||
if (fh == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Win9x appears to need us seeked to zero */
|
||||
lseek(fileno, 0, SEEK_SET);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue