aboutsummaryrefslogtreecommitdiffhomepage
path: root/cgo/cgo.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-09-22 18:21:12 +0200
committerRon Evans <[email protected]>2023-09-24 07:41:26 -0700
commit6ef8fcd5379b9610c518ab893e878a4c9b37ba08 (patch)
tree43c14799d864cd0444320bfadc3ed187dbc437df /cgo/cgo.go
parenta896f7f218832667db9bb1ccf04b08c0bae63a8c (diff)
downloadtinygo-6ef8fcd5379b9610c518ab893e878a4c9b37ba08.tar.gz
tinygo-6ef8fcd5379b9610c518ab893e878a4c9b37ba08.zip
cgo: add C._Bool type
This fixes https://github.com/tinygo-org/tinygo/issues/3926. While working on this I've found another bug: if C.bool is referenced from within Go, it isn't available anymore on the C side. This is an existing bug that also applies to float and double, but may be less likely to be triggered there. This bug is something to be fixed at a later time (it has something to do with preprocessor defines).
Diffstat (limited to 'cgo/cgo.go')
-rw-r--r--cgo/cgo.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/cgo/cgo.go b/cgo/cgo.go
index 67979230c..850007967 100644
--- a/cgo/cgo.go
+++ b/cgo/cgo.go
@@ -88,6 +88,7 @@ var cgoAliases = map[string]string{
"C.uintptr_t": "uintptr",
"C.float": "float32",
"C.double": "float64",
+ "C._Bool": "bool",
}
// builtinAliases are handled specially because they only exist on the Go side
@@ -311,10 +312,11 @@ func Process(files []*ast.File, dir, importPath string, fset *token.FileSet, cfl
// Process CGo imports for each file.
for i, f := range files {
cf := p.newCGoFile(f, i)
- // Float and double are aliased, meaning that C.float is the same thing
- // as float32 in Go.
+ // These types are aliased with the corresponding types in C. For
+ // example, float in C is always float32 in Go.
cf.names["float"] = clangCursor{}
cf.names["double"] = clangCursor{}
+ cf.names["_Bool"] = clangCursor{}
// Now read all the names (identifies) that C defines in the header
// snippet.
cf.readNames(p.cgoHeaders[i], cflagsForCGo, filepath.Base(fset.File(f.Pos()).Name()), func(names map[string]clangCursor) {