Issue #23524: Replace _PyVerify_fd function with calls to _set_thread_local_invalid_parameter_handler.
This commit is contained in:
parent
fe0a41aae4
commit
8fc8980c96
|
@ -121,7 +121,7 @@ PyAPI_FUNC(int) _Py_get_blocking(int fd);
|
||||||
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
|
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
|
||||||
#endif /* !MS_WINDOWS */
|
#endif /* !MS_WINDOWS */
|
||||||
|
|
||||||
#if defined _MSC_VER && _MSC_VER >= 1400
|
#if defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900
|
||||||
/* A routine to check if a file descriptor is valid on Windows. Returns 0
|
/* A routine to check if a file descriptor is valid on Windows. Returns 0
|
||||||
* and sets errno to EBADF if it isn't. This is to avoid Assertions
|
* and sets errno to EBADF if it isn't. This is to avoid Assertions
|
||||||
* from various functions in the Windows CRT beginning with
|
* from various functions in the Windows CRT beginning with
|
||||||
|
|
|
@ -877,4 +877,24 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
|
||||||
#define PY_LITTLE_ENDIAN 1
|
#define PY_LITTLE_ENDIAN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef Py_BUILD_CORE
|
||||||
|
/*
|
||||||
|
* Macros to protect CRT calls against instant termination when passed an
|
||||||
|
* invalid parameter (issue23524).
|
||||||
|
*/
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1900
|
||||||
|
|
||||||
|
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
|
||||||
|
#define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
|
||||||
|
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
|
||||||
|
#define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define _Py_BEGIN_SUPPRESS_IPH
|
||||||
|
#define _Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
|
#endif /* _MSC_VER >= 1900 */
|
||||||
|
#endif /* Py_BUILD_CORE */
|
||||||
|
|
||||||
#endif /* Py_PYPORT_H */
|
#endif /* Py_PYPORT_H */
|
||||||
|
|
|
@ -107,9 +107,11 @@ internal_close(fileio *self)
|
||||||
/* fd is accessible and someone else may have closed it */
|
/* fd is accessible and someone else may have closed it */
|
||||||
if (_PyVerify_fd(fd)) {
|
if (_PyVerify_fd(fd)) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
err = close(fd);
|
err = close(fd);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} else {
|
} else {
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
|
@ -599,11 +601,14 @@ fileio_readall(fileio *self)
|
||||||
if (!_PyVerify_fd(self->fd))
|
if (!_PyVerify_fd(self->fd))
|
||||||
return PyErr_SetFromErrno(PyExc_IOError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
pos = _lseeki64(self->fd, 0L, SEEK_CUR);
|
pos = _lseeki64(self->fd, 0L, SEEK_CUR);
|
||||||
#else
|
#else
|
||||||
pos = lseek(self->fd, 0L, SEEK_CUR);
|
pos = lseek(self->fd, 0L, SEEK_CUR);
|
||||||
#endif
|
#endif
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
if (_Py_fstat_noraise(self->fd, &status) == 0)
|
if (_Py_fstat_noraise(self->fd, &status) == 0)
|
||||||
end = status.st_size;
|
end = status.st_size;
|
||||||
else
|
else
|
||||||
|
@ -792,11 +797,13 @@ portable_lseek(int fd, PyObject *posobj, int whence)
|
||||||
|
|
||||||
if (_PyVerify_fd(fd)) {
|
if (_PyVerify_fd(fd)) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
res = _lseeki64(fd, pos, whence);
|
res = _lseeki64(fd, pos, whence);
|
||||||
#else
|
#else
|
||||||
res = lseek(fd, pos, whence);
|
res = lseek(fd, pos, whence);
|
||||||
#endif
|
#endif
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} else
|
} else
|
||||||
res = -1;
|
res = -1;
|
||||||
|
@ -951,7 +958,12 @@ fileio_isatty(fileio *self)
|
||||||
if (self->fd < 0)
|
if (self->fd < 0)
|
||||||
return err_closed();
|
return err_closed();
|
||||||
Py_BEGIN_ALLOW_THREADS
|
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
|
Py_END_ALLOW_THREADS
|
||||||
return PyBool_FromLong(res);
|
return PyBool_FromLong(res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1325,11 +1325,13 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
|
||||||
*/
|
*/
|
||||||
if (fileno != -1 && fileno != 0) {
|
if (fileno != -1 && fileno != 0) {
|
||||||
/* Ensure that fileno is within the CRT's valid range */
|
/* Ensure that fileno is within the CRT's valid range */
|
||||||
if (_PyVerify_fd(fileno) == 0) {
|
if (!_PyVerify_fd(fileno)) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
fh = (HANDLE)_get_osfhandle(fileno);
|
fh = (HANDLE)_get_osfhandle(fileno);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (fh==(HANDLE)-1) {
|
if (fh==(HANDLE)-1) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1280,10 +1280,6 @@ fildes_converter(PyObject *o, void *p)
|
||||||
fd = PyObject_AsFileDescriptor(o);
|
fd = PyObject_AsFileDescriptor(o);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (!_PyVerify_fd(fd)) {
|
|
||||||
posix_error();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*pointer = fd;
|
*pointer = fd;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1294,9 +1290,14 @@ posix_fildes_fd(int fd, int (*func)(int))
|
||||||
int res;
|
int res;
|
||||||
int async_err = 0;
|
int async_err = 0;
|
||||||
|
|
||||||
|
if (!_PyVerify_fd(fd))
|
||||||
|
return posix_error();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
res = (*func)(fd);
|
res = (*func)(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
|
@ -4359,6 +4360,7 @@ os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd)
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
if (path->wide)
|
if (path->wide)
|
||||||
result = Py_DeleteFileW(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 */
|
#endif /* HAVE_UNLINKAT */
|
||||||
result = unlink(path->narrow);
|
result = unlink(path->narrow);
|
||||||
#endif
|
#endif
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -7692,6 +7695,7 @@ os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd)
|
||||||
flags |= O_CLOEXEC;
|
flags |= O_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
do {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
#ifdef MS_WINDOWS
|
#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);
|
fd = open(path->narrow, flags, mode);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
} while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
if (!async_err)
|
if (!async_err)
|
||||||
|
@ -7745,7 +7750,9 @@ os_close_impl(PyModuleDef *module, int fd)
|
||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
res = close(fd);
|
res = close(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
@ -7769,9 +7776,11 @@ os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
for (i = fd_low; i < fd_high; i++)
|
for (i = fd_low; i < fd_high; i++)
|
||||||
if (_PyVerify_fd(i))
|
if (_PyVerify_fd(i))
|
||||||
close(i);
|
close(i);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -7823,7 +7832,9 @@ os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable)
|
||||||
*/
|
*/
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
res = dup2(fd, fd2);
|
res = dup2(fd, fd2);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
@ -7957,11 +7968,13 @@ os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
result = _lseeki64(fd, position, how);
|
result = _lseeki64(fd, position, how);
|
||||||
#else
|
#else
|
||||||
result = lseek(fd, position, how);
|
result = lseek(fd, position, how);
|
||||||
#endif
|
#endif
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
posix_error();
|
posix_error();
|
||||||
|
@ -8168,7 +8181,9 @@ os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
n = pread(fd, PyBytes_AS_STRING(buffer), length, offset);
|
n = pread(fd, PyBytes_AS_STRING(buffer), length, offset);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
} 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 {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -8285,6 +8301,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
#endif
|
#endif
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
} while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
if (sf.headers != NULL)
|
if (sf.headers != NULL)
|
||||||
iov_cleanup(sf.headers, hbuf, sf.hdr_cnt);
|
iov_cleanup(sf.headers, hbuf, sf.hdr_cnt);
|
||||||
|
@ -8401,9 +8418,13 @@ static int
|
||||||
os_isatty_impl(PyModuleDef *module, int fd)
|
os_isatty_impl(PyModuleDef *module, int fd)
|
||||||
/*[clinic end generated code: output=acec9d3c29d16d33 input=08ce94aa1eaf7b5e]*/
|
/*[clinic end generated code: output=acec9d3c29d16d33 input=08ce94aa1eaf7b5e]*/
|
||||||
{
|
{
|
||||||
|
int return_value;
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
return 0;
|
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 {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset);
|
size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (size < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
} while (size < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||||
|
|
||||||
|
@ -11193,12 +11216,16 @@ static int
|
||||||
os_get_inheritable_impl(PyModuleDef *module, int fd)
|
os_get_inheritable_impl(PyModuleDef *module, int fd)
|
||||||
/*[clinic end generated code: output=36110bb36efaa21e input=89ac008dc9ab6b95]*/
|
/*[clinic end generated code: output=36110bb36efaa21e input=89ac008dc9ab6b95]*/
|
||||||
{
|
{
|
||||||
if (!_PyVerify_fd(fd)){
|
int return_value;
|
||||||
|
if (!_PyVerify_fd(fd)) {
|
||||||
posix_error();
|
posix_error();
|
||||||
return -1;
|
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)
|
os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable)
|
||||||
/*[clinic end generated code: output=2ac5c6ce8623f045 input=9ceaead87a1e2402]*/
|
/*[clinic end generated code: output=2ac5c6ce8623f045 input=9ceaead87a1e2402]*/
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
return posix_error();
|
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;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -11289,7 +11320,9 @@ posix_get_blocking(PyObject *self, PyObject *args)
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
blocking = _Py_get_blocking(fd);
|
blocking = _Py_get_blocking(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (blocking < 0)
|
if (blocking < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyBool_FromLong(blocking);
|
return PyBool_FromLong(blocking);
|
||||||
|
@ -11305,7 +11338,7 @@ PyDoc_STRVAR(set_blocking__doc__,
|
||||||
static PyObject*
|
static PyObject*
|
||||||
posix_set_blocking(PyObject *self, PyObject *args)
|
posix_set_blocking(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int fd, blocking;
|
int fd, blocking, result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
|
if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -11313,7 +11346,10 @@ posix_set_blocking(PyObject *self, PyObject *args)
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
return posix_error();
|
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;
|
return NULL;
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ static void __cdecl _silent_invalid_parameter_handler(
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
uintptr_t pReserved) { }
|
uintptr_t pReserved) { }
|
||||||
|
|
||||||
void *_Py_silent_invalid_parameter_handler =
|
_invalid_parameter_handler _Py_silent_invalid_parameter_handler = _silent_invalid_parameter_handler;
|
||||||
(void*)_silent_invalid_parameter_handler;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -149,7 +149,9 @@ msvcrt_get_osfhandle(PyObject *self, PyObject *args)
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
return PyErr_SetFromErrno(PyExc_IOError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
handle = _get_osfhandle(fd);
|
handle = _get_osfhandle(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (handle == -1)
|
if (handle == -1)
|
||||||
return PyErr_SetFromErrno(PyExc_IOError);
|
return PyErr_SetFromErrno(PyExc_IOError);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
extern int winerror_to_errno(int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LANGINFO_H
|
#ifdef HAVE_LANGINFO_H
|
||||||
|
@ -41,9 +42,13 @@ _Py_device_encoding(int fd)
|
||||||
#if defined(MS_WINDOWS)
|
#if defined(MS_WINDOWS)
|
||||||
UINT cp;
|
UINT cp;
|
||||||
#endif
|
#endif
|
||||||
if (!_PyVerify_fd(fd) || !isatty(fd)) {
|
int valid;
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
|
valid = _PyVerify_fd(fd) && isatty(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
if (!valid)
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
|
||||||
#if defined(MS_WINDOWS)
|
#if defined(MS_WINDOWS)
|
||||||
if (fd == 0)
|
if (fd == 0)
|
||||||
cp = GetConsoleCP();
|
cp = GetConsoleCP();
|
||||||
|
@ -610,16 +615,15 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
|
||||||
|
|
||||||
if (!_PyVerify_fd(fd))
|
if (!_PyVerify_fd(fd))
|
||||||
h = INVALID_HANDLE_VALUE;
|
h = INVALID_HANDLE_VALUE;
|
||||||
else
|
else {
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
h = (HANDLE)_get_osfhandle(fd);
|
h = (HANDLE)_get_osfhandle(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
/* 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) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
/* This is really a C library error (invalid file handle).
|
/* errno is already set by _get_osfhandle, but we also set
|
||||||
We set the Win32 error to the closes one matching. */
|
the Win32 error for callers who expect that */
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -628,8 +632,10 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
|
||||||
type = GetFileType(h);
|
type = GetFileType(h);
|
||||||
if (type == FILE_TYPE_UNKNOWN) {
|
if (type == FILE_TYPE_UNKNOWN) {
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
if (error != 0)
|
if (error != 0) {
|
||||||
|
errno = winerror_to_errno(error);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
/* else: valid but unknown file */
|
/* else: valid but unknown file */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,6 +648,9 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFileInformationByHandle(h, &info)) {
|
if (!GetFileInformationByHandle(h, &info)) {
|
||||||
|
/* The Win32 error is already set, but we also set errno for
|
||||||
|
callers who expect it */
|
||||||
|
errno = winerror_to_errno(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,7 +744,9 @@ get_inheritable(int fd, int raise)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
handle = (HANDLE)_get_osfhandle(fd);
|
handle = (HANDLE)_get_osfhandle(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
if (raise)
|
if (raise)
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
@ -810,7 +821,9 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
handle = (HANDLE)_get_osfhandle(fd);
|
handle = (HANDLE)_get_osfhandle(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
if (raise)
|
if (raise)
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
@ -1171,6 +1184,7 @@ _Py_read(int fd, void *buf, size_t count)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
do {
|
do {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -1185,6 +1199,7 @@ _Py_read(int fd, void *buf, size_t count)
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
} while (n < 0 && err == EINTR &&
|
} while (n < 0 && err == EINTR &&
|
||||||
!(async_err = PyErr_CheckSignals()));
|
!(async_err = PyErr_CheckSignals()));
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
if (async_err) {
|
if (async_err) {
|
||||||
/* read() was interrupted by a signal (failed with EINTR)
|
/* read() was interrupted by a signal (failed with EINTR)
|
||||||
|
@ -1219,6 +1234,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
if (count > 32767 && isatty(fd)) {
|
if (count > 32767 && isatty(fd)) {
|
||||||
/* Issue #11395: the Windows console returns an error (12: not
|
/* Issue #11395: the Windows console returns an error (12: not
|
||||||
|
@ -1264,6 +1280,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
|
||||||
err = errno;
|
err = errno;
|
||||||
} while (n < 0 && err == EINTR);
|
} while (n < 0 && err == EINTR);
|
||||||
}
|
}
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
if (async_err) {
|
if (async_err) {
|
||||||
/* write() was interrupted by a signal (failed with EINTR)
|
/* write() was interrupted by a signal (failed with EINTR)
|
||||||
|
@ -1451,7 +1468,9 @@ _Py_dup(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
handle = (HANDLE)_get_osfhandle(fd);
|
handle = (HANDLE)_get_osfhandle(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (handle == INVALID_HANDLE_VALUE) {
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1461,7 +1480,9 @@ _Py_dup(int fd)
|
||||||
ftype = GetFileType(handle);
|
ftype = GetFileType(handle);
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
fd = dup(fd);
|
fd = dup(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
@ -1471,13 +1492,17 @@ _Py_dup(int fd)
|
||||||
/* Character files like console cannot be make non-inheritable */
|
/* Character files like console cannot be make non-inheritable */
|
||||||
if (ftype != FILE_TYPE_CHAR) {
|
if (ftype != FILE_TYPE_CHAR) {
|
||||||
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
|
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
close(fd);
|
close(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC)
|
#elif defined(HAVE_FCNTL_H) && defined(F_DUPFD_CLOEXEC)
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
@ -1486,7 +1511,9 @@ _Py_dup(int fd)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
fd = dup(fd);
|
fd = dup(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
@ -1494,7 +1521,9 @@ _Py_dup(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
|
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
close(fd);
|
close(fd);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1508,7 +1537,10 @@ _Py_dup(int fd)
|
||||||
int
|
int
|
||||||
_Py_get_blocking(int fd)
|
_Py_get_blocking(int fd)
|
||||||
{
|
{
|
||||||
int flags = fcntl(fd, F_GETFL, 0);
|
int flags;
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
|
flags = fcntl(fd, F_GETFL, 0);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
if (flags < 0) {
|
if (flags < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1533,16 +1565,20 @@ _Py_set_blocking(int fd, int blocking)
|
||||||
#else
|
#else
|
||||||
int flags, res;
|
int flags, res;
|
||||||
|
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
flags = fcntl(fd, F_GETFL, 0);
|
flags = fcntl(fd, F_GETFL, 0);
|
||||||
if (flags < 0)
|
if (flags >= 0) {
|
||||||
goto error;
|
if (blocking)
|
||||||
|
flags = flags & (~O_NONBLOCK);
|
||||||
|
else
|
||||||
|
flags = flags | O_NONBLOCK;
|
||||||
|
|
||||||
if (blocking)
|
res = fcntl(fd, F_SETFL, flags);
|
||||||
flags = flags & (~O_NONBLOCK);
|
} else {
|
||||||
else
|
res = -1;
|
||||||
flags = flags | O_NONBLOCK;
|
}
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
res = fcntl(fd, F_SETFL, flags);
|
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1554,25 +1590,7 @@ error:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#if defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900
|
||||||
#if _MSC_VER >= 1900
|
|
||||||
|
|
||||||
/* This function lets the Windows CRT validate the file handle without
|
|
||||||
terminating the process if it's invalid. */
|
|
||||||
int
|
|
||||||
_PyVerify_fd(int fd)
|
|
||||||
{
|
|
||||||
intptr_t osh;
|
|
||||||
/* Fast check for the only condition we know */
|
|
||||||
if (fd < 0) {
|
|
||||||
_set_errno(EBADF);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
osh = _get_osfhandle(fd);
|
|
||||||
return osh != (intptr_t)-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif _MSC_VER >= 1400
|
|
||||||
/* Legacy implementation of _PyVerify_fd while transitioning to
|
/* Legacy implementation of _PyVerify_fd while transitioning to
|
||||||
* MSVC 14.0. This should eventually be removed. (issue23524)
|
* MSVC 14.0. This should eventually be removed. (issue23524)
|
||||||
*/
|
*/
|
||||||
|
@ -1651,5 +1669,4 @@ _PyVerify_fd(int fd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _MSC_VER >= 1900 || _MSC_VER >= 1400 */
|
#endif /* defined _MSC_VER && _MSC_VER >= 1400 && _MSC_VER < 1900 */
|
||||||
#endif /* defined _MSC_VER */
|
|
||||||
|
|
|
@ -1068,11 +1068,12 @@ is_valid_fd(int fd)
|
||||||
int dummy_fd;
|
int dummy_fd;
|
||||||
if (fd < 0 || !_PyVerify_fd(fd))
|
if (fd < 0 || !_PyVerify_fd(fd))
|
||||||
return 0;
|
return 0;
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
dummy_fd = dup(fd);
|
dummy_fd = dup(fd);
|
||||||
if (dummy_fd < 0)
|
if (dummy_fd >= 0)
|
||||||
return 0;
|
close(dummy_fd);
|
||||||
close(dummy_fd);
|
_Py_END_SUPPRESS_IPH
|
||||||
return 1;
|
return dummy_fd >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize sys.stdin, stdout, stderr and builtins.open */
|
/* Initialize sys.stdin, stdout, stderr and builtins.open */
|
||||||
|
|
|
@ -22,12 +22,6 @@ to avoid the expense of doing their own locking).
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined _MSC_VER && _MSC_VER >= 1900
|
|
||||||
/* Issue #23524: Temporary fix to disable termination due to invalid parameters */
|
|
||||||
PyAPI_DATA(void*) _Py_silent_invalid_parameter_handler;
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -228,11 +222,6 @@ new_threadstate(PyInterpreterState *interp, int init)
|
||||||
tstate->next->prev = tstate;
|
tstate->next->prev = tstate;
|
||||||
interp->tstate_head = tstate;
|
interp->tstate_head = tstate;
|
||||||
HEAD_UNLOCK();
|
HEAD_UNLOCK();
|
||||||
|
|
||||||
#if defined _MSC_VER && _MSC_VER >= 1900
|
|
||||||
/* Issue #23524: Temporary fix to disable termination due to invalid parameters */
|
|
||||||
_set_thread_local_invalid_parameter_handler((_invalid_parameter_handler)_Py_silent_invalid_parameter_handler);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tstate;
|
return tstate;
|
||||||
|
|
|
@ -717,6 +717,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
|
||||||
/* Dump the traceback of each thread */
|
/* Dump the traceback of each thread */
|
||||||
tstate = PyInterpreterState_ThreadHead(interp);
|
tstate = PyInterpreterState_ThreadHead(interp);
|
||||||
nthreads = 0;
|
nthreads = 0;
|
||||||
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (nthreads != 0)
|
if (nthreads != 0)
|
||||||
|
@ -730,6 +731,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
|
||||||
tstate = PyThreadState_Next(tstate);
|
tstate = PyThreadState_Next(tstate);
|
||||||
nthreads++;
|
nthreads++;
|
||||||
} while (tstate != NULL);
|
} while (tstate != NULL);
|
||||||
|
_Py_END_SUPPRESS_IPH
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue