summaryrefslogtreecommitdiffstats
path: root/Python/random.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-30 09:19:07 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-30 09:19:07 (GMT)
commit81c6df5c0fa046eea1a9fe971fe72ad03b0bf9b3 (patch)
tree9f711e41c0a2833adb7b831855eb78eb86edf16c /Python/random.c
parent79b74aeb20a539cb807aa297dc22eabbb525b892 (diff)
parent9aa1331c6f73b0868f736a40445cc3bcd33c5345 (diff)
downloadcpython-81c6df5c0fa046eea1a9fe971fe72ad03b0bf9b3.zip
cpython-81c6df5c0fa046eea1a9fe971fe72ad03b0bf9b3.tar.gz
cpython-81c6df5c0fa046eea1a9fe971fe72ad03b0bf9b3.tar.bz2
(Merge 3.4) Issue #22585: os.urandom() now releases the GIL when the
getentropy() is used (OpenBSD 5.6+).
Diffstat (limited to 'Python/random.c')
-rw-r--r--Python/random.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Python/random.c b/Python/random.c
index f3a8ae5..9c9d505 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -81,16 +81,24 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
{
while (size > 0) {
Py_ssize_t len = Py_MIN(size, 256);
- int res = getentropy(buffer, len);
- if (res < 0) {
- if (fatal) {
- Py_FatalError("getentropy() failed");
- }
- else {
+ int res;
+
+ if (!fatal) {
+ Py_BEGIN_ALLOW_THREADS
+ res = getentropy(buffer, len);
+ Py_END_ALLOW_THREADS
+
+ if (res < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
}
+ else {
+ res = getentropy(buffer, len);
+ if (res < 0)
+ Py_FatalError("getentropy() failed");
+ }
+
buffer += len;
size -= len;
}