diff options
| author | Steve Dower <steve.dower@microsoft.com> | 2015-03-07 18:14:07 -0800 |
|---|---|---|
| committer | Steve Dower <steve.dower@microsoft.com> | 2015-03-07 18:14:07 -0800 |
| commit | 8acde7dccebd914ec4235f3ed1e9eef53a300978 (patch) | |
| tree | 3af6da4a9ba7c3da9f4c1e8bb3fbcfc2c4bd08b6 | |
| parent | 35a97c0bed8af6cab7ea0fffe374c3369561c444 (diff) | |
| download | cpython-git-8acde7dccebd914ec4235f3ed1e9eef53a300978.tar.gz | |
Issue #23524: Change back to using Windows errors for _Py_fstat instead of the errno shim.
| -rw-r--r-- | Modules/_io/fileio.c | 8 | ||||
| -rw-r--r-- | Modules/signalmodule.c | 2 | ||||
| -rw-r--r-- | Python/fileutils.c | 8 |
3 files changed, 13 insertions, 5 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index ab9eb8c061..0f226eafbf 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -182,7 +182,13 @@ check_fd(int fd) { #if defined(HAVE_FSTAT) || defined(MS_WINDOWS) struct _Py_stat_struct buf; - if (_Py_fstat(fd, &buf) < 0 && errno == EBADF) { + if (_Py_fstat(fd, &buf) < 0 && +#ifdef MS_WINDOWS + GetLastError() == ERROR_INVALID_HANDLE +#else + errno == EBADF +#endif + ) { PyObject *exc; char *msg = strerror(EBADF); exc = PyObject_CallFunction(PyExc_OSError, "(is)", diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 598bc8a342..3ad8ebb8cd 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -560,7 +560,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args) } if (_Py_fstat(fd, &st) != 0) { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetExcFromWindowsErr(PyExc_OSError, GetLastError()); return NULL; } diff --git a/Python/fileutils.c b/Python/fileutils.c index c0dbc86a93..6502823535 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -637,10 +637,14 @@ _Py_fstat(int fd, struct _Py_stat_struct *result) else h = (HANDLE)_get_osfhandle(fd); + /* Protocol violation: we explicitly clear errno, instead of + setting it to a POSIX error. Callers should use GetLastError. */ errno = 0; if (h == INVALID_HANDLE_VALUE) { - errno = EBADF; + /* This is really a C library error (invalid file handle). + We set the Win32 error to the closes one matching. */ + SetLastError(ERROR_INVALID_HANDLE); return -1; } memset(result, 0, sizeof(*result)); @@ -649,7 +653,6 @@ _Py_fstat(int fd, struct _Py_stat_struct *result) if (type == FILE_TYPE_UNKNOWN) { DWORD error = GetLastError(); if (error != 0) { - errno = EINVAL; return -1; } /* else: valid but unknown file */ @@ -664,7 +667,6 @@ _Py_fstat(int fd, struct _Py_stat_struct *result) } if (!GetFileInformationByHandle(h, &info)) { - errno = EINVAL; return -1; } |
