From 7fe996e7ba25290c5748098613c3e9d2fd021a65 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 2 Feb 2023 18:47:37 +0100 Subject: [PATCH] runtime: implement internal/godebug.setUpdate This function was a stub, but it really needs to be implemented for full Go 1.20 support. Without it, the archive/zip tests will fail. --- src/runtime/env_unix.go | 6 ++++++ src/runtime/runtime.go | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/runtime/env_unix.go b/src/runtime/env_unix.go index 70716204..6fb13c56 100644 --- a/src/runtime/env_unix.go +++ b/src/runtime/env_unix.go @@ -11,6 +11,12 @@ func syscallSetenv(key, value string) { valdata := cstring(value) // ignore any errors libc_setenv(&keydata[0], &valdata[0], 1) + if key == "GODEBUG" && godebugUpdate != nil { + // Starting with Go 1.20, we need to call a callback (set by + // internal/godebug) to notify the GODEBUG environment variable has + // changed. This is necessary to get archive/zip to pass tests. + godebugUpdate(key, value) + } } // Update the C environment if cgo is loaded. diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 1a2a0495..a9778eae 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -96,8 +96,11 @@ func SetFinalizer(obj interface{}, finalizer interface{}) { // Unimplemented. } +var godebugUpdate func(string, string) + //go:linkname godebug_setUpdate internal/godebug.setUpdate func godebug_setUpdate(update func(string, string)) { - // Unimplemented. The 'update' function needs to be called whenever the - // GODEBUG environment variable changes (for example, via os.Setenv). + // The 'update' function needs to be called whenever the GODEBUG environment + // variable changes (for example, via os.Setenv). + godebugUpdate = update }