diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /misc/cgo/testcdefs | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'misc/cgo/testcdefs')
-rw-r--r-- | misc/cgo/testcdefs/cdefstest.c | 1 | ||||
-rw-r--r-- | misc/cgo/testcdefs/cdefstest.go | 19 | ||||
-rw-r--r-- | misc/cgo/testcdefs/main.c | 28 |
3 files changed, 48 insertions, 0 deletions
diff --git a/misc/cgo/testcdefs/cdefstest.c b/misc/cgo/testcdefs/cdefstest.c index 10cdd66b6..ce670e729 100644 --- a/misc/cgo/testcdefs/cdefstest.c +++ b/misc/cgo/testcdefs/cdefstest.c @@ -6,3 +6,4 @@ #include "cdefstest.h" struct CdefsTest test; +struct PackedTest packed; diff --git a/misc/cgo/testcdefs/cdefstest.go b/misc/cgo/testcdefs/cdefstest.go index e6305b77d..5e613c79e 100644 --- a/misc/cgo/testcdefs/cdefstest.go +++ b/misc/cgo/testcdefs/cdefstest.go @@ -35,7 +35,26 @@ 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 diff --git a/misc/cgo/testcdefs/main.c b/misc/cgo/testcdefs/main.c index 2d3ee4dbe..594a43167 100644 --- a/misc/cgo/testcdefs/main.c +++ b/misc/cgo/testcdefs/main.c @@ -17,11 +17,25 @@ struct CdefsOrig { int8 **array5[20][20]; }; +// Packed structs are no longer supported for -cdefs. +/* +typedef struct PackedOrig PackedOrig; +#pragma pack on +struct PackedOrig { + int8 first; + int32 second; + int64 third; +}; +#pragma pack off +*/ + void main·test(int32 ret) { CdefsOrig o; CdefsTest t; + // PackedOrig po; + // PackedTest pt; ret = 0; if(sizeof(t.array1) != sizeof(o.array1) || offsetof(CdefsTest, array1[0]) != offsetof(CdefsOrig, array1[0])) { @@ -44,5 +58,19 @@ main·test(int32 ret) runtime·printf("array5: size, offset = %d, %d, want %d, %d\n", sizeof(t.array5), offsetof(CdefsTest, array5[0][0]), sizeof(o.array5), offsetof(CdefsOrig, array5[0][0])); ret = 1; } +/* + if(sizeof(pt.first) != sizeof(po.first) || offsetof(PackedTest, first) != offsetof(PackedOrig, first)) { + runtime·printf("first: size, offset = %d, %d, want %d, %d\n", sizeof(pt.first), offsetof(PackedTest, first), sizeof(po.first), offsetof(PackedOrig, first)); + ret = 1; + } + if(sizeof(pt.second) != sizeof(po.second) || offsetof(PackedTest, second) != offsetof(PackedOrig, second)) { + runtime·printf("second: size, offset = %d, %d, want %d, %d\n", sizeof(pt.second), offsetof(PackedTest, second), sizeof(po.second), offsetof(PackedOrig, second)); + ret = 1; + } + if(sizeof(pt.third) != sizeof(po.third) || offsetof(PackedTest, third) != offsetof(PackedOrig, third)) { + runtime·printf("third: size, offset = %d, %d, want %d, %d\n", sizeof(pt.third), offsetof(PackedTest, third), sizeof(po.third), offsetof(PackedOrig, third)); + ret = 1; + } +*/ FLUSH(&ret); // flush return value } |