swig/Lib/go/std_string.i
Ian Lance Taylor 0a021a938e [Go] Remove all generated calls to _swig_makegostring, as it will no
longer as of Go 1.5.  In Go 1.5 or later user calls to
_swig_makegostring will fail at link time.

Instead, use goout and godirectorin typemaps to allocate strings in Go
code.

Change the Go typemaps support to ignore empty strings, so that we can
define empty strings for regular types so that %apply will override
the definitions for string types.

Fix the gccgo code to wrap SwigCgoCallback around all godirectorin
typemaps.

Add a few newlines after typemap code so that the typemaps don't have
to include them.
2015-02-05 10:15:37 -08:00

67 lines
1.8 KiB
OpenEdge ABL

/* -----------------------------------------------------------------------------
* std_string.i
*
* Typemaps for std::string and const std::string&
* These are mapped to a Go string and are passed around by value.
*
* To use non-const std::string references use the following %apply. Note
* that they are passed by value.
* %apply const std::string & {std::string &};
* ----------------------------------------------------------------------------- */
%{
#include <string>
%}
namespace std {
%naturalvar string;
class string;
%typemap(gotype) string, const string & "string"
%typemap(in) string
%{ $1.assign($input.p, $input.n); %}
%typemap(directorout) string
%{ $result.assign($input.p, $input.n); %}
%typemap(out,fragment="AllocateString") string
%{ $result = Swig_AllocateString($1.data(), $1.length()); %}
%typemap(goout,fragment="CopyString") string
%{ $result = swigCopyString($1) %}
%typemap(directorin,fragment="AllocateString") string
%{ $input = Swig_AllocateString($1.data(), $1.length()); %}
%typemap(godirectorin,fragment="CopyString") string
%{ $result = swigCopyString($input) %}
%typemap(in) const string &
%{
$*1_ltype $1_str($input.p, $input.n);
$1 = &$1_str;
%}
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
%{
static $*1_ltype $1_str;
$1_str.assign($input.p, $input.n);
$result = &$1_str;
%}
%typemap(out,fragment="AllocateString") const string &
%{ $result = Swig_AllocateString((*$1).data(), (*$1).length()); %}
%typemap(goout,fragment="CopyString") const string &
%{ $result = swigCopyString($1) %}
%typemap(directorin,fragment="AllocateString") const string &
%{ $input = Swig_AllocateString($1.data(), $1.length()); %}
%typemap(godirectorin,fragment="CopyString") const string &
%{ $result = swigCopyString($input) %}
}