Skip to content

Commit

Permalink
cmd/cgo: document that structs and arrays don't work with //export
Browse files Browse the repository at this point in the history
Fixes #18412

Change-Id: Ib457eeced7820517aa35df9e7dfda1c0de4ac004
Reviewed-on: https://go-review.googlesource.com/52852
Reviewed-by: Avelino <t@avelino.xxx>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
ianlancetaylor committed Aug 8, 2017
1 parent 4fa2674 commit c3c2e45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cmd/cgo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ They will be available in the C code as:
found in the _cgo_export.h generated header, after any preambles
copied from the cgo input files. Functions with multiple
return values are mapped to functions returning a struct.
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:
since it is copied into two different C output files, it must not
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,9 @@ func (p *Package) cgoType(e ast.Expr) *Type {
// Slice: pointer, len, cap.
return &Type{Size: p.PtrSize * 3, Align: p.PtrSize, C: c("GoSlice")}
}
// Non-slice array types are not supported.
case *ast.StructType:
// TODO
// Not supported.
case *ast.FuncType:
return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("void*")}
case *ast.InterfaceType:
Expand Down

0 comments on commit c3c2e45

Please sign in to comment.