Thread overview
[Issue 18425] std.process environment["VAR"] = "NAME" does not always take effect
Feb 12, 2018
Rainer Schuetze
Feb 12, 2018
Rainer Schuetze
Feb 16, 2018
Rainer Schuetze
Dec 17, 2022
Iain Buclaw
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18425

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de

--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> ---
Here's a simple test:

import std.process;
import core.stdc.stdlib;
import core.stdc.stdio;

extern(C) int putenv(const char*);

void main()
{
        putenv("DFLAGS=1");
        printf("1.DFLAGS=%s\n", getenv("DFLAGS"));
        environment["DLAGS"] = "2";
        printf("2.DFLAGS=%s\n", getenv("DFLAGS"));
        system("echo 3.DFLAGS=%DFLAGS%");
}

It prints "1" three times.

The issue is that the C runtime caches the environment changes, but std.process.environment bypasses the cache. Subsequent C runtime calls like getenv, system or spawn use the cached environment.

--
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18425

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--- Comment #2 from Rainer Schuetze <r.sagitario@gmx.de> ---
Happens with both dmc and VC libraries.

--
February 15, 2018
https://issues.dlang.org/show_bug.cgi?id=18425

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to Rainer Schuetze from comment #1)
> 	environment["DLAGS"] = "2";

Was this a hand-copied typo, or was there a typo in the original?

> The issue is that the C runtime caches the environment changes, but std.process.environment bypasses the cache. Subsequent C runtime calls like getenv, system or spawn use the cached environment.

Bleh, too bad we can't update snn.lib. This is like papering over the problem.

I looked at the code, and it's very complex, so I don't know that it's worth trying to fix.

--
February 16, 2018
https://issues.dlang.org/show_bug.cgi?id=18425

--- Comment #4 from Rainer Schuetze <r.sagitario@gmx.de> ---
> Was this a hand-copied typo, or was there a typo in the original?

Ooops. Typo is in the test only. The result with DFLAGS is the same, though.

> I looked at the code, and it's very complex, so I don't know that it's worth trying to fix.

We could do the same as for posix: call the C runtime instead of SetEnvironmentVariable. Both dmc and VC have _wputenv

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18425

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 01
https://issues.dlang.org/show_bug.cgi?id=18425

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10307

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--