aboutsummaryrefslogtreecommitdiff
path: root/misc/cgo/errors
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-12-21 16:06:54 -0800
committerIan Lance Taylor <iant@golang.org>2019-01-04 02:40:56 +0000
commit0d6a2d5f9a0cd3c7111f38abd12a2255363bbd51 (patch)
tree0e6ac99573db4d54dbc613ee525579b9effd530b /misc/cgo/errors
parent95a6f112c6db064d3394f9f66aa569e9bbeb3617 (diff)
downloadgo-0d6a2d5f9a0cd3c7111f38abd12a2255363bbd51.tar.xz
runtime: skip writes to persistent memory in cgo checker
Fixes #23899 Fixes #28458 Change-Id: Ie177f2d4c399445d8d5e1a327f2419c7866cb45e Reviewed-on: https://go-review.googlesource.com/c/155697 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'misc/cgo/errors')
-rw-r--r--misc/cgo/errors/ptr_test.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/misc/cgo/errors/ptr_test.go b/misc/cgo/errors/ptr_test.go
index 165c2d407c..254671f179 100644
--- a/misc/cgo/errors/ptr_test.go
+++ b/misc/cgo/errors/ptr_test.go
@@ -406,6 +406,24 @@ var ptrTests = []ptrTest{
body: `var b bytes.Buffer; b.WriteString("a"); C.f(unsafe.Pointer(&b.Bytes()[0]))`,
fail: false,
},
+ {
+ // Test that bgsweep releasing a finalizer is OK.
+ name: "finalizer",
+ c: `// Nothing to declare.`,
+ imports: []string{"os"},
+ support: `func open() { os.Open(os.Args[0]) }; var G [][]byte`,
+ body: `for i := 0; i < 10000; i++ { G = append(G, make([]byte, 4096)); if i % 100 == 0 { G = nil; open() } }`,
+ fail: false,
+ },
+ {
+ // Test that converting generated struct to interface is OK.
+ name: "structof",
+ c: `// Nothing to declare.`,
+ imports: []string{"reflect"},
+ support: `type MyInt int; func (i MyInt) Get() int { return int(i) }; type Getter interface { Get() int }`,
+ body: `t := reflect.StructOf([]reflect.StructField{{Name: "MyInt", Type: reflect.TypeOf(MyInt(0)), Anonymous: true}}); v := reflect.New(t).Elem(); v.Interface().(Getter).Get()`,
+ fail: false,
+ },
}
func TestPointerChecks(t *testing.T) {
@@ -478,7 +496,7 @@ func testOne(t *testing.T, pt ptrTest) {
cmd := exec.Command("go", "build")
cmd.Dir = src
- cmd.Env = addEnv("GOPATH", gopath)
+ cmd.Env = append(os.Environ(), "GOPATH="+gopath)
buf, err := cmd.CombinedOutput()
if err != nil {
t.Logf("%#q:\n%s", args(cmd), buf)
@@ -550,16 +568,5 @@ func testOne(t *testing.T, pt ptrTest) {
}
func cgocheckEnv(val string) []string {
- return addEnv("GODEBUG", "cgocheck="+val)
-}
-
-func addEnv(key, val string) []string {
- env := []string{key + "=" + val}
- look := key + "="
- for _, e := range os.Environ() {
- if !strings.HasPrefix(e, look) {
- env = append(env, e)
- }
- }
- return env
+ return append(os.Environ(), "GODEBUG=cgocheck="+val)
}