diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-03-15 20:30:40 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2022-03-15 20:30:53 -0700 |
commit | 0c0b93f8e06f362bae5b732460f8aeb9752b1f0c (patch) | |
tree | 7d548c70ca569f5f4a6c9745e95cf129276586bd | |
parent | b8193631175d668890d9bcbb0e964f36affa2e12 (diff) | |
download | swig-0c0b93f8e06f362bae5b732460f8aeb9752b1f0c.tar.gz |
[Go] add typemaps for std::string*
Fixes #2214
-rw-r--r-- | CHANGES.current | 3 | ||||
-rw-r--r-- | Examples/test-suite/go_director_inout.i | 9 | ||||
-rw-r--r-- | Lib/go/std_string.i | 50 |
3 files changed, 53 insertions, 9 deletions
diff --git a/CHANGES.current b/CHANGES.current index 64e4c4402..69a6d527f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -8,6 +8,9 @@ Version 4.1.0 (in progress) =========================== 2022-03-15: ianlancetaylor + [Go] Add typemaps for std::string*. + +2022-03-15: ianlancetaylor [Go] Don't convert arrays to pointers if there is a "gotype" typemap entry. diff --git a/Examples/test-suite/go_director_inout.i b/Examples/test-suite/go_director_inout.i index 708bd7c87..38059ea40 100644 --- a/Examples/test-suite/go_director_inout.i +++ b/Examples/test-suite/go_director_inout.i @@ -120,15 +120,6 @@ type GoRetStruct struct { $1.assign(tmp->p, tmp->p + tmp->n); } -%typemap(directorin) std::string * (_gostring_ temp) { - $input = &temp; - $input->p = (char *) $1->data(); - $input->n = $1->size(); -} -%typemap(directorargout) std::string * { - $1->assign($input->p, $input->p + $input->n); -} - %feature("director") MyClass; %inline diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i index 099ae84d4..c362f5c5e 100644 --- a/Lib/go/std_string.i +++ b/Lib/go/std_string.i @@ -88,4 +88,54 @@ class string; %typemap(godirectorin,fragment="CopyString") const string & %{ $result = swigCopyString($input) %} + +%typemap(gotype) string * "*string" + +%typemap(in) string * (string temp) +%{ + temp.assign($input->p, $input->n); + $1 = &temp; +%} + +%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 * (string temp) +%{ + temp.assign($input->p, $input->n); + $result = &temp; + free($input.p); +%} + +%typemap(out,fragment="AllocateString") string * (_gostring_ temp) +%{ + temp = Swig_AllocateString($1->data(), $1->length()); + $result = &temp; +%} + +%typemap(goout,fragment="CopyString") string * +%{ *$result = swigCopyString(*$1) %} + +%typemap(directorin,fragment="AllocateString") string * (_gostring_ temp) +%{ + temp = Swig_AllocateString($1->data(), $1->length()); + $input = &temp; +%} + +%typemap(godirectorin,fragment="CopyString") string * +%{ *$result = swigCopyString(*$input); %} + +%typemap(argout,fragment="AllocateString") string * +%{ *$input = Swig_AllocateString($1->data(), $1->length()); %} + +%typemap(goargout,fragment="CopyString") string * +%{ *$input = swigCopyString(*$1) %} + } |