Commit c3c2e453 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/cgo: document that structs and arrays don't work with //export

Fixes #18412

Change-Id: Ib457eeced7820517aa35df9e7dfda1c0de4ac004
Reviewed-on: https://go-review.googlesource.com/52852Reviewed-by: 's avatarAvelino <t@avelino.xxx>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 4fa2674a
...@@ -241,7 +241,10 @@ They will be available in the C code as: ...@@ -241,7 +241,10 @@ They will be available in the C code as:
found in the _cgo_export.h generated header, after any preambles found in the _cgo_export.h generated header, after any preambles
copied from the cgo input files. Functions with multiple copied from the cgo input files. Functions with multiple
return values are mapped to functions returning a struct. return values are mapped to functions returning a struct.
Not all Go types can be mapped to C types in a useful way. Not all Go types can be mapped to C types in a useful way.
Go struct types are not supported; use a C struct type.
Go array types are not supported; use a C pointer.
Using //export in a file places a restriction on the preamble: Using //export in a file places a restriction on the preamble:
since it is copied into two different C output files, it must not since it is copied into two different C output files, it must not
......
...@@ -1223,8 +1223,9 @@ func (p *Package) cgoType(e ast.Expr) *Type { ...@@ -1223,8 +1223,9 @@ func (p *Package) cgoType(e ast.Expr) *Type {
// Slice: pointer, len, cap. // Slice: pointer, len, cap.
return &Type{Size: p.PtrSize * 3, Align: p.PtrSize, C: c("GoSlice")} return &Type{Size: p.PtrSize * 3, Align: p.PtrSize, C: c("GoSlice")}
} }
// Non-slice array types are not supported.
case *ast.StructType: case *ast.StructType:
// TODO // Not supported.
case *ast.FuncType: case *ast.FuncType:
return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("void*")} return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("void*")}
case *ast.InterfaceType: case *ast.InterfaceType:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment