diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-17 23:22:14 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-17 23:22:14 (GMT) |
commit | a555cfcb73cf677a99d29af6fa0bcfe4c35a2aeb (patch) | |
tree | fa88ce2ae8c7d2213dc3e80845405d0d8719308a /Python/random.c | |
parent | 6562b29e13f4da98558636c43a1b242698c8f8d9 (diff) | |
download | cpython-a555cfcb73cf677a99d29af6fa0bcfe4c35a2aeb.zip cpython-a555cfcb73cf677a99d29af6fa0bcfe4c35a2aeb.tar.gz cpython-a555cfcb73cf677a99d29af6fa0bcfe4c35a2aeb.tar.bz2 |
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
Diffstat (limited to 'Python/random.c')
-rw-r--r-- | Python/random.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Python/random.c b/Python/random.c index 031d887..39a389c 100644 --- a/Python/random.c +++ b/Python/random.c @@ -111,7 +111,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size) assert (0 < size); - fd = _Py_open("/dev/urandom", O_RDONLY); + fd = _Py_open_noraise("/dev/urandom", O_RDONLY); if (fd < 0) Py_FatalError("Failed to open /dev/urandom"); @@ -158,17 +158,13 @@ dev_urandom_python(char *buffer, Py_ssize_t size) if (urandom_cache.fd >= 0) fd = urandom_cache.fd; else { - Py_BEGIN_ALLOW_THREADS fd = _Py_open("/dev/urandom", O_RDONLY); - Py_END_ALLOW_THREADS - if (fd < 0) - { + if (fd < 0) { if (errno == ENOENT || errno == ENXIO || errno == ENODEV || errno == EACCES) PyErr_SetString(PyExc_NotImplementedError, "/dev/urandom (or equivalent) not found"); - else - PyErr_SetFromErrno(PyExc_OSError); + /* otherwise, keep the OSError exception raised by _Py_open() */ return -1; } if (urandom_cache.fd >= 0) { |