From 3a5bcac339c5b166bc1a51c38226a8dc5e6484ca Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 Mar 2021 19:44:12 -0800 Subject: libgo: update to Go 1.16.2 release Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/301459 --- libgo/misc/cgo/testplugin/plugin_test.go | 13 ++++----- libgo/misc/cgo/testplugin/testdata/method2/main.go | 32 ++++++++++++++++++++++ libgo/misc/cgo/testplugin/testdata/method2/p/p.go | 9 ++++++ .../misc/cgo/testplugin/testdata/method2/plugin.go | 11 ++++++++ 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 libgo/misc/cgo/testplugin/testdata/method2/main.go create mode 100644 libgo/misc/cgo/testplugin/testdata/method2/p/p.go create mode 100644 libgo/misc/cgo/testplugin/testdata/method2/plugin.go (limited to 'libgo/misc') diff --git a/libgo/misc/cgo/testplugin/plugin_test.go b/libgo/misc/cgo/testplugin/plugin_test.go index 9055dbd..2d99101 100644 --- a/libgo/misc/cgo/testplugin/plugin_test.go +++ b/libgo/misc/cgo/testplugin/plugin_test.go @@ -201,12 +201,11 @@ func TestMethod(t *testing.T) { // Exported symbol's method must be live. goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go") goCmd(t, "build", "-o", "method.exe", "./method/main.go") + run(t, "./method.exe") +} - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - cmd := exec.CommandContext(ctx, "./method.exe") - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out) - } +func TestMethod2(t *testing.T) { + goCmd(t, "build", "-buildmode=plugin", "-o", "method2.so", "./method2/plugin.go") + goCmd(t, "build", "-o", "method2.exe", "./method2/main.go") + run(t, "./method2.exe") } diff --git a/libgo/misc/cgo/testplugin/testdata/method2/main.go b/libgo/misc/cgo/testplugin/testdata/method2/main.go new file mode 100644 index 0000000..6a87e7b --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/main.go @@ -0,0 +1,32 @@ +// Copyright 2021 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. + +// A type can be passed to a plugin and converted to interface +// there. So its methods need to be live. + +package main + +import ( + "plugin" + + "testplugin/method2/p" +) + +var t p.T + +type I interface { M() } + +func main() { + pl, err := plugin.Open("method2.so") + if err != nil { + panic(err) + } + + f, err := pl.Lookup("F") + if err != nil { + panic(err) + } + + f.(func(p.T) interface{})(t).(I).M() +} diff --git a/libgo/misc/cgo/testplugin/testdata/method2/p/p.go b/libgo/misc/cgo/testplugin/testdata/method2/p/p.go new file mode 100644 index 0000000..acb526a --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/p/p.go @@ -0,0 +1,9 @@ +// Copyright 2021 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 p + +type T int + +func (T) M() { println("M") } diff --git a/libgo/misc/cgo/testplugin/testdata/method2/plugin.go b/libgo/misc/cgo/testplugin/testdata/method2/plugin.go new file mode 100644 index 0000000..6198e76 --- /dev/null +++ b/libgo/misc/cgo/testplugin/testdata/method2/plugin.go @@ -0,0 +1,11 @@ +// Copyright 2021 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 + +import "testplugin/method2/p" + +func main() {} + +func F(t p.T) interface{} { return t } -- cgit v1.1