[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

@ -44,14 +44,14 @@ type GoRetStruct struct {
$result.str.assign($input.p, $input.n);
%}
%typemap(out) RetStruct
%typemap(out,fragment="AllocateString") RetStruct
%{
$result = _swig_makegostring($1.str.data(), $1.str.length());
$result = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(goout) RetStruct
%typemap(goout,fragment="CopyString") RetStruct
%{
$result = GoRetStruct{Str: $input}
$result = GoRetStruct{Str: swigCopyString($input)}
%}
%typemap(godirectorout) RetStruct
@ -81,23 +81,28 @@ type GoRetStruct struct {
}
%}
%typemap(directorin) MyStruct
%typemap(directorin,fragment="AllocateString") MyStruct
%{
$input = _swig_makegostring($1.str.data(), $1.str.length());
$input = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(out) MyStruct
%typemap(godirectorin,fragment="CopyString") MyStruct
%{
$result = _swig_makegostring($1.str.data(), $1.str.length());
%}
%typemap(godirectorin) MyStruct
%{
if err := json.Unmarshal([]byte($input), &$result); err != nil {
if err := json.Unmarshal([]byte(swigCopyString($input)), &$result); err != nil {
panic(err)
}
%}
%typemap(out,fragment="AllocateString") MyStruct
%{
$result = Swig_AllocateString($1.str.data(), $1.str.length());
%}
%typemap(goout,fragment="CopyString") MyStruct
%{
$result = swigCopyString($input)
%}
%typemap(in) MyStruct
%{
$1.str.assign($input.p, $input.n);