summaryrefslogtreecommitdiff
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-18 00:22:14 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-03-18 00:22:14 +0100
commitb8d0bcab60af86bb0d982ef0483eec7930a0a9d0 (patch)
treeef47b3ed67ba75967e5b95289773bcbc8ecfb8cc /Python/random.c
parente5cb7bc5a80a77c85bab243ae01238d5367e6b8d (diff)
downloadcpython-b8d0bcab60af86bb0d982ef0483eec7930a0a9d0.tar.gz
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 031d8875c9..39a389c79f 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) {