[Go] Ensure structs are properly packed between gc and GCC/clang.
From https://github.com/swig/swig/pull/262.
This commit is contained in:
parent
344d10935e
commit
15b75a74c5
3 changed files with 26 additions and 5 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 3.0.9 (in progress)
|
Version 3.0.9 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2016-01-27: steeve
|
||||||
|
[Go] Ensure structs are properly packed between gc and GCC/clang.
|
||||||
|
|
||||||
2016-01-12: olly
|
2016-01-12: olly
|
||||||
[Javascript] Look for "nodejs" as well as "node", as it's packaged
|
[Javascript] Look for "nodejs" as well as "node", as it's packaged
|
||||||
as the former on Debian.
|
as the former on Debian.
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,24 @@ typedef size_t uintgo;
|
||||||
#endif
|
#endif
|
||||||
#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) %{
|
%insert(runtime) %{
|
||||||
|
|
||||||
typedef struct { char *p; intgo n; } _gostring_;
|
typedef struct { char *p; intgo n; } _gostring_;
|
||||||
|
|
@ -116,7 +134,7 @@ static char *_swig_topofstack() {
|
||||||
static void _swig_gopanic(const char *p) {
|
static void _swig_gopanic(const char *p) {
|
||||||
struct {
|
struct {
|
||||||
const char *p;
|
const char *p;
|
||||||
} a;
|
} SWIGSTRUCTPACKED a;
|
||||||
a.p = p;
|
a.p = p;
|
||||||
crosscall2(_cgo_panic, &a, (int) sizeof a);
|
crosscall2(_cgo_panic, &a, (int) sizeof a);
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +151,7 @@ static void *_swig_goallocate(size_t len) {
|
||||||
struct {
|
struct {
|
||||||
size_t len;
|
size_t len;
|
||||||
void *ret;
|
void *ret;
|
||||||
} a;
|
} SWIGSTRUCTPACKED a;
|
||||||
a.len = len;
|
a.len = len;
|
||||||
crosscall2(_cgo_allocate, &a, (int) sizeof a);
|
crosscall2(_cgo_allocate, &a, (int) sizeof a);
|
||||||
return a.ret;
|
return a.ret;
|
||||||
|
|
|
||||||
|
|
@ -2160,7 +2160,7 @@ private:
|
||||||
Delete(ct);
|
Delete(ct);
|
||||||
Delete(ln);
|
Delete(ln);
|
||||||
}
|
}
|
||||||
Printv(swigargs, "\t} *swig_a = (struct swigargs *) swig_v;\n", NULL);
|
Printv(swigargs, "\t} SWIGSTRUCTPACKED *swig_a = (struct swigargs *) swig_v;\n", NULL);
|
||||||
|
|
||||||
// Copy the input arguments out of the structure into the Go local
|
// Copy the input arguments out of the structure into the Go local
|
||||||
// variables.
|
// variables.
|
||||||
|
|
@ -3982,7 +3982,7 @@ private:
|
||||||
Printv(f_c_directors, director_sig, NULL);
|
Printv(f_c_directors, director_sig, NULL);
|
||||||
|
|
||||||
if (!gccgo_flag) {
|
if (!gccgo_flag) {
|
||||||
Printv(f_c_directors, " struct { intgo p; } a;\n", NULL);
|
Printv(f_c_directors, " struct { intgo p; } SWIGSTRUCTPACKED a;\n", NULL);
|
||||||
Printv(f_c_directors, " a.p = go_val;\n", NULL);
|
Printv(f_c_directors, " a.p = go_val;\n", NULL);
|
||||||
Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL);
|
Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL);
|
||||||
|
|
||||||
|
|
@ -5116,7 +5116,7 @@ private:
|
||||||
Delete(rname);
|
Delete(rname);
|
||||||
}
|
}
|
||||||
|
|
||||||
Printv(w->code, " } swig_a;\n", NULL);
|
Printv(w->code, " } SWIGSTRUCTPACKED swig_a;\n", NULL);
|
||||||
Printv(w->code, " swig_a.go_val = go_val;\n", NULL);
|
Printv(w->code, " swig_a.go_val = go_val;\n", NULL);
|
||||||
|
|
||||||
p = parms;
|
p = parms;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue