diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 09:16:40 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 09:16:40 (GMT) |
commit | 79b74aeb20a539cb807aa297dc22eabbb525b892 (patch) | |
tree | 1280b7822fdcb888dc5a3801af351d8f64423651 | |
parent | a52f31dfe2c6aaf7477f9ca8b81b7c89c417f68c (diff) | |
download | cpython-79b74aeb20a539cb807aa297dc22eabbb525b892.zip cpython-79b74aeb20a539cb807aa297dc22eabbb525b892.tar.gz cpython-79b74aeb20a539cb807aa297dc22eabbb525b892.tar.bz2 |
Issue #22181: os.urandom() now releases the GIL when the getrandom()
implementation is used.
-rw-r--r-- | Python/random.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/random.c b/Python/random.c index a4eba3c..f3a8ae5 100644 --- a/Python/random.c +++ b/Python/random.c @@ -115,9 +115,18 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise) while (0 < size) { errno = 0; - /* the libc doesn't expose getrandom() yet, see: + + /* Use syscall() because the libc doesn't expose getrandom() yet, see: * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ - n = syscall(SYS_getrandom, buffer, size, flags); + if (raise) { + Py_BEGIN_ALLOW_THREADS + n = syscall(SYS_getrandom, buffer, size, flags); + Py_END_ALLOW_THREADS + } + else { + n = syscall(SYS_getrandom, buffer, size, flags); + } + if (n < 0) { if (errno == ENOSYS) { getrandom_works = 0; |