[Go] add typemaps for std::string*

Fixes #2214
This commit is contained in:
Ian Lance Taylor 2022-03-15 20:30:40 -07:00
commit 0c0b93f8e0
3 changed files with 53 additions and 9 deletions

View file

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
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.

View file

@ -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

View file

@ -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) %}
}