bind: add missing unsafe import in generated code

The ClassGen.genGo function always uses unsafe, contrary to what
the check in GenGo says. With this CL, generated code always
imports unsafe if there are any classes to be generated.

Change-Id: Ic807111a26e494b4941790830b1950bb8b1f73d5
Reviewed-on: https://go-review.googlesource.com/29873
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur
2016-09-27 16:37:51 +00:00
parent 8b28d19931
commit 9640137a86
3 changed files with 5 additions and 3 deletions
+1 -3
View File
@@ -162,18 +162,16 @@ func (g *ClassGen) GenPackage(idx int) {
func (g *ClassGen) GenGo() {
g.Printf(classesGoHeader)
impUnsafe := false
for _, cls := range g.classes {
for _, f := range cls.Funcs {
if f.Public && g.isFuncSupported(f) {
impUnsafe = true
pkgName := strings.Replace(cls.Name, ".", "/", -1)
g.Printf("import %q\n", "Java/"+pkgName)
break
}
}
}
if impUnsafe {
if len(g.classes) > 0 {
g.Printf("import \"unsafe\"\n\n")
}
g.Printf("type proxy interface { Bind_proxy_refnum__() int32 }\n\n")
+2
View File
@@ -44,6 +44,8 @@ import (
_seq "golang.org/x/mobile/bind/seq"
)
import "unsafe"
type proxy interface { Bind_proxy_refnum__() int32 }
// Suppress unused package error
+2
View File
@@ -39,6 +39,8 @@ import (
_seq "golang.org/x/mobile/bind/seq"
)
import "unsafe"
type proxy interface { Bind_proxy_refnum__() int32 }
// Suppress unused package error