[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
STINNER Victor added the comment: The initial issue has been fixed, so I close the issue. Big thanks to Eryk Sun for your great help, thanks also Serhiy Storchaka. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
STINNER Victor added the comment: Serhiy: > Maybe use SetEnvironmentVariable() on Windows? In bpo-39413, I implemented os.unsetenv() on Windows using SetEnvironmentVariable(), but Eryk reported that SetEnvironmentVariable() does not update the CRT API (_environ, _wenviron, getenv, etc.). So

[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
STINNER Victor added the comment: New changeset b477d19a6b7751b0c933b239dae4fc96dbcde9c4 by Victor Stinner in branch 'master': bpo-39406: Implement os.putenv() with setenv() if available (GH-18128) https://github.com/python/cpython/commit/b477d19a6b7751b0c933b239dae4fc96dbcde9c4 --

[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +17515 pull_request: https://github.com/python/cpython/pull/18128 ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
STINNER Victor added the comment: New changeset 0852c7dd52ac42e7843ddfef44571494e4c86070 by Victor Stinner in branch 'master': bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126) https://github.com/python/cpython/commit/0852c7dd52ac42e7843ddfef44571494e4c86070 --

[issue39406] Implement os.putenv() with setenv() if available

2020-01-22 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +17513 pull_request: https://github.com/python/cpython/pull/18126 ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Eryk Sun
Eryk Sun added the comment: > Python can safely removes the string to _putenv() just after the call? Windows ucrt copies the buffer that's passed to _[w]putenv. This makes it non-compliant with POSIX but easier to use in this case. Here's an example using ctypes: >>> ucrt =

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Why posix_putenv_garbage was renamed to putenv_dict? -- ___ Python tracker ___ ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There is also _wputenv_s which affects _spawn, _exec and system. -- ___ Python tracker ___ ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
STINNER Victor added the comment: New changeset 623ed6171eae35af7fd2e804dfd9c832c05c5d48 by Victor Stinner in branch 'master': bpo-39406: Add PY_PUTENV_DICT macro to posixmodule.c (GH-18106) https://github.com/python/cpython/commit/623ed6171eae35af7fd2e804dfd9c832c05c5d48 --

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
STINNER Victor added the comment: I created bpo-39413 "Implement os.unsetenv() on Windows" to prepare work on this issue. But Eryk raised the same concern about CRT: https://bugs.python.org/issue39413#msg360404 I wasn't aware of that :-/ > `_wputenv` keeps Python's copy of the environment

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +17495 pull_request: https://github.com/python/cpython/pull/18106 ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This indeed a good argument to continue to use _wputenv. Thank you Eryk, you have saved us from making a mistake. -- ___ Python tracker

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Eryk Sun
Eryk Sun added the comment: > Maybe use SetEnvironmentVariable() on Windows? `_wputenv` keeps Python's copy of the environment block in sync with CRT's copy, which in turn calls `SetEnvironmentVariableW` to sync with process environment block. The CRT's copy of the environment excludes and

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
STINNER Victor added the comment: > Maybe use SetEnvironmentVariable() on Windows? I didn't know this function. I updated PR 18095. -- ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Maybe use SetEnvironmentVariable() on Windows? -- nosy: +serhiy.storchaka ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
STINNER Victor added the comment: setenv() is available on: * Linux: http://man7.org/linux/man-pages/man3/setenv.3.html * macOS: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/setenv.3.html * FreeBSD:

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
Change by STINNER Victor : -- keywords: +patch pull_requests: +17485 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18095 ___ Python tracker ___

[issue39406] Implement os.putenv() with setenv() if available

2020-01-21 Thread STINNER Victor
New submission from STINNER Victor : Currently, os.putenv() is always implemented with putenv(). The problem is that putenv(str) puts directly the string into the environment, the string is not copied. So Python has to keep track of this memory. In Python 3.9, this string is now cleared at