]> granicus.if.org Git - python/commitdiff
Issue #22181: os.urandom() now releases the GIL when the getrandom()
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Mar 2015 09:16:40 +0000 (11:16 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 30 Mar 2015 09:16:40 +0000 (11:16 +0200)
implementation is used.

Python/random.c

index a4eba3ccd93b9ae6e66b04f4c57332dc444ee7e9..f3a8ae552e1c51f0575b59fe01a8fad675f3ecff 100644 (file)
@@ -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;