summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-30 09:18:30 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-30 09:18:30 (GMT)
commit9aa1331c6f73b0868f736a40445cc3bcd33c5345 (patch)
tree4b481b7359d5edbf2892dc3ba95c1cbb4421ea18
parent04d09ebd396d2a87ad7204e170c1149edc9b141d (diff)
downloadcpython-9aa1331c6f73b0868f736a40445cc3bcd33c5345.zip
cpython-9aa1331c6f73b0868f736a40445cc3bcd33c5345.tar.gz
cpython-9aa1331c6f73b0868f736a40445cc3bcd33c5345.tar.bz2
Issue #22585: os.urandom() now releases the GIL when the getentropy() is used
(OpenBSD 5.6+).
-rw-r--r--Python/random.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Python/random.c b/Python/random.c
index 93d300d..3f307cf 100644
--- a/Python/random.c
+++ b/Python/random.c
@@ -78,16 +78,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;
}