mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-130000: Release the GIL in winreg when doing Windows API calls (GH-130001)
This commit is contained in:
parent
6a22963291
commit
7a504b3d5d
1 changed files with 32 additions and 9 deletions
41
PC/winreg.c
41
PC/winreg.c
|
@ -426,7 +426,9 @@ PyHKEY_Close(winreg_state *st, PyObject *ob_handle)
|
||||||
if (PyHKEY_Check(st, ob_handle)) {
|
if (PyHKEY_Check(st, ob_handle)) {
|
||||||
((PyHKEYObject*)ob_handle)->hkey = 0;
|
((PyHKEYObject*)ob_handle)->hkey = 0;
|
||||||
}
|
}
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = key ? RegCloseKey(key) : ERROR_SUCCESS;
|
rc = key ? RegCloseKey(key) : ERROR_SUCCESS;
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
||||||
return rc == ERROR_SUCCESS;
|
return rc == ERROR_SUCCESS;
|
||||||
|
@ -499,14 +501,21 @@ PyWinObject_CloseHKEY(winreg_state *st, PyObject *obHandle)
|
||||||
}
|
}
|
||||||
#if SIZEOF_LONG >= SIZEOF_HKEY
|
#if SIZEOF_LONG >= SIZEOF_HKEY
|
||||||
else if (PyLong_Check(obHandle)) {
|
else if (PyLong_Check(obHandle)) {
|
||||||
long rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle));
|
long rc;
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle));
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
ok = (rc == ERROR_SUCCESS);
|
ok = (rc == ERROR_SUCCESS);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else if (PyLong_Check(obHandle)) {
|
else if (PyLong_Check(obHandle)) {
|
||||||
long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
|
long rc;
|
||||||
|
HKEY hkey = (HKEY)PyLong_AsVoidPtr(obHandle);
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
rc = RegCloseKey(hkey);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
ok = (rc == ERROR_SUCCESS);
|
ok = (rc == ERROR_SUCCESS);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
|
||||||
|
@ -924,7 +933,9 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
|
||||||
(Py_ssize_t)KEY_WRITE) < 0) {
|
(Py_ssize_t)KEY_WRITE) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegCreateKeyW(key, sub_key, &retKey);
|
rc = RegCreateKeyW(key, sub_key, &retKey);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
if (rc != ERROR_SUCCESS) {
|
if (rc != ERROR_SUCCESS) {
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
|
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -973,8 +984,10 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
|
||||||
(Py_ssize_t)access) < 0) {
|
(Py_ssize_t)access) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
|
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
|
||||||
access, NULL, &retKey, NULL);
|
access, NULL, &retKey, NULL);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
if (rc != ERROR_SUCCESS) {
|
if (rc != ERROR_SUCCESS) {
|
||||||
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
|
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1187,10 +1200,12 @@ winreg_EnumValue_impl(PyObject *module, HKEY key, int index)
|
||||||
(Py_ssize_t)key, index) < 0) {
|
(Py_ssize_t)key, index) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
||||||
NULL,
|
Py_BEGIN_ALLOW_THREADS
|
||||||
&retValueSize, &retDataSize, NULL, NULL))
|
rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||||
!= ERROR_SUCCESS)
|
&retValueSize, &retDataSize, NULL, NULL);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
if (rc != ERROR_SUCCESS)
|
||||||
return PyErr_SetFromWindowsErrWithFunction(rc,
|
return PyErr_SetFromWindowsErrWithFunction(rc,
|
||||||
"RegQueryInfoKey");
|
"RegQueryInfoKey");
|
||||||
++retValueSize; /* include null terminators */
|
++retValueSize; /* include null terminators */
|
||||||
|
@ -1477,9 +1492,11 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key)
|
||||||
if (PySys_Audit("winreg.QueryInfoKey", "n", (Py_ssize_t)key) < 0) {
|
if (PySys_Audit("winreg.QueryInfoKey", "n", (Py_ssize_t)key) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((rc = RegQueryInfoKeyW(key, NULL, NULL, 0, &nSubKeys, NULL, NULL,
|
Py_BEGIN_ALLOW_THREADS
|
||||||
&nValues, NULL, NULL, NULL, &ft))
|
rc = RegQueryInfoKeyW(key, NULL, NULL, 0, &nSubKeys, NULL, NULL,
|
||||||
!= ERROR_SUCCESS) {
|
&nValues, NULL, NULL, NULL, &ft);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
if (rc != ERROR_SUCCESS) {
|
||||||
return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
|
return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
|
||||||
}
|
}
|
||||||
li.LowPart = ft.dwLowDateTime;
|
li.LowPart = ft.dwLowDateTime;
|
||||||
|
@ -1587,7 +1604,9 @@ exit:
|
||||||
PyMem_Free(pbuf);
|
PyMem_Free(pbuf);
|
||||||
}
|
}
|
||||||
if (childKey != key) {
|
if (childKey != key) {
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
RegCloseKey(childKey);
|
RegCloseKey(childKey);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1625,7 +1644,9 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const wchar_t *name)
|
||||||
(Py_ssize_t)key, NULL, name) < 0) {
|
(Py_ssize_t)key, NULL, name) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegQueryValueExW(key, name, NULL, NULL, NULL, &bufSize);
|
rc = RegQueryValueExW(key, name, NULL, NULL, NULL, &bufSize);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
if (rc == ERROR_MORE_DATA)
|
if (rc == ERROR_MORE_DATA)
|
||||||
bufSize = 256;
|
bufSize = 256;
|
||||||
else if (rc != ERROR_SUCCESS)
|
else if (rc != ERROR_SUCCESS)
|
||||||
|
@ -1637,8 +1658,10 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const wchar_t *name)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
retSize = bufSize;
|
retSize = bufSize;
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rc = RegQueryValueExW(key, name, NULL, &typ,
|
rc = RegQueryValueExW(key, name, NULL, &typ,
|
||||||
(BYTE *)retBuf, &retSize);
|
(BYTE *)retBuf, &retSize);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
if (rc != ERROR_MORE_DATA)
|
if (rc != ERROR_MORE_DATA)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue