Skip to content

Commit ebd6601

Browse files
authored
gh-95423: Update winreg.DeleteKeyEx documentation and remove dynamic function load (GH-95521)
1 parent 4d02572 commit ebd6601

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
@@ -979,7 +979,9 @@ winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
979979
(Py_ssize_t)0) < 0) {
980980
return NULL;
981981
}
982-
rc = RegDeleteKeyW(key, sub_key );
982+
Py_BEGIN_ALLOW_THREADS
983+
rc = RegDeleteKeyW(key, sub_key);
984+
Py_END_ALLOW_THREADS
983985
if (rc != ERROR_SUCCESS)
984986
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
985987
Py_RETURN_NONE;
@@ -1000,7 +1002,10 @@ winreg.DeleteKeyEx
10001002
reserved: int = 0
10011003
A reserved integer, and must be zero. Default is zero.
10021004
1003-
Deletes the specified key (64-bit OS only).
1005+
Deletes the specified key (intended for 64-bit OS).
1006+
1007+
While this function is intended to be used for 64-bit OS, it is also
1008+
available on 32-bit systems.
10041009
10051010
This method can not delete keys with subkeys.
10061011
@@ -1013,34 +1018,17 @@ static PyObject *
10131018
winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
10141019
const Py_UNICODE *sub_key, REGSAM access,
10151020
int reserved)
1016-
/*[clinic end generated code: output=52a1c8b374ebc003 input=711d9d89e7ecbed7]*/
1021+
/*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/
10171022
{
1018-
HMODULE hMod;
1019-
typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int);
1020-
RDKEFunc pfn = NULL;
10211023
long rc;
1022-
10231024
if (PySys_Audit("winreg.DeleteKey", "nun",
10241025
(Py_ssize_t)key, sub_key,
10251026
(Py_ssize_t)access) < 0) {
10261027
return NULL;
10271028
}
1028-
/* Only available on 64bit platforms, so we must load it
1029-
dynamically. */
10301029
Py_BEGIN_ALLOW_THREADS
1031-
hMod = GetModuleHandleW(L"advapi32.dll");
1032-
if (hMod)
1033-
pfn = (RDKEFunc)GetProcAddress(hMod, "RegDeleteKeyExW");
1030+
rc = RegDeleteKeyExW(key, sub_key, access, reserved);
10341031
Py_END_ALLOW_THREADS
1035-
if (!pfn) {
1036-
PyErr_SetString(PyExc_NotImplementedError,
1037-
"not implemented on this platform");
1038-
return NULL;
1039-
}
1040-
Py_BEGIN_ALLOW_THREADS
1041-
rc = (*pfn)(key, sub_key, access, reserved);
1042-
Py_END_ALLOW_THREADS
1043-
10441032
if (rc != ERROR_SUCCESS)
10451033
return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
10461034
Py_RETURN_NONE;

0 commit comments

Comments
 (0)