mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-23 13:59:02 +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,
|
Name: files[0].Name.Name,
|
||||||
},
|
},
|
||||||
Decls: []ast.Decl{
|
Decls: []ast.Decl{
|
||||||
|
// import "unsafe"
|
||||||
&ast.GenDecl{
|
&ast.GenDecl{
|
||||||
TokPos: p.generatedPos,
|
TokPos: p.generatedPos,
|
||||||
Tok: token.IMPORT,
|
Tok: token.IMPORT,
|
||||||
@@ -192,6 +193,32 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
|
|||||||
unsafeImport,
|
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},
|
Imports: []*ast.ImportSpec{unsafeImport},
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
var _ unsafe.Pointer
|
||||||
|
|
||||||
type C.int16_t = int16
|
type C.int16_t = int16
|
||||||
type C.int32_t = int32
|
type C.int32_t = int32
|
||||||
type C.int64_t = int64
|
type C.int64_t = int64
|
||||||
|
|||||||
Vendored
+2
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
var _ unsafe.Pointer
|
||||||
|
|
||||||
const C.option2A = 20
|
const C.option2A = 20
|
||||||
const C.optionA = 0
|
const C.optionA = 0
|
||||||
const C.optionB = 1
|
const C.optionB = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user