diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-01-27 15:51:13 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2016-01-27 15:51:13 -0800 |
commit | 15b75a74c5c11e4bbdf75f7b525e16c7cfc792f5 (patch) | |
tree | 9609041aa78cb37f49440e71d3d5b640347de880 /Lib/go | |
parent | 344d10935ec58b8a17a87734334af85219fb6b1d (diff) | |
download | swig-15b75a74c5c11e4bbdf75f7b525e16c7cfc792f5.tar.gz |
[Go] Ensure structs are properly packed between gc and GCC/clang.
From https://github.com/swig/swig/pull/262.
Diffstat (limited to 'Lib/go')
-rw-r--r-- | Lib/go/goruntime.swg | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 031a7f6f0..e7a33adc4 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -60,6 +60,24 @@ typedef size_t uintgo; #endif #endif +#ifndef SWIGGO_GCCGO +// Set the host compiler struct attribute that will be +// used to match gc's struct layout. For example, on 386 Windows, +// gcc wants to 8-align int64s, but gc does not. +// Use __gcc_struct__ to work around http://gcc.gnu.org/PR52991 on x86, +// and https://golang.org/issue/5603. +// See: https://github.com/golang/go/blob/fcbf04f9b93b4cd8addd05c2ed784118eb50a46c/src/cmd/cgo/out.go#L663 +%insert(runtime) %{ +# if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__)) +# define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__)) +# else +# define SWIGSTRUCTPACKED __attribute__((__packed__)) +# endif +%} +#else +# define SWIGSTRUCTPACKED +#endif + %insert(runtime) %{ typedef struct { char *p; intgo n; } _gostring_; @@ -116,7 +134,7 @@ static char *_swig_topofstack() { static void _swig_gopanic(const char *p) { struct { const char *p; - } a; + } SWIGSTRUCTPACKED a; a.p = p; crosscall2(_cgo_panic, &a, (int) sizeof a); } @@ -133,7 +151,7 @@ static void *_swig_goallocate(size_t len) { struct { size_t len; void *ret; - } a; + } SWIGSTRUCTPACKED a; a.len = len; crosscall2(_cgo_allocate, &a, (int) sizeof a); return a.ret; |