From 12a9671440e9408a07d59a8936e75da096fea5fc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 26 May 2012 06:33:49 +0000 Subject: [PATCH] std::string typemap modifications so they can be used with %apply for other string classes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13120 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/allegrocl/std_string.i | 10 +++++----- Lib/chicken/std_string.i | 2 +- Lib/csharp/std_string.i | 4 ++-- Lib/d/std_string.i | 4 ++-- Lib/go/std_string.i | 4 ++-- Lib/guile/std_string.i | 4 ++-- Lib/java/std_string.i | 12 ++++++------ Lib/lua/std_string.i | 4 ++-- Lib/mzscheme/std_string.i | 2 +- Lib/ocaml/std_string.i | 10 +++++----- Lib/php/std_string.i | 6 +++--- Lib/pike/std_string.i | 4 ++-- 13 files changed, 37 insertions(+), 33 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index acbd8b642..d6de00200 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.7 (in progress) =========================== +2012-05-26: wsfulton + std::string typemap modifications so they can be used with %apply for other string + classes. + 2012-05-25: wsfulton [Lua] Fixes for -external-runtime to work again. diff --git a/Lib/allegrocl/std_string.i b/Lib/allegrocl/std_string.i index 372758dee..cbcd250a9 100644 --- a/Lib/allegrocl/std_string.i +++ b/Lib/allegrocl/std_string.i @@ -121,7 +121,7 @@ namespace std { // SWIG_exception(SWIG_TypeError, "string expected"); // } -// %typemap(in) const string & (std::string temp) { +// %typemap(in) const string & ($*1_ltype temp) { // if (caml_ptr_check($input)) { // temp.assign((char *)caml_ptr_val($input,0), // caml_string_len($input)); @@ -131,7 +131,7 @@ namespace std { // } // } -// %typemap(in) string & (std::string temp) { +// %typemap(in) string & ($*1_ltype temp) { // if (caml_ptr_check($input)) { // temp.assign((char *)caml_ptr_val($input,0), // caml_string_len($input)); @@ -141,9 +141,9 @@ namespace std { // } // } -// %typemap(in) string * (std::string *temp) { +// %typemap(in) string * ($*1_ltype *temp) { // if (caml_ptr_check($input)) { -// temp = new std::string((char *)caml_ptr_val($input,0), +// temp = new $*1_ltype((char *)caml_ptr_val($input,0), // caml_string_len($input)); // $1 = temp; // } else { @@ -151,7 +151,7 @@ namespace std { // } // } -// %typemap(free) string * (std::string *temp) { +// %typemap(free) string * ($*1_ltype *temp) { // delete temp; // } diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i index 9907a58bc..fa77c1533 100644 --- a/Lib/chicken/std_string.i +++ b/Lib/chicken/std_string.i @@ -44,7 +44,7 @@ namespace std { } } - %typemap(in) const string& (std::string temp, char *tempptr) { + %typemap(in) const string& ($*1_ltype temp, char *tempptr) { if ($input == C_SCHEME_FALSE) { temp.resize(0); diff --git a/Lib/csharp/std_string.i b/Lib/csharp/std_string.i index 0d804518b..5f8fa44cb 100644 --- a/Lib/csharp/std_string.i +++ b/Lib/csharp/std_string.i @@ -69,7 +69,7 @@ class string; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0); return $null; } - std::string $1_str($input); + $*1_ltype $1_str($input); $1 = &$1_str; %} %typemap(out) const string & %{ $result = SWIG_csharp_string_callback($1->c_str()); %} @@ -85,7 +85,7 @@ class string; return $null; } /* possible thread/reentrant code problem */ - static std::string $1_str; + static $*1_ltype $1_str; $1_str = $input; $result = &$1_str; %} diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i index 7a4accf18..8d75d23e4 100644 --- a/Lib/d/std_string.i +++ b/Lib/d/std_string.i @@ -36,7 +36,7 @@ class string; SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string"); return $null; } - std::string $1_str($input); + $*1_ltype $1_str($input); $1 = &$1_str; %} %typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %} @@ -63,7 +63,7 @@ class string; return $null; } /* possible thread/reentrant code problem */ - static std::string $1_str; + static $*1_ltype $1_str; $1_str = $input; $result = &$1_str; %} diff --git a/Lib/go/std_string.i b/Lib/go/std_string.i index e7c964263..9922fbe13 100644 --- a/Lib/go/std_string.i +++ b/Lib/go/std_string.i @@ -35,13 +35,13 @@ class string; %typemap(in) const string & %{ - std::string $1_str($input.p, $input.n); + $*1_ltype $1_str($input.p, $input.n); $1 = &$1_str; %} %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string & %{ - static std::string $1_str; + static $*1_ltype $1_str; $1_str.assign($input.p, $input.n); $result = &$1_str; %} diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index 65ab6efbf..83e0dd26d 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -36,7 +36,7 @@ namespace std { } } - %typemap(in) const string & (std::string temp, char *tempptr) { + %typemap(in) const string & ($*1_ltype temp, char *tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); temp.assign(tempptr); @@ -50,7 +50,7 @@ namespace std { %typemap(in) string * (char *tempptr) { if (gh_string_p($input)) { tempptr = SWIG_scm2str($input); - $1 = new std::string(tempptr); + $1 = new $*1_ltype(tempptr); if (tempptr) SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); diff --git a/Lib/java/std_string.i b/Lib/java/std_string.i index f0d837696..f178e6d43 100644 --- a/Lib/java/std_string.i +++ b/Lib/java/std_string.i @@ -28,7 +28,7 @@ class string; %typemap(in) string %{ if(!$input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); @@ -38,7 +38,7 @@ class string; %typemap(directorout) string %{ if(!$input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); @@ -73,24 +73,24 @@ class string; %typemap(in) const string & %{ if(!$input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); if (!$1_pstr) return $null; - std::string $1_str($1_pstr); + $*1_ltype $1_str($1_pstr); $1 = &$1_str; jenv->ReleaseStringUTFChars($input, $1_pstr); %} %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string & %{ if(!$input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return $null; } const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0); if (!$1_pstr) return $null; /* possible thread/reentrant code problem */ - static std::string $1_str; + static $*1_ltype $1_str; $1_str = $1_pstr; $result = &$1_str; jenv->ReleaseStringUTFChars($input, $1_pstr); %} diff --git a/Lib/lua/std_string.i b/Lib/lua/std_string.i index 64c0957b1..b754eaf1c 100644 --- a/Lib/lua/std_string.i +++ b/Lib/lua/std_string.i @@ -51,7 +51,7 @@ Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2 %typemap(out) std::string %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%} -%typemap(in,checkfn="lua_isstring") const std::string& (std::string temp) +%typemap(in,checkfn="lua_isstring") const std::string& ($*1_ltype temp) %{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%} %typemap(out) const std::string& @@ -84,7 +84,7 @@ typemaps to tell SWIG what to do. */ %typemap(in) std::string &INPUT=const std::string &; -%typemap(in, numinputs=0) std::string &OUTPUT (std::string temp) +%typemap(in, numinputs=0) std::string &OUTPUT ($*1_ltype temp) %{ $1 = &temp; %} %typemap(argout) std::string &OUTPUT %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%} diff --git a/Lib/mzscheme/std_string.i b/Lib/mzscheme/std_string.i index b8b99d9ad..b19e8567a 100644 --- a/Lib/mzscheme/std_string.i +++ b/Lib/mzscheme/std_string.i @@ -35,7 +35,7 @@ namespace std { SWIG_exception(SWIG_TypeError, "string expected"); } - %typemap(in) const string & (std::string temp) { + %typemap(in) const string & ($*1_ltype temp) { if (SCHEME_STRINGP($input)) { temp.assign(SCHEME_STR_VAL($input)); $1 = &temp; diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i index 5b6966dec..bd5be0da2 100644 --- a/Lib/ocaml/std_string.i +++ b/Lib/ocaml/std_string.i @@ -36,7 +36,7 @@ class wstring; SWIG_exception(SWIG_TypeError, "string expected"); } -%typemap(in) const string & (std::string temp) { +%typemap(in) const string & ($*1_ltype temp) { /* %typemap(in) const string & */ if (caml_ptr_check($input)) { temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input)); @@ -46,7 +46,7 @@ class wstring; } } -%typemap(in) string & (std::string temp) { +%typemap(in) string & ($*1_ltype temp) { /* %typemap(in) string & */ if (caml_ptr_check($input)) { temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input)); @@ -56,17 +56,17 @@ class wstring; } } -%typemap(in) string * (std::string *temp) { +%typemap(in) string * ($*1_ltype *temp) { /* %typemap(in) string * */ if (caml_ptr_check($input)) { - temp = new std::string((char *)caml_ptr_val($input,0), caml_string_len($input)); + temp = new $*1_ltype((char *)caml_ptr_val($input,0), caml_string_len($input)); $1 = temp; } else { SWIG_exception(SWIG_TypeError, "string expected"); } } -%typemap(free) string * (std::string *temp) { +%typemap(free) string * ($*1_ltype *temp) { delete temp; } diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index ff70bc83c..10d7fdd31 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -56,15 +56,15 @@ namespace std { /* These next two handle a function which takes a non-const reference to * a std::string and modifies the string. */ - %typemap(in) string & (std::string temp) %{ + %typemap(in) string & ($*1_ltype temp) %{ convert_to_string_ex($input); temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); $1 = &temp; %} - %typemap(directorout) string & (std::string *temp) %{ + %typemap(directorout) string & ($*1_ltype *temp) %{ convert_to_string_ex($input); - temp = new std::string(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + temp = new $*1_ltype(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); swig_acquire_ownership(temp); $result = temp; %} diff --git a/Lib/pike/std_string.i b/Lib/pike/std_string.i index c6fc48c8d..b32b3c112 100644 --- a/Lib/pike/std_string.i +++ b/Lib/pike/std_string.i @@ -25,7 +25,7 @@ namespace std { $1.assign(STR0($input.u.string)); } - %typemap(in, pikedesc="tStr") const string & (std::string temp) { + %typemap(in, pikedesc="tStr") const string & ($*1_ltype temp) { if ($input.type != T_STRING) Pike_error("Bad argument: Expected a string.\n"); temp.assign(STR0($input.u.string)); @@ -47,7 +47,7 @@ namespace std { throw Swig::DirectorTypeMismatchException("string expected"); } - %typemap(directorout) const string & (std::string temp) { + %typemap(directorout) const string & ($*1_ltype temp) { if ($input.type == T_STRING) { temp.assign(STR0($input.u.string)); $result = &temp;