diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 09:22:13 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 09:22:13 (GMT) |
commit | e9932451ae954dbba7fb54deaf3641293021c9a1 (patch) | |
tree | 271febe7e4c5f571c6faeecd99f4ba555b793d16 /Python/random.c | |
parent | 96d80129643a72ea08a4f563054b7c3506b3af0d (diff) | |
download | cpython-e9932451ae954dbba7fb54deaf3641293021c9a1.zip cpython-e9932451ae954dbba7fb54deaf3641293021c9a1.tar.gz cpython-e9932451ae954dbba7fb54deaf3641293021c9a1.tar.bz2 |
Issue #23115: 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.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Python/random.c b/Python/random.c index ad8993d..d94f89a 100644 --- a/Python/random.c +++ b/Python/random.c @@ -103,16 +103,24 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal) { while (size > 0) { Py_ssize_t len = size < 256 ? 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; } |