From 8dc08394f0d5f83523080e4dd99fded26b7c1ceb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 17 Oct 2022 15:34:50 -0400 Subject: 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 Run-TryBot: Russ Cox Reviewed-by: Austin Clements Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/runtime/runtime.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/runtime/runtime.go') diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 50f68a327c..25b714de4e 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -65,3 +65,31 @@ func os_runtime_args() []string { return append([]string{}, argslice...) } func syscall_Exit(code int) { exit(int32(code)) } + +var godebugenv atomic.Pointer[string] // set by parsedebugvars + +//go:linkname godebug_getGODEBUG internal/godebug.getGODEBUG +func godebug_getGODEBUG() string { + if p := godebugenv.Load(); p != nil { + return *p + } + return "" +} + +//go:linkname syscall_runtimeSetenv syscall.runtimeSetenv +func syscall_runtimeSetenv(key, value string) { + setenv_c(key, value) + if key == "GODEBUG" { + p := new(string) + *p = value + godebugenv.Store(p) + } +} + +//go:linkname syscall_runtimeUnsetenv syscall.runtimeUnsetenv +func syscall_runtimeUnsetenv(key string) { + unsetenv_c(key) + if key == "GODEBUG" { + godebugenv.Store(nil) + } +} -- cgit v1.3-6-g1900