cpython: 86d0d74bc2e1 (original) (raw)

--- a/Python/random.c +++ b/Python/random.c @@ -77,7 +77,7 @@ win32_urandom(unsigned char buffer, Py_ } / Issue #25003: Don't use getentropy() on Solaris (available since

#elif defined(HAVE_GETENTROPY) && !defined(sun) #define PY_GETENTROPY 1 @@ -119,25 +119,32 @@ py_getentropy(char buffer, Py_ssize_t s #if defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL) #define PY_GETRANDOM 1 +/ Call getrandom()

static int py_getrandom(void buffer, Py_ssize_t size, int raise) { / Is getrandom() supported by the running kernel?

dest = buffer; while (0 < size) { @@ -161,8 +168,8 @@ py_getrandom(void buffer, Py_ssize_t si } #else / On Linux, use the syscall() function because the GNU libc doesn't

@@ -180,12 +187,12 @@ py_getrandom(void buffer, Py_ssize_t si } if (errno == EAGAIN) { / If we failed with EAGAIN, the entropy pool was

+

@@ -221,130 +228,117 @@ static struct { } urandom_cache = { -1 }; -/* Read size bytes from /dev/urandom into buffer.

- -#ifdef PY_GETRANDOM

-#endif -

-

-

-

-

-} - -/* Read size bytes from /dev/urandom into buffer.

#ifdef PY_GETRANDOM int res; #endif

#ifdef PY_GETRANDOM

#endif

+

+

+

+

@@ -381,10 +375,10 @@ lcg_urandom(unsigned int x0, unsigned ch } /* If raise is zero:

#elif defined(PY_GETENTROPY) return py_getentropy(buffer, size, raise); #else

#endif } @@ -466,7 +455,7 @@ void int res; /* _PyRandom_Init() is called very early in the Python initialization