cpython: 8c978cbe057c (original) (raw)
Mercurial > cpython
changeset 99470:8c978cbe057c
Issue #25717: Merge fstat() fix from 3.5 [#25717]
Martin Panter vadmium+py@gmail.com | |
---|---|
date | Sun, 06 Dec 2015 03:29:54 +0000 |
parents | 0c9095566f21(current diff)20ea12222b0e(diff) |
children | 50a99be891bc |
files | Misc/NEWS |
diffstat | 2 files changed, 31 insertions(+), 12 deletions(-)[+] [-] Misc/NEWS 4 Modules/_io/fileio.c 39 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -109,6 +109,10 @@ Core and Builtins Library ------- +- Issue #25717: Restore the previous behaviour of tolerating most fstat()
- errors when opening files. This was a regression in 3.5a1, and stopped
- anonymous temporary files from working in special cases. +
- Issue #24903: Fix regression in number of arguments compileall accepts when '-d' is specified. The check on the number of arguments has been dropped completely as it never worked correctly anyway.
--- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -250,6 +250,7 @@ static int int *atomic_flag_works = NULL; #endif struct _Py_stat_struct fdfstat;
- int fstat_result; int async_err = 0; assert(PyFileIO_Check(self)); @@ -438,22 +439,36 @@ static int } self->blksize = DEFAULT_BUFFER_SIZE;
- Py_BEGIN_ALLOW_THREADS
- fstat_result = _Py_fstat_noraise(self->fd, &fdfstat);
- Py_END_ALLOW_THREADS
- if (fstat_result < 0) {
if (GetLastError() == ERROR_INVALID_HANDLE) {[](#l2.22)
PyErr_SetFromWindowsErr(0);[](#l2.23)
if (errno == EBADF) {[](#l2.25)
PyErr_SetFromErrno(PyExc_OSError);[](#l2.26)
#if defined(S_ISDIR) && defined(EISDIR)
- /* On Unix, open will succeed for directories.
In Python, there should be no file objects referring to[](#l2.34)
directories, so we need a check. */[](#l2.35)
- if (S_ISDIR(fdfstat.st_mode)) {
errno = EISDIR;[](#l2.37)
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj);[](#l2.38)
goto error;[](#l2.39)
- }
/* On Unix, open will succeed for directories.[](#l2.41)
In Python, there should be no file objects referring to[](#l2.42)
directories, so we need a check. */[](#l2.43)
if (S_ISDIR(fdfstat.st_mode)) {[](#l2.44)
errno = EISDIR;[](#l2.45)
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj);[](#l2.46)
goto error;[](#l2.47)
}[](#l2.48)
#endif /* defined(S_ISDIR) */ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
if (fdfstat.st_blksize > 1)[](#l2.53)
self->blksize = fdfstat.st_blksize;[](#l2.54)
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
#if defined(MS_WINDOWS) || defined(CYGWIN) /* don't translate newlines (\r\n <=> \n) */