diff options
author | Matthew Dempsky <mdempsky@google.com> | 2014-08-05 18:12:32 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2014-08-05 18:12:32 -0700 |
commit | 4066aff8b63ca59b8866c482872c14a2087ae8b4 (patch) | |
tree | 48160ddfe5f55e1f6d735e946deda34a29004c8b /misc/cgo/testcdefs/cdefstest.go | |
parent | 7846f72f54f04574afa96507a895c24d39257ff5 (diff) | |
download | go-4066aff8b63ca59b8866c482872c14a2087ae8b4.tar.gz |
cmd/cgo: fix handling of defs_linux.go
Instead of including <sys/types.h> to get size_t, instead include
the ISO C standard <stddef.h> header, which defines fewer additional
types at risk of colliding with the user code. In particular, this
prevents collisions between <sys/types.h>'s userspace definitions with
the kernel definitions needed by defs_linux.go.
Also, -cdefs mode uses #pragma pack, so we can keep misaligned fields.
Fixes issue 8477.
LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://codereview.appspot.com/120610043
Committer: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc/cgo/testcdefs/cdefstest.go')
-rw-r--r-- | misc/cgo/testcdefs/cdefstest.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/misc/cgo/testcdefs/cdefstest.go b/misc/cgo/testcdefs/cdefstest.go index e6305b77d..0804083a0 100644 --- a/misc/cgo/testcdefs/cdefstest.go +++ b/misc/cgo/testcdefs/cdefstest.go @@ -35,7 +35,25 @@ struct cdefsTest { // Correct: -> Array [20][20]**int8 -> int8 **array[20][20] char **array5[20][20]; }; + +// Test that packed structures can be translated to C correctly too. +// See issue 8477. + +struct packedTest { + char first; + int second; + long long third; +} __attribute__((packed)); + +// Test that conflicting type definitions don't cause problems with cgo. +// See issue 8477. + +typedef struct timespec { + double bogus; +} pid_t; + */ import "C" type CdefsTest C.struct_cdefsTest +type PackedTest C.struct_packedTest |