Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions PC/winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ PyHKEY_Close(winreg_state *st, PyObject *ob_handle)
if (PyHKEY_Check(st, ob_handle)) {
((PyHKEYObject*)ob_handle)->hkey = 0;
}
Py_BEGIN_ALLOW_THREADS
rc = key ? RegCloseKey(key) : ERROR_SUCCESS;
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS)
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
return rc == ERROR_SUCCESS;
Expand Down Expand Up @@ -499,14 +501,21 @@ PyWinObject_CloseHKEY(winreg_state *st, PyObject *obHandle)
}
#if SIZEOF_LONG >= SIZEOF_HKEY
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);
if (!ok)
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
}
#else
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);
if (!ok)
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
Expand Down Expand Up @@ -924,7 +933,9 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
(Py_ssize_t)KEY_WRITE) < 0) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rc = RegCreateKeyW(key, sub_key, &retKey);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS) {
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
return NULL;
Expand Down Expand Up @@ -973,8 +984,10 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
(Py_ssize_t)access) < 0) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
access, NULL, &retKey, NULL);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS) {
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
return NULL;
Expand Down Expand Up @@ -1187,10 +1200,12 @@ winreg_EnumValue_impl(PyObject *module, HKEY key, int index)
(Py_ssize_t)key, index) < 0) {
return NULL;
}
if ((rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL,
NULL,
&retValueSize, &retDataSize, NULL, NULL))
!= ERROR_SUCCESS)

Py_BEGIN_ALLOW_THREADS
rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&retValueSize, &retDataSize, NULL, NULL);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS)
return PyErr_SetFromWindowsErrWithFunction(rc,
"RegQueryInfoKey");
++retValueSize; /* include null terminators */
Expand Down Expand Up @@ -1477,9 +1492,11 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key)
if (PySys_Audit("winreg.QueryInfoKey", "n", (Py_ssize_t)key) < 0) {
return NULL;
}
if ((rc = RegQueryInfoKeyW(key, NULL, NULL, 0, &nSubKeys, NULL, NULL,
&nValues, NULL, NULL, NULL, &ft))
!= ERROR_SUCCESS) {
Py_BEGIN_ALLOW_THREADS
rc = RegQueryInfoKeyW(key, NULL, NULL, 0, &nSubKeys, NULL, NULL,
&nValues, NULL, NULL, NULL, &ft);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS) {
return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
}
li.LowPart = ft.dwLowDateTime;
Expand Down Expand Up @@ -1587,7 +1604,9 @@ winreg_QueryValue_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
PyMem_Free(pbuf);
}
if (childKey != key) {
Py_BEGIN_ALLOW_THREADS
RegCloseKey(childKey);
Py_END_ALLOW_THREADS
}
return result;
}
Expand Down Expand Up @@ -1625,7 +1644,9 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const wchar_t *name)
(Py_ssize_t)key, NULL, name) < 0) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rc = RegQueryValueExW(key, name, NULL, NULL, NULL, &bufSize);
Py_END_ALLOW_THREADS
if (rc == ERROR_MORE_DATA)
bufSize = 256;
else if (rc != ERROR_SUCCESS)
Expand All @@ -1637,8 +1658,10 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const wchar_t *name)

while (1) {
retSize = bufSize;
Py_BEGIN_ALLOW_THREADS
rc = RegQueryValueExW(key, name, NULL, &typ,
(BYTE *)retBuf, &retSize);
Py_END_ALLOW_THREADS
if (rc != ERROR_MORE_DATA)
break;

Expand Down
Loading