diff options
author | Ian Lance Taylor <iant@golang.org> | 2015-05-04 15:11:31 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2015-05-04 15:11:31 -0700 |
commit | 48263f48028aef62a7a162ca869050cf62ff8b15 (patch) | |
tree | 008f7d1d42d8c7731e15752eaa9805f6c2f41321 /Lib/go | |
parent | 140782054a1be924dda81b3abd9f1b181415e606 (diff) | |
download | swig-48263f48028aef62a7a162ca869050cf62ff8b15.tar.gz |
[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.
Diffstat (limited to 'Lib/go')
-rw-r--r-- | Lib/go/goruntime.swg | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 8f6eb742e..031a7f6f0 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -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. */ |