diff options
author | Russ Cox <rsc@golang.org> | 2012-02-19 13:32:55 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2012-02-19 13:32:55 -0500 |
commit | 7bec2f4521adc13afc8c915fa6d78e2a8defff2e (patch) | |
tree | 518b6cf3a0c3fd1ce75ccda000afc6d8ecd96310 /src/cmd/cgo/doc.go | |
parent | 228b6d21d8e2102dcd527a00b837743bf49b16da (diff) | |
download | go-7bec2f4521adc13afc8c915fa6d78e2a8defff2e.tar.gz |
cmd/cgo: bug fixes
* disallow embedding of C type (Fixes issue 2552)
* detect 0-length array (Fixes issue 2806)
* use typedefs when possible, to avoid attribute((unavailable)) (Fixes issue 2888)
* print Go types constructed from C types using original C types (Fixes issue 2612)
This fix changes _cgo_export.h to repeat the preamble from import "C".
Otherwise the fix to issue 2612 is impossible, since it cannot refer to
types that have not been defined. If people are using //export and
putting non-header information in the preamble, they will need to
refactor their code.
R=golang-dev, r, r
CC=golang-dev
http://codereview.appspot.com/5672080
Diffstat (limited to 'src/cmd/cgo/doc.go')
-rw-r--r-- | src/cmd/cgo/doc.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 1d64c75ad..83f1ba46c 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -16,8 +16,8 @@ the pseudo-package "C" and then refers to types such as C.size_t, variables such as C.stdout, or functions such as C.putchar. If the import of "C" is immediately preceded by a comment, that -comment is used as a header when compiling the C parts of -the package. For example: +comment, called the preamble, is used as a header when compiling +the C parts of the package. For example: // #include <stdio.h> // #include <errno.h> @@ -57,6 +57,8 @@ The C type void* is represented by Go's unsafe.Pointer. To access a struct, union, or enum type directly, prefix it with struct_, union_, or enum_, as in C.struct_stat. +Go structs cannot embed fields with C types. + Any C function that returns a value may be called in a multiple assignment context to retrieve both the return value and the C errno variable as an error. For example: @@ -100,7 +102,8 @@ They will be available in the C code as: extern int64 MyFunction(int arg1, int arg2, GoString arg3); extern struct MyFunction2_return MyFunction2(int arg1, int arg2, GoString arg3); -found in _cgo_export.h generated header. Functions with multiple +found in _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. |