gh-95423: Update winreg.DeleteKeyEx documentation and remove dynamic function load (GH-95521)

Co-authored-by: Derek Kim <ddkim1024@gmail.com>
This commit is contained in:
Steve Dower 2022-08-03 22:25:47 +01:00 committed by GitHub
parent a591c4701c
commit 1016df0a23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 35 deletions

7
PC/clinic/winreg.c.h generated
View file

@ -390,7 +390,7 @@ PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
" reserved=0)\n"
"--\n"
"\n"
"Deletes the specified key (64-bit OS only).\n"
"Deletes the specified key (intended for 64-bit OS).\n"
"\n"
" key\n"
" An already open key, or any one of the predefined HKEY_* constants.\n"
@ -404,6 +404,9 @@ PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
" reserved\n"
" A reserved integer, and must be zero. Default is zero.\n"
"\n"
"While this function is intended to be used for 64-bit OS, it is also\n"
" available on 32-bit systems.\n"
"\n"
"This method can not delete keys with subkeys.\n"
"\n"
"If the function succeeds, the entire key, including all of its values,\n"
@ -1346,4 +1349,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=c3454803528f6e97 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7ad1db69bc42cab4 input=a9049054013a1b77]*/

View file

@ -991,7 +991,9 @@ winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
(Py_ssize_t)0) < 0) {
return NULL;
}
rc = RegDeleteKeyW(key, sub_key );
Py_BEGIN_ALLOW_THREADS
rc = RegDeleteKeyW(key, sub_key);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS)
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
Py_RETURN_NONE;
@ -1012,7 +1014,10 @@ winreg.DeleteKeyEx
reserved: int = 0
A reserved integer, and must be zero. Default is zero.
Deletes the specified key (64-bit OS only).
Deletes the specified key (intended for 64-bit OS).
While this function is intended to be used for 64-bit OS, it is also
available on 32-bit systems.
This method can not delete keys with subkeys.
@ -1025,34 +1030,17 @@ static PyObject *
winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
const Py_UNICODE *sub_key, REGSAM access,
int reserved)
/*[clinic end generated code: output=52a1c8b374ebc003 input=711d9d89e7ecbed7]*/
/*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/
{
HMODULE hMod;
typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int);
RDKEFunc pfn = NULL;
long rc;
if (PySys_Audit("winreg.DeleteKey", "nun",
(Py_ssize_t)key, sub_key,
(Py_ssize_t)access) < 0) {
return NULL;
}
/* Only available on 64bit platforms, so we must load it
dynamically. */
Py_BEGIN_ALLOW_THREADS
hMod = GetModuleHandleW(L"advapi32.dll");
if (hMod)
pfn = (RDKEFunc)GetProcAddress(hMod, "RegDeleteKeyExW");
rc = RegDeleteKeyExW(key, sub_key, access, reserved);
Py_END_ALLOW_THREADS
if (!pfn) {
PyErr_SetString(PyExc_NotImplementedError,
"not implemented on this platform");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rc = (*pfn)(key, sub_key, access, reserved);
Py_END_ALLOW_THREADS
if (rc != ERROR_SUCCESS)
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
Py_RETURN_NONE;