The wrapper takes a pointer to the argument, not the argument itself.
Fixes #36705
Change-Id: I566d4457d00bf5b84e4a8315a26516975f0d7e10
Reviewed-on: https://go-review.googlesource.com/c/go/+/215942
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
/* Stub for calling unsetenv */
void
-x_cgo_unsetenv(char *arg)
+x_cgo_unsetenv(char **arg)
{
_cgo_tsan_acquire();
- unsetenv(arg);
+ unsetenv(arg[0]);
_cgo_tsan_release();
}
--- /dev/null
+// +build cgo
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// #include <stdlib.h>
+// #include <unistd.h>
+import "C"
+
+import "os"
+
+func main() {
+ os.Setenv("FOO", "bar")
+ s := C.GoString(C.getenv(C.CString("FOO")))
+ if s != "bar" {
+ panic("bad setenv, environment variable only has value \"" + s + "\"")
+ }
+ os.Unsetenv("FOO")
+ s = C.GoString(C.getenv(C.CString("FOO")))
+ if s != "" {
+ panic("bad unsetenv, environment variable still has value \"" + s + "\"")
+ }
+}