[Go] Make sure that arguments for which use memcpy when calling C are

still live after the call.  This ensures that they will not be
collected if the GC runs during the call.
This commit is contained in:
Ian Lance Taylor 2015-05-04 15:11:31 -07:00
commit 48263f4802
4 changed files with 77 additions and 34 deletions

View file

@ -113,8 +113,22 @@ static char *_swig_topofstack() {
}
}
static void _swig_gopanic(const char *p) {
struct {
const char *p;
} a;
a.p = p;
crosscall2(_cgo_panic, &a, (int) sizeof a);
}
%}
#if !SWIGGO_CGO
/* This is here for backward compatibility, but it will not work
with Go 1.5 or later. Do not use it in new code. */
%insert(runtime) %{
static void *_swig_goallocate(size_t len) {
struct {
size_t len;
@ -125,16 +139,10 @@ static void *_swig_goallocate(size_t len) {
return a.ret;
}
static void _swig_gopanic(const char *p) {
struct {
const char *p;
} a;
a.p = p;
crosscall2(_cgo_panic, &a, (int) sizeof a);
}
%}
#endif
#if !SWIGGO_CGO
/* Boilerplate for C code when using 6g/8g. This code is compiled
@ -246,6 +254,8 @@ void SwigCgocallBackDone() {
#endif
#if !SWIGGO_CGO
%insert(runtime) %{
/* This is here for backward compatibility, but it will not work
@ -258,6 +268,12 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) {
return ret;
}
%}
#endif
%insert(runtime) %{
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { _swig_gopanic(msg); } else
%}
@ -290,8 +306,6 @@ type _ unsafe.Pointer
%}
#if !SWIGGO_CGO
/* Swig_always_false is used to conditionally assign parameters to
Swig_escape_val so that the compiler thinks that they escape. We
only assign them if Swig_always_false is true, which it never is.
@ -302,8 +316,6 @@ var Swig_escape_always_false bool
var Swig_escape_val interface{}
%}
#endif
/* Function pointers are translated by the code in go.cxx into
_swig_fnptr. Member pointers are translated to _swig_memberptr. */