summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-17 23:22:14 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-17 23:22:14 (GMT)
commita555cfcb73cf677a99d29af6fa0bcfe4c35a2aeb (patch)
treefa88ce2ae8c7d2213dc3e80845405d0d8719308a /Python/random.c
parent6562b29e13f4da98558636c43a1b242698c8f8d9 (diff)
downloadcpython-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.c10
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) {