summaryrefslogtreecommitdiff
path: root/Lib/go/std_string.i
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/go/std_string.i')
-rw-r--r--Lib/go/std_string.i26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i
index 068c688cb..099ae84d4 100644
--- a/Lib/go/std_string.i
+++ b/Lib/go/std_string.i
@@ -24,8 +24,21 @@ class string;
%typemap(in) string
%{ $1.assign($input.p, $input.n); %}
+%typemap(godirectorout) string
+%{
+ {
+ p := Swig_malloc(len($input))
+ s := (*[1<<30]byte)(unsafe.Pointer(p))[:len($input)]
+ copy(s, $input)
+ $result = *(*string)(unsafe.Pointer(&s))
+ }
+%}
+
%typemap(directorout) string
-%{ $result.assign($input.p, $input.n); %}
+%{
+ $result.assign($input.p, $input.n);
+ free($input.p);
+%}
%typemap(out,fragment="AllocateString") string
%{ $result = Swig_AllocateString($1.data(), $1.length()); %}
@@ -45,10 +58,21 @@ class string;
$1 = &$1_str;
%}
+%typemap(godirectorout) const string &
+%{
+ {
+ p := Swig_malloc(len($input))
+ s := (*[1<<30]byte)(unsafe.Pointer(p))[:len($input)]
+ copy(s, $input)
+ $result = *(*string)(unsafe.Pointer(&s))
+ }
+%}
+
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{
static $*1_ltype $1_str;
$1_str.assign($input.p, $input.n);
+ free($input.p);
$result = &$1_str;
%}