Skip to content

Commit 1016df0

Browse files
zoobaderekdkim
andauthored
gh-95423: Update winreg.DeleteKeyEx documentation and remove dynamic function load (GH-95521)
Co-authored-by: Derek Kim <[email protected]>
1 parent a591c47 commit 1016df0

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

Doc/library/winreg.rst

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ This module offers the following functions:
144144

145145
Deletes the specified key.
146146

147-
.. note::
148-
The :func:`DeleteKeyEx` function is implemented with the RegDeleteKeyEx
149-
Windows API function, which is specific to 64-bit versions of Windows.
150-
See the `RegDeleteKeyEx documentation
151-
<https://msdn.microsoft.com/en-us/library/ms724847%28VS.85%29.aspx>`__.
152-
153147
*key* is an already open key, or one of the predefined
154148
:ref:`HKEY_* constants <hkey-constants>`.
155149

@@ -159,9 +153,10 @@ This module offers the following functions:
159153

160154
*reserved* is a reserved integer, and must be zero. The default is zero.
161155

162-
*access* is an integer that specifies an access mask that describes the desired
163-
security access for the key. Default is :const:`KEY_WOW64_64KEY`. See
164-
:ref:`Access Rights <access-rights>` for other allowed values.
156+
*access* is an integer that specifies an access mask that describes the
157+
desired security access for the key. Default is :const:`KEY_WOW64_64KEY`.
158+
On 32-bit Windows, the WOW64 constants are ignored.
159+
See :ref:`Access Rights <access-rights>` for other allowed values.
165160

166161
*This method can not delete keys with subkeys.*
167162

@@ -658,13 +653,12 @@ For more information, see `Accessing an Alternate Registry View
658653
.. data:: KEY_WOW64_64KEY
659654

660655
Indicates that an application on 64-bit Windows should operate on
661-
the 64-bit registry view.
656+
the 64-bit registry view. On 32-bit Windows, this constant is ignored.
662657

663658
.. data:: KEY_WOW64_32KEY
664659

665660
Indicates that an application on 64-bit Windows should operate on
666-
the 32-bit registry view.
667-
661+
the 32-bit registry view. On 32-bit Windows, this constant is ignored.
668662

669663
.. _value-types:
670664

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ Sanyam Khurana
917917
Tyler Kieft
918918
Mads Kiilerich
919919
Jason Killen
920+
Derek D. Kim
920921
Jan Kim
921922
Taek Joo Kim
922923
Sam Kimbrel

PC/clinic/winreg.c.h

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/winreg.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,9 @@ winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
991991
(Py_ssize_t)0) < 0) {
992992
return NULL;
993993
}
994-
rc = RegDeleteKeyW(key, sub_key );
994+
Py_BEGIN_ALLOW_THREADS
995+
rc = RegDeleteKeyW(key, sub_key);
996+
Py_END_ALLOW_THREADS
995997
if (rc != ERROR_SUCCESS)
996998
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
997999
Py_RETURN_NONE;
@@ -1012,7 +1014,10 @@ winreg.DeleteKeyEx
10121014
reserved: int = 0
10131015
A reserved integer, and must be zero. Default is zero.
10141016
1015-
Deletes the specified key (64-bit OS only).
1017+
Deletes the specified key (intended for 64-bit OS).
1018+
1019+
While this function is intended to be used for 64-bit OS, it is also
1020+
available on 32-bit systems.
10161021
10171022
This method can not delete keys with subkeys.
10181023
@@ -1025,34 +1030,17 @@ static PyObject *
10251030
winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
10261031
const Py_UNICODE *sub_key, REGSAM access,
10271032
int reserved)
1028-
/*[clinic end generated code: output=52a1c8b374ebc003 input=711d9d89e7ecbed7]*/
1033+
/*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/
10291034
{
1030-
HMODULE hMod;
1031-
typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int);
1032-
RDKEFunc pfn = NULL;
10331035
long rc;
1034-
10351036
if (PySys_Audit("winreg.DeleteKey", "nun",
10361037
(Py_ssize_t)key, sub_key,
10371038
(Py_ssize_t)access) < 0) {
10381039
return NULL;
10391040
}
1040-
/* Only available on 64bit platforms, so we must load it
1041-
dynamically. */
10421041
Py_BEGIN_ALLOW_THREADS
1043-
hMod = GetModuleHandleW(L"advapi32.dll");
1044-
if (hMod)
1045-
pfn = (RDKEFunc)GetProcAddress(hMod, "RegDeleteKeyExW");
1042+
rc = RegDeleteKeyExW(key, sub_key, access, reserved);
10461043
Py_END_ALLOW_THREADS
1047-
if (!pfn) {
1048-
PyErr_SetString(PyExc_NotImplementedError,
1049-
"not implemented on this platform");
1050-
return NULL;
1051-
}
1052-
Py_BEGIN_ALLOW_THREADS
1053-
rc = (*pfn)(key, sub_key, access, reserved);
1054-
Py_END_ALLOW_THREADS
1055-
10561044
if (rc != ERROR_SUCCESS)
10571045
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
10581046
Py_RETURN_NONE;

0 commit comments

Comments
 (0)