Issue #23694: Enhance _Py_open(), it now raises exceptions

* _Py_open() now raises exceptions on error. If open() fails, it raises an
  OSError with the filename.
* _Py_open() now releases the GIL while calling open()
* Add _Py_open_noraise() when _Py_open() cannot be used because the GIL is not
  held
This commit is contained in:
Victor Stinner 2015-03-18 00:22:14 +01:00
parent 6562b29e13
commit a555cfcb73
8 changed files with 71 additions and 45 deletions

View file

@ -1013,7 +1013,6 @@ newDevPollObject(void)
struct pollfd *fds;
struct rlimit limit;
Py_BEGIN_ALLOW_THREADS
/*
** If we try to process more that getrlimit()
** fds, the kernel will give an error, so
@ -1021,18 +1020,14 @@ newDevPollObject(void)
** value, because we can change rlimit() anytime.
*/
limit_result = getrlimit(RLIMIT_NOFILE, &limit);
if (limit_result != -1)
fd_devpoll = _Py_open("/dev/poll", O_RDWR);
Py_END_ALLOW_THREADS
if (limit_result == -1) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (fd_devpoll == -1) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, "/dev/poll");
fd_devpoll = _Py_open("/dev/poll", O_RDWR);
if (fd_devpoll == -1)
return NULL;
}
fds = PyMem_NEW(struct pollfd, limit.rlim_cur);
if (fds == NULL) {