cpython: 128f92ae8bae (original) (raw)

Mercurial > cpython

changeset 95285:128f92ae8bae

Issue #23752: _Py_fstat() is now responsible to raise the Python exception Add _Py_fstat_noraise() function when a Python exception is not welcome. [#23752]

Victor Stinner victor.stinner@gmail.com
date Mon, 30 Mar 2015 10:09:31 +0200
parents 2fcd99929dba
children e00b581a65ec
files Include/fileutils.h Modules/_io/fileio.c Modules/main.c Modules/mmapmodule.c Modules/posixmodule.c Modules/signalmodule.c Programs/_freeze_importlib.c Python/dynload_shlib.c Python/fileutils.c Python/marshal.c Python/random.c Python/sysmodule.c
diffstat 12 files changed, 89 insertions(+), 57 deletions(-)[+] [-] Include/fileutils.h 8 Modules/_io/fileio.c 10 Modules/main.c 6 Modules/mmapmodule.c 25 Modules/posixmodule.c 2 Modules/signalmodule.c 10 Programs/_freeze_importlib.c 6 Python/dynload_shlib.c 14 Python/fileutils.c 58 Python/marshal.c 2 Python/random.c 3 Python/sysmodule.c 2

line wrap: on

line diff

--- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -41,12 +41,16 @@ struct _Py_stat_struct { PyAPI_FUNC(int) _Py_fstat( int fd,

+ +PyAPI_FUNC(int) _Py_fstat_noraise(

#endif /* Py_LIMITED_API */ PyAPI_FUNC(int) _Py_stat( PyObject *path,

#ifndef Py_LIMITED_API PyAPI_FUNC(int) _Py_open(

--- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -399,10 +399,8 @@ fileio_init(PyObject *oself, PyObject *a } self->blksize = DEFAULT_BUFFER_SIZE;

#if defined(S_ISDIR) && defined(EISDIR) /* On Unix, open will succeed for directories. In Python, there should be no file objects referring to @@ -589,7 +587,7 @@ new_buffersize(fileio *self, size_t curr static PyObject * fileio_readall(fileio *self) {

#else pos = lseek(self->fd, 0L, SEEK_CUR); #endif

--- a/Modules/main.c +++ b/Modules/main.c @@ -753,9 +753,11 @@ Py_Main(int argc, wchar_t **argv) } { struct _Py_stat_struct sb;

--- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -465,15 +465,13 @@ mmap_size_method(mmap_object *self, #ifdef UNIX {

#ifdef HAVE_LARGEFILE_SUPPORT

#else

#endif } #endif /* UNIX */ @@ -1112,7 +1110,7 @@ static Py_ssize_t static PyObject * new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) {

#endif

--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -351,7 +351,7 @@ static int win32_can_symlink = 0; #ifdef MS_WINDOWS

define STAT win32_stat

define LSTAT win32_lstat

-# define FSTAT _Py_fstat +# define FSTAT _Py_fstat_noraise

define STRUCT_STAT struct _Py_stat_struct

#else

define STAT stat

--- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -503,7 +503,7 @@ signal_siginterrupt(PyObject *self, PyOb static PyObject * signal_set_wakeup_fd(PyObject *self, PyObject *args) {

#ifdef MS_WINDOWS PyObject *fdobj; SOCKET_T sockfd, old_sockfd; @@ -559,10 +559,8 @@ signal_set_wakeup_fd(PyObject *self, PyO return NULL; }

/* on Windows, a file cannot be set to non-blocking mode */ } @@ -591,10 +589,8 @@ signal_set_wakeup_fd(PyObject *self, PyO return NULL; }

blocking = _Py_get_blocking(fd); if (blocking < 0)

--- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -35,7 +35,7 @@ main(int argc, char *argv[]) { char *inpath, *outpath; FILE *infile = NULL, *outfile = NULL;

--- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -71,22 +71,20 @@ dl_funcptr _PyImport_GetDynLoadFunc(cons if (fp != NULL) { int i;

--- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -565,7 +565,8 @@ attributes_to_mode(DWORD attr) } void -_Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, struct _Py_stat_struct *result) +_Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag,

{ memset(result, 0, sizeof(*result)); result->st_mode = attributes_to_mode(info->dwFileAttributes); @@ -595,9 +596,12 @@ void files larger than 2 GB. fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer: see issue #23152.

#ifdef MS_WINDOWS BY_HANDLE_FILE_INFORMATION info; @@ -619,22 +623,21 @@ int SetLastError(ERROR_INVALID_HANDLE); return -1; }

type = GetFileType(h); if (type == FILE_TYPE_UNKNOWN) { DWORD error = GetLastError();

#else

#endif } +/* Return information about a file. +

+

+

+

+#ifdef MS_WINDOWS

+#else

+#endif

+} /* Call _wstat() on Windows, or encode the path to the filesystem encoding and call stat() otherwise. Only fill st_mode attribute on Windows.

--- a/Python/marshal.c +++ b/Python/marshal.c @@ -1486,7 +1486,7 @@ static off_t getfilesize(FILE *fp) { struct _Py_stat_struct st;

#if SIZEOF_OFF_T == 4 else if (st.st_size >= INT_MAX)

--- a/Python/random.c +++ b/Python/random.c @@ -221,7 +221,7 @@ dev_urandom_python(char buffer, Py_ssiz if (urandom_cache.fd >= 0) { / Does the fd point to the same thing as before? (issue #21207) */

@@ -250,7 +250,6 @@ dev_urandom_python(char *buffer, Py_ssiz } else { if (_Py_fstat(fd, &st)) {

--- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1690,7 +1690,7 @@ PyObject * #if !defined(MS_WINDOWS) { struct _Py_stat_struct sb;