@@ -148,8 +148,8 @@ private
148148 {
149149 version (Darwin)
150150 {
151- extern (C ) char *** _NSGetEnviron() nothrow ;
152- const (char ** ) getEnvironPtr () @trusted
151+ extern (C ) char *** _NSGetEnviron() @nogc nothrow ;
152+ const (char ** ) getEnvironPtr () @trusted @nogc nothrow
153153 {
154154 return * _NSGetEnviron;
155155 }
@@ -158,7 +158,7 @@ private
158158 {
159159 // Made available by the C runtime:
160160 extern (C ) extern __gshared const char ** environ;
161- const (char ** ) getEnvironPtr () @trusted
161+ const (char ** ) getEnvironPtr () @trusted @nogc nothrow
162162 {
163163 return environ;
164164 }
@@ -1221,7 +1221,7 @@ private Pid spawnProcessPosix(scope const(char[])[] args,
12211221 }
12221222
12231223 // Execute program.
1224- core.sys.posix.unistd.execve (argz[0 ], argz.ptr, envz);
1224+ core.sys.posix.unistd.execve (argz[0 ], argz.ptr, envz is null ? getEnvironPtr : envz );
12251225
12261226 // If execution fails, exit as quickly as possible.
12271227 abortOnError(forkPipeOut, InternalError.exec, .errno);
@@ -1527,7 +1527,7 @@ private Pid spawnProcessWin(scope const(char)[] commandLine,
15271527// on the form "name=value", optionally adding those of the current process'
15281528// environment strings that are not present in childEnv. If the parent's
15291529// environment should be inherited without modification, this function
1530- // returns environ directly .
1530+ // returns null .
15311531version (Posix )
15321532private const (char * )* createEnv (const string [string ] childEnv,
15331533 bool mergeWithParentEnv)
@@ -1537,7 +1537,7 @@ private const(char*)* createEnv(const string[string] childEnv,
15371537 auto environ = getEnvironPtr;
15381538 if (mergeWithParentEnv)
15391539 {
1540- if (childEnv.length == 0 ) return environ ;
1540+ if (childEnv.length == 0 ) return null ;
15411541 while (environ[parentEnvLength] != null ) ++ parentEnvLength;
15421542 }
15431543
@@ -1567,16 +1567,7 @@ version (Posix) @system unittest
15671567 assert (e1 != null && * e1 == null );
15681568
15691569 auto e2 = createEnv(null , true );
1570- assert (e2 != null );
1571- int i = 0 ;
1572- auto environ = getEnvironPtr;
1573- for (; environ[i] != null ; ++ i)
1574- {
1575- assert (e2[i] != null );
1576- import core.stdc.string : strcmp;
1577- assert (strcmp(e2[i], environ[i]) == 0 );
1578- }
1579- assert (e2[i] == null );
1570+ assert (e2 == null );
15801571
15811572 auto e3 = createEnv([" foo" : " bar" , " hello" : " world" ], false );
15821573 assert (e3 != null && e3[0 ] != null && e3[1 ] != null && e3[2 ] == null );
0 commit comments