]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: revert 6974:1f3c3696babb
authorAlex Brainman <alex.brainman@gmail.com>
Wed, 12 Jan 2011 00:48:15 +0000 (11:48 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 12 Jan 2011 00:48:15 +0000 (11:48 +1100)
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
src/pkg/runtime/darwin/thread.c
src/pkg/runtime/freebsd/thread.c
src/pkg/runtime/linux/thread.c
src/pkg/runtime/plan9/thread.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.c
src/pkg/runtime/runtime.h
src/pkg/runtime/string.goc
src/pkg/runtime/tiny/thread.c
src/pkg/runtime/windows/thread.c

index ad50610ee622bab349a2065f94b8bf45ba86e331..d2b159dfba747e7f7422aed28eb777c149e17ce6 100644 (file)
@@ -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 {
index 185f0ce963c8ca801c9e392f2d6bf4a9b86c419d..d69c624128dd3dc211e5e32c90e9128d8eb73e54 100644 (file)
@@ -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))
 {
index fc80dfb77fb0f82168a87edad97b61cf7c672208..9bd8838335c40e830e27d88ec649f7b9115cb96b 100644 (file)
@@ -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)
index 9c9fc755b28c62b39100d968d3b5cbda69f8d3a1..979260ba1d10866d78732d21d6e44b68bd194008 100644 (file)
@@ -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)
index f1bd1ffbe2d543c4ccbd448cd8b7f8249e577b09..fa96552a91543390c2d9a78d121f20404ecf461a 100644 (file)
@@ -17,6 +17,11 @@ runtime·osinit(void)
 {
 }
 
+void
+runtime·goenvs(void)
+{
+}
+
 void
 runtime·initsig(int32 queue)
 {
index d469e7c5b798a54cac33b0081d8af388ff06cb67..e9a19d950453e1295cd2bcc46b1a195f83924ece 100644 (file)
@@ -111,6 +111,7 @@ runtime·schedinit(void)
 
        runtime·mallocinit();
        runtime·goargs();
+       runtime·goenvs();
 
        // For debugging:
        // Allocate internal symbol table representation now,
index dbdc0f2ac6072d9b5246483280fb93f598361d69..9d3efe966d45a38bf4ca9f466dd9836d0292c115 100644 (file)
@@ -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<argc; i++)
-               gargv[i] = runtime·gostringnocopy(argv[i]);
-       os·Args.array = (byte*)gargv;
+               s[i] = runtime·gostringnocopy(argv[i]);
+       os·Args.array = (byte*)s;
        os·Args.len = argc;
        os·Args.cap = argc;
+}
 
-       for(i=0; i<envc; i++)
-               genvv[i] = runtime·gostringnocopy(argv[argc+1+i]);
-       os·Envs.array = (byte*)genvv;
-       os·Envs.len = envc;
-       os·Envs.cap = envc;
+void
+runtime·goenvs_unix(void)
+{
+       String *s;
+       int32 i, n;
+       
+       for(n=0; argv[argc+1+n] != 0; n++)
+               ;
+
+       s = runtime·malloc(n*sizeof s[0]);
+       for(i=0; i<n; i++)
+               s[i] = runtime·gostringnocopy(argv[argc+1+i]);
+       os·Envs.array = (byte*)s;
+       os·Envs.len = n;
+       os·Envs.cap = n;
 }
 
 // Atomic add and return new value.
index e53855e3ca415ae8f6d6326a869e9600b1a6972b..bde62833e09799cfea96de15cc144db8ad670ec4 100644 (file)
@@ -370,6 +370,7 @@ extern      bool    runtime·iscgo;
  */
 int32  runtime·strcmp(byte*, byte*);
 int32  runtime·findnull(byte*);
+int32  runtime·findnullw(uint16*);
 void   runtime·dump(byte*, int32);
 int32  runtime·runetochar(byte*, int32);
 int32  runtime·charntorune(int32*, uint8*, int32);
@@ -384,6 +385,8 @@ void        runtime·gogocall(Gobuf*, void(*)(void));
 uintptr        runtime·gosave(Gobuf*);
 void   runtime·lessstack(void);
 void   runtime·goargs(void);
+void   runtime·goenvs(void);
+void   runtime·goenvs_unix(void);
 void*  runtime·getu(void);
 void   runtime·throw(int8*);
 void   runtime·panicstring(int8*);
@@ -399,6 +402,7 @@ String      runtime·catstring(String, String);
 String runtime·gostring(byte*);
 String  runtime·gostringn(byte*, int32);
 String runtime·gostringnocopy(byte*);
+String runtime·gostringw(uint16*);
 void   runtime·initsig(int32);
 int32  runtime·gotraceback(void);
 void   runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
index 6752f31ccb811faf2b8200415c4d1e9d5f0f50b2..916559eb2d88c1148c110a6badc6b7e1b08b0b15 100644 (file)
@@ -20,6 +20,18 @@ runtime·findnull(byte *s)
        return l;
 }
 
+int32
+runtime·findnullw(uint16 *s)
+{
+       int32 l;
+
+       if(s == nil)
+               return 0;
+       for(l=0; s[l]!=0; l++)
+               ;
+       return l;
+}
+
 int32 runtime·maxstring = 256;
 
 String
@@ -68,6 +80,24 @@ runtime·gostringnocopy(byte *str)
        return s;
 }
 
+String
+runtime·gostringw(uint16 *str)
+{
+       int32 n, i;
+       byte buf[8];
+       String s;
+
+       n = 0;
+       for(i=0; str[i]; i++)
+               n += runtime·runetochar(buf, str[i]);
+       s = runtime·gostringsize(n+4);
+       n = 0;
+       for(i=0; str[i]; i++)
+               n += runtime·runetochar(s.str+n, str[i]);
+       s.len = n;
+       return s;
+}
+
 String
 runtime·catstring(String s1, String s2)
 {
index b976a1254c976c6fd329225932a836c70d0cec05..0572ecb779e0f35db2dc29c98c417dd161a8d479 100644 (file)
@@ -16,6 +16,12 @@ runtime·osinit(void)
 {
 }
 
+void
+runtime·goenvs(void)
+{
+       runtime·goenvs_unix();
+}
+
 void
 runtime·initsig(int32 queue)
 {
index 00cd0e8bdcf87080f64b0db6f1c9d1e76689c12d..9b518133735da17d232cd8956c4559cfd250dba7 100644 (file)
@@ -39,6 +39,42 @@ runtime·osinit(void)
 {
 }
 
+#pragma dynimport runtime·GetEnvironmentStringsW GetEnvironmentStringsW  "kernel32.dll"
+#pragma dynimport runtime·FreeEnvironmentStringsW FreeEnvironmentStringsW  "kernel32.dll"
+
+extern void *runtime·GetEnvironmentStringsW;
+extern void *runtime·FreeEnvironmentStringsW;
+
+void
+runtime·goenvs(void)
+{
+       extern Slice os·Envs;
+
+       uint16 *env;
+       String *s;
+       int32 i, n;
+       uint16 *p;
+
+       env = runtime·stdcall(runtime·GetEnvironmentStringsW, 0);
+
+       n = 0;
+       for(p=env; *p; n++)
+               p += runtime·findnullw(p)+1;
+
+       s = runtime·malloc(n*sizeof s[0]);
+
+       p = env;
+       for(i=0; i<n; i++) {
+               s[i] = runtime·gostringw(p);
+               p += runtime·findnullw(p)+1;
+       }
+       os·Envs.array = (byte*)s;
+       os·Envs.len = n;
+       os·Envs.cap = n;
+
+       runtime·stdcall(runtime·FreeEnvironmentStringsW, 1, env);
+}
+
 void
 runtime·exit(int32 code)
 {