diff options
author | Steve Dower <steve.dower@microsoft.com> | 2015-04-12 04:26:27 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2015-04-12 04:26:27 (GMT) |
commit | 8fc8980c96f58a7f06e4e3133735807bd245c658 (patch) | |
tree | 04376ea1928a20c88b506e836ab82cc266cc85ae /Modules | |
parent | fe0a41aae425c61364b79c18ca8321dffed3ac40 (diff) | |
download | cpython-8fc8980c96f58a7f06e4e3133735807bd245c658.zip cpython-8fc8980c96f58a7f06e4e3133735807bd245c658.tar.gz cpython-8fc8980c96f58a7f06e4e3133735807bd245c658.tar.bz2 |
Issue #23524: Replace _PyVerify_fd function with calls to _set_thread_local_invalid_parameter_handler.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/fileio.c | 14 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 4 | ||||
-rw-r--r-- | Modules/posixmodule.c | 56 |
3 files changed, 62 insertions, 12 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index bb3e9b9..186319b 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -107,9 +107,11 @@ internal_close(fileio *self) /* fd is accessible and someone else may have closed it */ if (_PyVerify_fd(fd)) { Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH err = close(fd); if (err < 0) save_errno = errno; + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } else { save_errno = errno; @@ -599,11 +601,14 @@ fileio_readall(fileio *self) if (!_PyVerify_fd(self->fd)) return PyErr_SetFromErrno(PyExc_IOError); + _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS pos = _lseeki64(self->fd, 0L, SEEK_CUR); #else pos = lseek(self->fd, 0L, SEEK_CUR); #endif + _Py_END_SUPPRESS_IPH + if (_Py_fstat_noraise(self->fd, &status) == 0) end = status.st_size; else @@ -792,11 +797,13 @@ portable_lseek(int fd, PyObject *posobj, int whence) if (_PyVerify_fd(fd)) { Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS res = _lseeki64(fd, pos, whence); #else res = lseek(fd, pos, whence); #endif + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } else res = -1; @@ -951,7 +958,12 @@ fileio_isatty(fileio *self) if (self->fd < 0) return err_closed(); Py_BEGIN_ALLOW_THREADS - res = isatty(self->fd); + _Py_BEGIN_SUPPRESS_IPH + if (_PyVerify_fd(self->fd)) + res = isatty(self->fd); + else + res = 0; + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS return PyBool_FromLong(res); } diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index e2ed5f9..c5ba4b7 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1325,11 +1325,13 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) */ if (fileno != -1 && fileno != 0) { /* Ensure that fileno is within the CRT's valid range */ - if (_PyVerify_fd(fileno) == 0) { + if (!_PyVerify_fd(fileno)) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } + _Py_BEGIN_SUPPRESS_IPH fh = (HANDLE)_get_osfhandle(fileno); + _Py_END_SUPPRESS_IPH if (fh==(HANDLE)-1) { PyErr_SetFromErrno(PyExc_OSError); return NULL; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 724acc6..fcabadd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1280,10 +1280,6 @@ fildes_converter(PyObject *o, void *p) fd = PyObject_AsFileDescriptor(o); if (fd < 0) return 0; - if (!_PyVerify_fd(fd)) { - posix_error(); - return 0; - } *pointer = fd; return 1; } @@ -1294,9 +1290,14 @@ posix_fildes_fd(int fd, int (*func)(int)) int res; int async_err = 0; + if (!_PyVerify_fd(fd)) + return posix_error(); + do { Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH res = (*func)(fd); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (res != 0) @@ -4359,6 +4360,7 @@ os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd) int result; Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS if (path->wide) result = Py_DeleteFileW(path->wide); @@ -4373,6 +4375,7 @@ os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd) #endif /* HAVE_UNLINKAT */ result = unlink(path->narrow); #endif + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (result) @@ -7692,6 +7695,7 @@ os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd) flags |= O_CLOEXEC; #endif + _Py_BEGIN_SUPPRESS_IPH do { Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS @@ -7707,6 +7711,7 @@ os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd) fd = open(path->narrow, flags, mode); Py_END_ALLOW_THREADS } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); + _Py_END_SUPPRESS_IPH if (fd == -1) { if (!async_err) @@ -7745,7 +7750,9 @@ os_close_impl(PyModuleDef *module, int fd) * for more details. */ Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH res = close(fd); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (res < 0) return posix_error(); @@ -7769,9 +7776,11 @@ os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high) { int i; Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH for (i = fd_low; i < fd_high; i++) if (_PyVerify_fd(i)) close(i); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS Py_RETURN_NONE; } @@ -7823,7 +7832,9 @@ os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable) */ #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH res = dup2(fd, fd2); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (res < 0) return posix_error(); @@ -7957,11 +7968,13 @@ os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how) return -1; } Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS result = _lseeki64(fd, position, how); #else result = lseek(fd, position, how); #endif + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS if (result < 0) posix_error(); @@ -8168,7 +8181,9 @@ os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset) do { Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH n = pread(fd, PyBytes_AS_STRING(buffer), length, offset); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); @@ -8276,6 +8291,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) } } + _Py_BEGIN_SUPPRESS_IPH do { Py_BEGIN_ALLOW_THREADS #ifdef __APPLE__ @@ -8285,6 +8301,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) #endif Py_END_ALLOW_THREADS } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); + _Py_END_SUPPRESS_IPH if (sf.headers != NULL) iov_cleanup(sf.headers, hbuf, sf.hdr_cnt); @@ -8401,9 +8418,13 @@ static int os_isatty_impl(PyModuleDef *module, int fd) /*[clinic end generated code: output=acec9d3c29d16d33 input=08ce94aa1eaf7b5e]*/ { + int return_value; if (!_PyVerify_fd(fd)) return 0; - return isatty(fd); + _Py_BEGIN_SUPPRESS_IPH + return_value = isatty(fd); + _Py_END_SUPPRESS_IPH + return return_value; } @@ -8598,7 +8619,9 @@ os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset) do { Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset); + _Py_END_SUPPRESS_IPH Py_END_ALLOW_THREADS } while (size < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); @@ -11193,12 +11216,16 @@ static int os_get_inheritable_impl(PyModuleDef *module, int fd) /*[clinic end generated code: output=36110bb36efaa21e input=89ac008dc9ab6b95]*/ { - if (!_PyVerify_fd(fd)){ + int return_value; + if (!_PyVerify_fd(fd)) { posix_error(); return -1; } - return _Py_get_inheritable(fd); + _Py_BEGIN_SUPPRESS_IPH + return_value = _Py_get_inheritable(fd); + _Py_END_SUPPRESS_IPH + return return_value; } @@ -11215,10 +11242,14 @@ static PyObject * os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable) /*[clinic end generated code: output=2ac5c6ce8623f045 input=9ceaead87a1e2402]*/ { + int result; if (!_PyVerify_fd(fd)) return posix_error(); - if (_Py_set_inheritable(fd, inheritable, NULL) < 0) + _Py_BEGIN_SUPPRESS_IPH + result = _Py_set_inheritable(fd, inheritable, NULL); + _Py_END_SUPPRESS_IPH + if (result < 0) return NULL; Py_RETURN_NONE; } @@ -11289,7 +11320,9 @@ posix_get_blocking(PyObject *self, PyObject *args) if (!_PyVerify_fd(fd)) return posix_error(); + _Py_BEGIN_SUPPRESS_IPH blocking = _Py_get_blocking(fd); + _Py_END_SUPPRESS_IPH if (blocking < 0) return NULL; return PyBool_FromLong(blocking); @@ -11305,7 +11338,7 @@ PyDoc_STRVAR(set_blocking__doc__, static PyObject* posix_set_blocking(PyObject *self, PyObject *args) { - int fd, blocking; + int fd, blocking, result; if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking)) return NULL; @@ -11313,7 +11346,10 @@ posix_set_blocking(PyObject *self, PyObject *args) if (!_PyVerify_fd(fd)) return posix_error(); - if (_Py_set_blocking(fd, blocking) < 0) + _Py_BEGIN_SUPPRESS_IPH + result = _Py_set_blocking(fd, blocking); + _Py_END_SUPPRESS_IPH + if (result < 0) return NULL; Py_RETURN_NONE; } |