Skip to content

Commit 046c658

Browse files
committed
misc/cgo/testplugin: add test for issue 18584
Fixes #18584 Change-Id: I5f9428758999cacee49f3449e596e0a88bc06f91 Reviewed-on: https://go-review.googlesource.com/67150 Run-TryBot: David Crawshaw <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 33c06b1 commit 046c658

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import "plugin"
8+
9+
func main() {
10+
p, err := plugin.Open("plugin.so")
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
sym, err := p.Lookup("G")
16+
if err != nil {
17+
panic(err)
18+
}
19+
g := sym.(func() bool)
20+
if !g() {
21+
panic("expected types to match, Issue #18584")
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import "reflect"
8+
9+
type C struct {
10+
}
11+
12+
func F(c *C) *C {
13+
return nil
14+
}
15+
16+
func G() bool {
17+
var c *C
18+
return reflect.TypeOf(F).Out(0) == reflect.TypeOf(c)
19+
}

misc/cgo/testplugin/test.bash

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ goos=$(go env GOOS)
1515
goarch=$(go env GOARCH)
1616

1717
function cleanup() {
18-
rm -f plugin*.so unnamed*.so iface*.so
19-
rm -rf host pkg sub iface issue18676 issue19534
18+
rm -f plugin*.so unnamed*.so iface*.so issue*
19+
rm -rf host pkg sub iface
2020
}
2121
trap cleanup EXIT
2222

@@ -61,3 +61,8 @@ _timeout 10s ./issue18676
6161
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -ldflags='-pluginpath=issue.19534' -o plugin.so src/issue19534/plugin.go
6262
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19534 src/issue19534/main.go
6363
./issue19534
64+
65+
# Test for issue 18584
66+
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18584/plugin.go
67+
GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18584 src/issue18584/main.go
68+
./issue18584

0 commit comments

Comments
 (0)