mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
(Merge 3.4) Issue #22585: os.urandom() now releases the GIL when the
getentropy() is used (OpenBSD 5.6+).
This commit is contained in:
commit
81c6df5c0f
1 changed files with 14 additions and 6 deletions
|
@ -81,16 +81,24 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
|
||||||
{
|
{
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
Py_ssize_t len = Py_MIN(size, 256);
|
Py_ssize_t len = Py_MIN(size, 256);
|
||||||
int res = getentropy(buffer, len);
|
int res;
|
||||||
if (res < 0) {
|
|
||||||
if (fatal) {
|
if (!fatal) {
|
||||||
Py_FatalError("getentropy() failed");
|
Py_BEGIN_ALLOW_THREADS
|
||||||
}
|
res = getentropy(buffer, len);
|
||||||
else {
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
|
if (res < 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
res = getentropy(buffer, len);
|
||||||
|
if (res < 0)
|
||||||
|
Py_FatalError("getentropy() failed");
|
||||||
|
}
|
||||||
|
|
||||||
buffer += len;
|
buffer += len;
|
||||||
size -= len;
|
size -= len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue