diff options
| author | Russ Cox <rsc@golang.org> | 2022-10-17 15:34:50 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-10-18 14:49:44 +0000 |
| commit | 8dc08394f0d5f83523080e4dd99fded26b7c1ceb (patch) | |
| tree | 06dc72d439c842aea68df4834e1310ac207fade7 /src/syscall | |
| parent | 9fedc481ea09a0539cd2669312429ef5416a8949 (diff) | |
| download | go-8dc08394f0d5f83523080e4dd99fded26b7c1ceb.tar.xz | |
internal/godebug: remove dependency on os
The immediate reason is that we want to use godebug from math/rand,
and math/rand importing godebug importing os causes an import cycle
in package testing.
More generally, the new approach to backward compatibility outlined
in discussion #55090 will require using this package from other similarly
sensitive places, perhaps even package os itself. Best to remove all
dependencies.
Preparation for #54880.
Change-Id: Ia01657a2d90e707a8121a336c9db3b7247c0198f
Reviewed-on: https://go-review.googlesource.com/c/go/+/439418
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/syscall')
| -rw-r--r-- | src/syscall/env_unix.go | 11 | ||||
| -rw-r--r-- | src/syscall/env_windows.go | 8 | ||||
| -rw-r--r-- | src/syscall/syscall.go | 4 |
3 files changed, 14 insertions, 9 deletions
diff --git a/src/syscall/env_unix.go b/src/syscall/env_unix.go index 67e6c5fbe2..6d917da208 100644 --- a/src/syscall/env_unix.go +++ b/src/syscall/env_unix.go @@ -31,11 +31,6 @@ var ( func runtime_envs() []string // in package runtime -// setenv_c and unsetenv_c are provided by the runtime but are no-ops -// if cgo isn't loaded. -func setenv_c(k, v string) -func unsetenv_c(k string) - func copyenv() { env = make(map[string]int) for i, s := range envs { @@ -67,7 +62,7 @@ func Unsetenv(key string) error { envs[i] = "" delete(env, key) } - unsetenv_c(key) + runtimeUnsetenv(key) return nil } @@ -124,7 +119,7 @@ func Setenv(key, value string) error { envs = append(envs, kv) } env[key] = i - setenv_c(key, value) + runtimeSetenv(key, value) return nil } @@ -135,7 +130,7 @@ func Clearenv() { defer envLock.Unlock() for k := range env { - unsetenv_c(k) + runtimeUnsetenv(k) } env = make(map[string]int) envs = []string{} diff --git a/src/syscall/env_windows.go b/src/syscall/env_windows.go index 74b154ec15..cd085a9e44 100644 --- a/src/syscall/env_windows.go +++ b/src/syscall/env_windows.go @@ -42,6 +42,7 @@ func Setenv(key, value string) error { if e != nil { return e } + runtimeSetenv(key, value) return nil } @@ -50,7 +51,12 @@ func Unsetenv(key string) error { if err != nil { return err } - return SetEnvironmentVariable(keyp, nil) + e := SetEnvironmentVariable(keyp, nil) + if e != nil { + return e + } + runtimeUnsetenv(key) + return nil } func Clearenv() { diff --git a/src/syscall/syscall.go b/src/syscall/syscall.go index 62bfa449cf..446a299f57 100644 --- a/src/syscall/syscall.go +++ b/src/syscall/syscall.go @@ -100,3 +100,7 @@ func (tv *Timeval) Nano() int64 { func Getpagesize() int func Exit(code int) + +// runtimeSetenv and runtimeUnsetenv are provided by the runtime. +func runtimeSetenv(k, v string) +func runtimeUnsetenv(k string) |
