]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95423: Update winreg.DeleteKeyEx documentation and remove dynamic function load...
authorDerek Kim <ddkim1024@gmail.com>
Wed, 3 Aug 2022 20:55:03 +0000 (15:55 -0500)
committerGitHub <noreply@github.com>
Wed, 3 Aug 2022 20:55:03 +0000 (21:55 +0100)
Doc/library/winreg.rst
Misc/ACKS
PC/clinic/winreg.c.h
PC/winreg.c

index 487856a3ac6c60050e7e4e320333d935f3d88522..4ab671817710dd723a6b19b0301ae39aa53b3da2 100644 (file)
@@ -144,12 +144,6 @@ This module offers the following functions:
 
    Deletes the specified key.
 
-   .. note::
-      The :func:`DeleteKeyEx` function is implemented with the RegDeleteKeyEx
-      Windows API function, which is specific to 64-bit versions of Windows.
-      See the `RegDeleteKeyEx documentation
-      <https://msdn.microsoft.com/en-us/library/ms724847%28VS.85%29.aspx>`__.
-
    *key* is an already open key, or one of the predefined
    :ref:`HKEY_* constants <hkey-constants>`.
 
@@ -159,9 +153,10 @@ This module offers the following functions:
 
    *reserved* is a reserved integer, and must be zero. The default is zero.
 
-   *access* is an integer that specifies an access mask that describes the desired
-   security access for the key.  Default is :const:`KEY_WOW64_64KEY`.  See
-   :ref:`Access Rights <access-rights>` for other allowed values.
+   *access* is an integer that specifies an access mask that describes the
+   desired security access for the key.  Default is :const:`KEY_WOW64_64KEY`.
+   On 32-bit Windows, the WOW64 constants are ignored.
+   See :ref:`Access Rights <access-rights>` for other allowed values.
 
    *This method can not delete keys with subkeys.*
 
@@ -658,13 +653,12 @@ For more information, see `Accessing an Alternate Registry View
 .. data:: KEY_WOW64_64KEY
 
    Indicates that an application on 64-bit Windows should operate on
-   the 64-bit registry view.
+   the 64-bit registry view. On 32-bit Windows, this constant is ignored.
 
 .. data:: KEY_WOW64_32KEY
 
    Indicates that an application on 64-bit Windows should operate on
-   the 32-bit registry view.
-
+   the 32-bit registry view. On 32-bit Windows, this constant is ignored.
 
 .. _value-types:
 
index 32475f874c36db74e19746276cf253582d5330f2..b18fabe09ef4f818d7bc120e4b6eee5bcce42699 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -917,6 +917,7 @@ Sanyam Khurana
 Tyler Kieft
 Mads Kiilerich
 Jason Killen
+Derek D. Kim
 Jan Kim
 Taek Joo Kim
 Sam Kimbrel
index 1e64b1eedeb3eabcc04d10da03364d58acf83950..7b0624919212be845785fd0da94c535502407c56 100644 (file)
@@ -405,7 +405,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"
@@ -419,6 +419,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"
@@ -1455,4 +1458,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=504fc17ae25a7c75 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3faa63af6fd1653c input=a9049054013a1b77]*/
index b326c3dfd2c782b70496b4b113af4bcf091b0e32..6ae0d8169cc56b346d5eb8af4d2d2984ccb81d46 100644 (file)
@@ -979,7 +979,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;
@@ -1000,7 +1002,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.
 
@@ -1013,34 +1018,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;