[Python-checkins] bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)

Victor Stinner webhook-mailer at python.org
Wed Jan 22 15:53:34 EST 2020


https://github.com/python/cpython/commit/0852c7dd52ac42e7843ddfef44571494e4c86070
commit: 0852c7dd52ac42e7843ddfef44571494e4c86070
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-01-22T21:53:26+01:00
summary:

bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)

Windows: _wputenv(env) copies the *env* string and doesn't require
the caller to manage the variable memory.

files:
M Modules/posixmodule.c

diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e0eecfa6d1143..71b99fd836f15 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -819,7 +819,9 @@ dir_fd_converter(PyObject *o, void *p)
     }
 }
 
-#ifdef HAVE_PUTENV
+/* Windows: _wputenv(env) copies the *env* string and doesn't require the
+   caller to manage the variable memory. */
+#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
 #  define PY_PUTENV_DICT
 #endif
 
@@ -10130,8 +10132,10 @@ os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
         posix_error();
         goto error;
     }
+    /* _wputenv(env) copies the *env* string and doesn't require the caller
+       to manage the variable memory. */
+    Py_DECREF(unicode);
 
-    posix_putenv_dict_setitem(name, unicode);
     Py_RETURN_NONE;
 
 error:



More information about the Python-checkins mailing list