[llvm-commits] [llvm] r52284 - /llvm/trunk/lib/System/Win32/Program.inc
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Jun 14 20:54:40 PDT 2008
Author: akirtzidis
Date: Sat Jun 14 22:54:39 2008
New Revision: 52284
URL: http://llvm.org/viewvc/llvm-project?rev=52284&view=rev
Log:
Fix the environment block that is passed to the CreateProcess function.
This bug made llvm-ld unable to function with "-native" option, since the process that was used to call 'gcc' was crashing.
Modified:
llvm/trunk/lib/System/Win32/Program.inc
Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=52284&r1=52283&r2=52284&view=diff
==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Sat Jun 14 22:54:39 2008
@@ -154,6 +154,33 @@
*p = 0;
+ // The pointer to the environment block for the new process.
+ char *envblock = 0;
+
+ if (envp) {
+ // An environment block consists of a null-terminated block of
+ // null-terminated strings. Convert the array of environment variables to
+ // an environment block by concatenating them.
+
+ // First, determine the length of the environment block.
+ len = 0;
+ for (unsigned i = 0; envp[i]; i++)
+ len += strlen(envp[i]) + 1;
+
+ // Now build the environment block.
+ envblock = reinterpret_cast<char *>(_alloca(len+1));
+ p = envblock;
+
+ for (unsigned i = 0; envp[i]; i++) {
+ const char *ev = envp[i];
+ size_t len = strlen(ev) + 1;
+ memcpy(p, ev, len);
+ p += len;
+ }
+
+ *p = 0;
+ }
+
// Create a child process.
STARTUPINFO si;
memset(&si, 0, sizeof(si));
@@ -200,7 +227,7 @@
fflush(stdout);
fflush(stderr);
BOOL rc = CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0,
- envp, NULL, &si, &pi);
+ envblock, NULL, &si, &pi);
DWORD err = GetLastError();
// Regardless of whether the process got created or not, we are done with
More information about the llvm-commits
mailing list