From de698e64a3d004d7d4fa423617864f30722a0b33 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Tue, 2 Jun 2020 17:30:19 +0200 Subject: [PATCH] Fix export & handle unsafe.pointer types --- cmd/library/const.go | 9 ++++----- cmd/library/main.go | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/library/const.go b/cmd/library/const.go index b0ccf10c1..66e32dfbf 100644 --- a/cmd/library/const.go +++ b/cmd/library/const.go @@ -2,15 +2,14 @@ package main const prelude = `package main // #include -import ( - "C" - mobile "github.com/status-im/status-go/mobile" -) +import "C" +import "unsafe" +import mobile "github.com/status-im/status-go/mobile" func main() {} ` const intType = "int" const stringType = "string" -const unsafePointerType = "unsafe.Pointer" +const unsafePointerType = "&{unsafe Pointer}" const boolType = "bool" diff --git a/cmd/library/main.go b/cmd/library/main.go index fe14dce68..d405f7b85 100644 --- a/cmd/library/main.go +++ b/cmd/library/main.go @@ -41,7 +41,7 @@ func handleFunction(name string, funcDecl *ast.FuncDecl) string { results := funcDecl.Type.Results // add export tag - output := fmt.Sprintf("// export %s\n", name) + output := fmt.Sprintf("//export %s\n", name) // add initial func declaration output += fmt.Sprintf("func %s (", name) @@ -56,6 +56,8 @@ func handleFunction(name string, funcDecl *ast.FuncDecl) string { output += paramIdentity.Name typeString := fmt.Sprint(paramIdentity.Obj.Decl.(*ast.Field).Type) + // We match against the stringified type, + // could not find a better way to match this switch typeString { case stringType: output += " *C.char"