From a41d85498eed6b606d261e3da84c760538d71b4f Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Wed, 12 Jan 2011 11:48:15 +1100 Subject: [PATCH] runtime: revert 6974:1f3c3696babb I missed that environment is used during runtime setup, well before go init() functions run. Implemented os-dependent runtime.goenvs functions to allow for different unix, plan9 and windows versions of environment discovery. R=rsc, paulzhol CC=golang-dev https://golang.org/cl/3787046 --- src/pkg/os/env_windows.go | 1 - src/pkg/runtime/darwin/thread.c | 6 +++++ src/pkg/runtime/freebsd/thread.c | 6 +++++ src/pkg/runtime/linux/thread.c | 6 +++++ src/pkg/runtime/plan9/thread.c | 5 ++++ src/pkg/runtime/proc.c | 1 + src/pkg/runtime/runtime.c | 40 +++++++++++++++++--------------- src/pkg/runtime/runtime.h | 4 ++++ src/pkg/runtime/string.goc | 30 ++++++++++++++++++++++++ src/pkg/runtime/tiny/thread.c | 6 +++++ src/pkg/runtime/windows/thread.c | 36 ++++++++++++++++++++++++++++ 11 files changed, 121 insertions(+), 20 deletions(-) diff --git a/src/pkg/os/env_windows.go b/src/pkg/os/env_windows.go index ad50610ee62..d2b159dfba7 100644 --- a/src/pkg/os/env_windows.go +++ b/src/pkg/os/env_windows.go @@ -114,7 +114,6 @@ func TempDir() string { func init() { var argc int32 - Envs = Environ() cmd := syscall.GetCommandLine() argv, e := syscall.CommandLineToArgv(cmd, &argc) if e != 0 { diff --git a/src/pkg/runtime/darwin/thread.c b/src/pkg/runtime/darwin/thread.c index 185f0ce963c..d69c624128d 100644 --- a/src/pkg/runtime/darwin/thread.c +++ b/src/pkg/runtime/darwin/thread.c @@ -148,6 +148,12 @@ runtime·osinit(void) runtime·bsdthread_register(); } +void +runtime·goenvs(void) +{ + runtime·goenvs_unix(); +} + void runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void)) { diff --git a/src/pkg/runtime/freebsd/thread.c b/src/pkg/runtime/freebsd/thread.c index fc80dfb77fb..9bd8838335c 100644 --- a/src/pkg/runtime/freebsd/thread.c +++ b/src/pkg/runtime/freebsd/thread.c @@ -163,6 +163,12 @@ runtime·osinit(void) { } +void +runtime·goenvs(void) +{ + runtime·goenvs_unix(); +} + // Called to initialize a new m (including the bootstrap m). void runtime·minit(void) diff --git a/src/pkg/runtime/linux/thread.c b/src/pkg/runtime/linux/thread.c index 9c9fc755b28..979260ba1d1 100644 --- a/src/pkg/runtime/linux/thread.c +++ b/src/pkg/runtime/linux/thread.c @@ -263,6 +263,12 @@ runtime·osinit(void) { } +void +runtime·goenvs(void) +{ + runtime·goenvs_unix(); +} + // Called to initialize a new m (including the bootstrap m). void runtime·minit(void) diff --git a/src/pkg/runtime/plan9/thread.c b/src/pkg/runtime/plan9/thread.c index f1bd1ffbe2d..fa96552a915 100644 --- a/src/pkg/runtime/plan9/thread.c +++ b/src/pkg/runtime/plan9/thread.c @@ -17,6 +17,11 @@ runtime·osinit(void) { } +void +runtime·goenvs(void) +{ +} + void runtime·initsig(int32 queue) { diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index d469e7c5b79..e9a19d95045 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -111,6 +111,7 @@ runtime·schedinit(void) runtime·mallocinit(); runtime·goargs(); + runtime·goenvs(); // For debugging: // Allocate internal symbol table representation now, diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index dbdc0f2ac60..9d3efe966d4 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -152,34 +152,36 @@ int32 runtime·isplan9; void runtime·goargs(void) { - String *gargv; - String *genvv; - int32 i, envc; + String *s; + int32 i; // for windows implementation see "os" package if(Windows) return; - if(runtime·isplan9) - envc=0; - else - for(envc=0; argv[argc+1+envc] != 0; envc++) - ; - - gargv = runtime·malloc(argc*sizeof gargv[0]); - genvv = runtime·malloc(envc*sizeof genvv[0]); - + s = runtime·malloc(argc*sizeof s[0]); for(i=0; i