mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 02:33:28 +00:00
cgo: avoid '"unsafe" imported but not used' error
This can happen when not all CGo features are used.
This commit is contained in:
committed by
Ron Evans
parent
b41e58bcb4
commit
913131bf62
+27
@@ -185,6 +185,7 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
|
||||
Name: files[0].Name.Name,
|
||||
},
|
||||
Decls: []ast.Decl{
|
||||
// import "unsafe"
|
||||
&ast.GenDecl{
|
||||
TokPos: p.generatedPos,
|
||||
Tok: token.IMPORT,
|
||||
@@ -192,6 +193,32 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
|
||||
unsafeImport,
|
||||
},
|
||||
},
|
||||
// var _ unsafe.Pointer
|
||||
// This avoids type errors when the unsafe package is never used.
|
||||
&ast.GenDecl{
|
||||
Tok: token.VAR,
|
||||
Specs: []ast.Spec{
|
||||
&ast.ValueSpec{
|
||||
Names: []*ast.Ident{
|
||||
&ast.Ident{
|
||||
Name: "_",
|
||||
Obj: &ast.Object{
|
||||
Kind: ast.Var,
|
||||
Name: "_",
|
||||
},
|
||||
},
|
||||
},
|
||||
Type: &ast.SelectorExpr{
|
||||
X: &ast.Ident{
|
||||
Name: "unsafe",
|
||||
},
|
||||
Sel: &ast.Ident{
|
||||
Name: "Pointer",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Imports: []*ast.ImportSpec{unsafeImport},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user