]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert "bpo-39413: Implement os.unsetenv() on Windows (GH-18104)" (GH-18124)
authorVictor Stinner <vstinner@python.org>
Wed, 22 Jan 2020 20:11:17 +0000 (21:11 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Jan 2020 20:11:17 +0000 (21:11 +0100)
This reverts commit 56cd3710a1ea3ba872d345ea1bebc86ed08bc8b8.

Doc/library/os.rst
Doc/whatsnew/3.9.rst
Lib/test/test_os.py
Misc/NEWS.d/next/Library/2020-01-21-15-48-35.bpo-39413.7XYDM8.rst [deleted file]
Modules/clinic/posixmodule.c.h
Modules/posixmodule.c

index de3e5603e109fea50b5448d3b907b02dcbddd7aa..4fec647828e25067f2e103ce384eae76a1cb122e 100644 (file)
@@ -645,9 +645,6 @@ process and user.
 
    .. availability:: most flavors of Unix, Windows.
 
-   .. versionchanged:: 3.9
-      The function is now also available on Windows.
-
 
 .. _os-newstreams:
 
index 0e82ff0695d3ee020ff7e5131b6ee2f73ba174cd..f5835d68515ac23bfad20a7ae2102509de061c6e 100644 (file)
@@ -216,9 +216,6 @@ Exposed the Linux-specific :func:`os.pidfd_open` (:issue:`38692`) and
 :data:`os.P_PIDFD` (:issue:`38713`) for process management with file
 descriptors.
 
-The :func:`os.unsetenv` function is now also available on Windows.
-(Contributed by Victor Stinner in :issue:`39413`.)
-
 poplib
 ------
 
index 50535da0a2bfc10e3bae54a46a4c3571842ad20c..82c441c204835a5fcf752a7368583baa3c276eb6 100644 (file)
@@ -956,9 +956,14 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
     # On OS X < 10.6, unsetenv() doesn't return a value (bpo-13415).
     @support.requires_mac_ver(10, 6)
     def test_unset_error(self):
-        # "=" is not allowed in a variable name
-        key = 'key='
-        self.assertRaises(OSError, os.environ.__delitem__, key)
+        if sys.platform == "win32":
+            # an environment variable is limited to 32,767 characters
+            key = 'x' * 50000
+            self.assertRaises(ValueError, os.environ.__delitem__, key)
+        else:
+            # "=" is not allowed in a variable name
+            key = 'key='
+            self.assertRaises(OSError, os.environ.__delitem__, key)
 
     def test_key_type(self):
         missing = 'missingkey'
diff --git a/Misc/NEWS.d/next/Library/2020-01-21-15-48-35.bpo-39413.7XYDM8.rst b/Misc/NEWS.d/next/Library/2020-01-21-15-48-35.bpo-39413.7XYDM8.rst
deleted file mode 100644 (file)
index a185ab5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-The :func:`os.unsetenv` function is now also available on Windows.
index 661d91afb7eb6f04b4e72246b304d1bcb396049b..aa4756a620aae5f4ae5bd15c41f198a9907b6775 100644 (file)
@@ -6125,43 +6125,7 @@ exit:
 
 #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
 
-#if defined(MS_WINDOWS)
-
-PyDoc_STRVAR(os_unsetenv__doc__,
-"unsetenv($module, name, /)\n"
-"--\n"
-"\n"
-"Delete an environment variable.");
-
-#define OS_UNSETENV_METHODDEF    \
-    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
-
-static PyObject *
-os_unsetenv_impl(PyObject *module, PyObject *name);
-
-static PyObject *
-os_unsetenv(PyObject *module, PyObject *arg)
-{
-    PyObject *return_value = NULL;
-    PyObject *name;
-
-    if (!PyUnicode_Check(arg)) {
-        _PyArg_BadArgument("unsetenv", "argument", "str", arg);
-        goto exit;
-    }
-    if (PyUnicode_READY(arg) == -1) {
-        goto exit;
-    }
-    name = arg;
-    return_value = os_unsetenv_impl(module, name);
-
-exit:
-    return return_value;
-}
-
-#endif /* defined(MS_WINDOWS) */
-
-#if (defined(HAVE_UNSETENV) && !defined(MS_WINDOWS))
+#if defined(HAVE_UNSETENV)
 
 PyDoc_STRVAR(os_unsetenv__doc__,
 "unsetenv($module, name, /)\n"
@@ -6193,7 +6157,7 @@ exit:
     return return_value;
 }
 
-#endif /* (defined(HAVE_UNSETENV) && !defined(MS_WINDOWS)) */
+#endif /* defined(HAVE_UNSETENV) */
 
 PyDoc_STRVAR(os_strerror__doc__,
 "strerror($module, code, /)\n"
@@ -8809,4 +8773,4 @@ exit:
 #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
     #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
 #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
-/*[clinic end generated code: output=6e739a2715712e88 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=51ba5b9536420cea input=a9049054013a1b77]*/
index 5a0c8a311a790eb371ad7a8c858ccf5e8e648de6..e0eecfa6d1143e23a0c9c31f8854c93f311bda7e 100644 (file)
@@ -10180,51 +10180,7 @@ os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
 #endif /* HAVE_PUTENV */
 
 
-#ifdef MS_WINDOWS
-/*[clinic input]
-os.unsetenv
-    name: unicode
-    /
-
-Delete an environment variable.
-[clinic start generated code]*/
-
-static PyObject *
-os_unsetenv_impl(PyObject *module, PyObject *name)
-/*[clinic end generated code: output=54c4137ab1834f02 input=4d6a1747cc526d2f]*/
-{
-    /* PyUnicode_AsWideCharString() rejects embedded null characters */
-    wchar_t *name_str = PyUnicode_AsWideCharString(name, NULL);
-    if (name_str == NULL) {
-        return NULL;
-    }
-
-    BOOL ok = SetEnvironmentVariableW(name_str, NULL);
-    PyMem_Free(name_str);
-
-    if (!ok) {
-        return PyErr_SetFromWindowsErr(0);
-    }
-
-#ifdef PY_PUTENV_DICT
-    /* Remove the key from putenv_dict;
-     * this will cause it to be collected.  This has to
-     * happen after the real unsetenv() call because the
-     * old value was still accessible until then.
-     */
-    if (PyDict_DelItem(_posixstate(module)->putenv_dict, name)) {
-        /* really not much we can do; just leak */
-        if (!PyErr_ExceptionMatches(PyExc_KeyError)) {
-            return NULL;
-        }
-        PyErr_Clear();
-    }
-#endif
-
-    Py_RETURN_NONE;
-}
-/* repeat !defined(MS_WINDOWS) to workaround an Argument Clinic issue */
-#elif defined(HAVE_UNSETENV) && !defined(MS_WINDOWS)
+#ifdef HAVE_UNSETENV
 /*[clinic input]
 os.unsetenv
     name: FSConverter