summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-30 08:09:31 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-30 08:09:31 (GMT)
commite134a7fe36652434c2ccffc4ebab2ec2031d1505 (patch)
tree9eea060bf19c856881f438860eb2abdbe41f2bdd /Modules
parent2e1c4e5db2894ec4322f917e9babc4e37dca9244 (diff)
downloadcpython-e134a7fe36652434c2ccffc4ebab2ec2031d1505.zip
cpython-e134a7fe36652434c2ccffc4ebab2ec2031d1505.tar.gz
cpython-e134a7fe36652434c2ccffc4ebab2ec2031d1505.tar.bz2
Issue #23752: _Py_fstat() is now responsible to raise the Python exception
Add _Py_fstat_noraise() function when a Python exception is not welcome.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c10
-rw-r--r--Modules/main.c6
-rw-r--r--Modules/mmapmodule.c25
-rw-r--r--Modules/posixmodule.c2
-rw-r--r--Modules/signalmodule.c10
5 files changed, 24 insertions, 29 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 595f99e..b56a9c3 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -399,10 +399,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
}
self->blksize = DEFAULT_BUFFER_SIZE;
- if (_Py_fstat(self->fd, &fdfstat) < 0) {
- PyErr_SetFromErrno(PyExc_OSError);
+ if (_Py_fstat(self->fd, &fdfstat) < 0)
goto error;
- }
#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 currentsize)
static PyObject *
fileio_readall(fileio *self)
{
- struct _Py_stat_struct st;
+ struct _Py_stat_struct status;
Py_off_t pos, end;
PyObject *result;
Py_ssize_t bytes_read = 0;
@@ -606,8 +604,8 @@ fileio_readall(fileio *self)
#else
pos = lseek(self->fd, 0L, SEEK_CUR);
#endif
- if (_Py_fstat(self->fd, &st) == 0)
- end = st.st_size;
+ if (_Py_fstat_noraise(self->fd, &status) == 0)
+ end = status.st_size;
else
end = (Py_off_t)-1;
diff --git a/Modules/main.c b/Modules/main.c
index 74e512b..2a9ea28 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -753,9 +753,11 @@ Py_Main(int argc, wchar_t **argv)
}
{
struct _Py_stat_struct sb;
- if (_Py_fstat(fileno(fp), &sb) == 0 &&
+ if (_Py_fstat_noraise(fileno(fp), &sb) == 0 &&
S_ISDIR(sb.st_mode)) {
- fprintf(stderr, "%ls: '%ls' is a directory, cannot continue\n", argv[0], filename);
+ fprintf(stderr,
+ "%ls: '%ls' is a directory, cannot continue\n",
+ argv[0], filename);
fclose(fp);
return 1;
}
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 25056a4..e2ed5f9 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -465,15 +465,13 @@ mmap_size_method(mmap_object *self,
#ifdef UNIX
{
- struct _Py_stat_struct buf;
- if (-1 == _Py_fstat(self->fd, &buf)) {
- PyErr_SetFromErrno(PyExc_OSError);
+ struct _Py_stat_struct status;
+ if (_Py_fstat(self->fd, &status) == -1)
return NULL;
- }
#ifdef HAVE_LARGEFILE_SUPPORT
- return PyLong_FromLongLong(buf.st_size);
+ return PyLong_FromLongLong(status.st_size);
#else
- return PyLong_FromLong(buf.st_size);
+ return PyLong_FromLong(status.st_size);
#endif
}
#endif /* UNIX */
@@ -1112,7 +1110,7 @@ _GetMapSize(PyObject *o, const char* param)
static PyObject *
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
{
- struct _Py_stat_struct st;
+ struct _Py_stat_struct status;
mmap_object *m_obj;
PyObject *map_size_obj = NULL;
Py_ssize_t map_size;
@@ -1177,25 +1175,26 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
if (fd != -1)
(void)fcntl(fd, F_FULLFSYNC);
#endif
- if (fd != -1 && _Py_fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
+ if (fd != -1 && _Py_fstat_noraise(fd, &status) == 0
+ && S_ISREG(status.st_mode)) {
if (map_size == 0) {
- if (st.st_size == 0) {
+ if (status.st_size == 0) {
PyErr_SetString(PyExc_ValueError,
"cannot mmap an empty file");
return NULL;
}
- if (offset >= st.st_size) {
+ if (offset >= status.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap offset is greater than file size");
return NULL;
}
- if (st.st_size - offset > PY_SSIZE_T_MAX) {
+ if (status.st_size - offset > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_ValueError,
"mmap length is too large");
return NULL;
}
- map_size = (Py_ssize_t) (st.st_size - offset);
- } else if (offset + map_size > st.st_size) {
+ map_size = (Py_ssize_t) (status.st_size - offset);
+ } else if (offset + map_size > status.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap length is greater than file size");
return NULL;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 801305f..ef69a45 100644
--- 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
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 1b3589d..3081562 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -503,7 +503,7 @@ signal_siginterrupt(PyObject *self, PyObject *args)
static PyObject *
signal_set_wakeup_fd(PyObject *self, PyObject *args)
{
- struct _Py_stat_struct st;
+ struct _Py_stat_struct status;
#ifdef MS_WINDOWS
PyObject *fdobj;
SOCKET_T sockfd, old_sockfd;
@@ -559,10 +559,8 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args)
return NULL;
}
- if (_Py_fstat(fd, &st) != 0) {
- PyErr_SetExcFromWindowsErr(PyExc_OSError, GetLastError());
+ if (_Py_fstat(fd, &status) != 0)
return NULL;
- }
/* on Windows, a file cannot be set to non-blocking mode */
}
@@ -591,10 +589,8 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args)
return NULL;
}
- if (_Py_fstat(fd, &st) != 0) {
- PyErr_SetFromErrno(PyExc_OSError);
+ if (_Py_fstat(fd, &status) != 0)
return NULL;
- }
blocking = _Py_get_blocking(fd);
if (blocking < 0)