diff -r 8167951e1569 Lib/test/test_os.py --- a/Lib/test/test_os.py Tue Sep 08 15:33:33 2015 -0400 +++ b/Lib/test/test_os.py Tue Sep 08 23:40:07 2015 +0200 @@ -1212,10 +1212,11 @@ class URandomTests(unittest.TestCase): self.assertNotEqual(data1, data2) -HAVE_GETENTROPY = (sysconfig.get_config_var('HAVE_GETENTROPY') == 1) +USE_GETENTROPY = ((sysconfig.get_config_var('HAVE_GETENTROPY') == 1) + and not sys.platform.startswith("sunos")) HAVE_GETRANDOM = (sysconfig.get_config_var('HAVE_GETRANDOM_SYSCALL') == 1) -@unittest.skipIf(HAVE_GETENTROPY, +@unittest.skipIf(USE_GETENTROPY, "getentropy() does not use a file descriptor") @unittest.skipIf(HAVE_GETRANDOM, "getrandom() does not use a file descriptor") diff -r 8167951e1569 Python/random.c --- a/Python/random.c Tue Sep 08 15:33:33 2015 -0400 +++ b/Python/random.c Tue Sep 08 23:40:07 2015 +0200 @@ -11,6 +11,13 @@ # endif #endif +/* Solaris 11.3 provides getrandom() and getentropy(). getentropy() cannot be + used for os.urandom() because it is blocking, it. Use + getrandom(GRND_NONBLOCK) instead, it is non-blocking. */ +#if defined(HAVE_GETENTROPY) && !defined(sun) +# define USE_GETENTROPY +#endif + #ifdef Py_DEBUG int _Py_HashSecret_Initialized = 0; #else @@ -70,7 +77,7 @@ win32_urandom(unsigned char *buffer, Py_ return 0; } -#elif HAVE_GETENTROPY +#elif defined(USE_GETENTROPY) /* Fill buffer with size pseudo-random bytes generated by getentropy(). Return 0 on success, or raise an exception and return -1 on error. @@ -105,7 +112,7 @@ py_getentropy(unsigned char *buffer, Py_ return 0; } -#else /* !HAVE_GETENTROPY */ +#else /* !USE_GETENTROPY */ #ifdef HAVE_GETRANDOM_SYSCALL static int @@ -304,7 +311,7 @@ dev_urandom_close(void) } } -#endif /* HAVE_GETENTROPY */ +#endif /* Fill buffer with pseudo-random bytes generated by a linear congruent generator (LCG): @@ -345,7 +352,7 @@ int #ifdef MS_WINDOWS return win32_urandom((unsigned char *)buffer, size, 1); -#elif HAVE_GETENTROPY +#elif defined(USE_GETENTROPY) return py_getentropy(buffer, size, 0); #else return dev_urandom_python((char*)buffer, size); @@ -392,7 +399,7 @@ void else { #ifdef MS_WINDOWS (void)win32_urandom(secret, secret_size, 0); -#elif HAVE_GETENTROPY +#elif defined(USE_GETENTROPY) (void)py_getentropy(secret, secret_size, 1); #else dev_urandom_noraise(secret, secret_size); @@ -408,7 +415,7 @@ void CryptReleaseContext(hCryptProv, 0); hCryptProv = 0; } -#elif HAVE_GETENTROPY +#elif defined(USE_GETENTROPY) /* nothing to clean */ #else dev_urandom_close();