diff --git a/Examples/test-suite/csharp/apply_strings_runme.cs b/Examples/test-suite/csharp/apply_strings_runme.cs new file mode 100644 index 000000000..deaa5213b --- /dev/null +++ b/Examples/test-suite/csharp/apply_strings_runme.cs @@ -0,0 +1,16 @@ + +using System; +using apply_stringsNamespace; + +public class apply_strings_runme { + + private static string TEST_MESSAGE = "A message from target language to the C++ world and back again."; + + public static void Main() { + if (apply_strings.UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (apply_strings.SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + SWIGTYPE_p_char pChar = apply_strings.CharFunction(null); + if (pChar != null) throw new Exception("CharFunction failed"); + } +} + diff --git a/Examples/test-suite/java/apply_strings_runme.java b/Examples/test-suite/java/apply_strings_runme.java new file mode 100644 index 000000000..0b9f78085 --- /dev/null +++ b/Examples/test-suite/java/apply_strings_runme.java @@ -0,0 +1,24 @@ +import apply_strings.*; + +public class apply_strings_runme { + + static { + try { + System.loadLibrary("apply_strings"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + private static String TEST_MESSAGE = "A message from target language to the C++ world and back again."; + + public static void main(String argv[]) { + if (!apply_strings.UCharFunction(TEST_MESSAGE).equals(TEST_MESSAGE)) throw new RuntimeException("UCharFunction failed"); + if (!apply_strings.SCharFunction(TEST_MESSAGE).equals(TEST_MESSAGE)) throw new RuntimeException("SCharFunction failed"); + SWIGTYPE_p_char pChar = apply_strings.CharFunction(null); + if (pChar != null) throw new RuntimeException("CharFunction failed"); + } +} + + diff --git a/Examples/test-suite/perl5/apply_strings_runme.pl b/Examples/test-suite/perl5/apply_strings_runme.pl new file mode 100644 index 000000000..6e0ad3d2d --- /dev/null +++ b/Examples/test-suite/perl5/apply_strings_runme.pl @@ -0,0 +1,10 @@ +use apply_strings; + +my $TEST_MESSAGE = "A message from target language to the C++ world and back again."; + +if (apply_strings::UCharFunction($TEST_MESSAGE) ne $TEST_MESSAGE) { + die "UCharFunction failed"; +} +if (apply_strings::SCharFunction($TEST_MESSAGE) ne $TEST_MESSAGE) { + die "SCharFunction failed"; +} diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index f968637d5..d71c52f47 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -126,8 +126,8 @@ %typemap(out) double %{ $result = $1; %} /* char * - treat as String */ -%typemap(in) char * %{ $1 = $input; %} -%typemap(out) char * %{ $result = SWIG_csharp_string_callback($1); %} +%typemap(in) char * %{ $1 = ($1_type)$input; %} +%typemap(out) char * %{ $result = SWIG_csharp_string_callback((const char *)$1); %} %typemap(out, null="") void "" diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index 332dc02ed..4a726cf17 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -289,11 +289,11 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); /* Strings */ %typemap (in, doc="$NAME is a string") char *(int must_free = 0) { - $1 = SWIG_scm2str($input); + $1 = ($1_type)SWIG_scm2str($input); must_free = 1; } %typemap (varin, doc="NEW-VALUE is a string") char * {$1 = SWIG_scm2str($input);} - %typemap (out, doc="") char * {$result = gh_str02scm($1);} + %typemap (out, doc="") char * {$result = gh_str02scm((const char *)$1);} %typemap (varout, doc="") char * {$result = gh_str02scm($1);} %typemap (in, doc="$NAME is a string") char * *INPUT(char * temp, int must_free = 0) { temp = (char *) SWIG_scm2str($input); $1 = &temp; diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 015c24f33..d7b59ccd9 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -358,13 +358,13 @@ %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * { $input = 0; if ($1) { - $input = JCALL1(NewStringUTF, jenv, $1); + $input = JCALL1(NewStringUTF, jenv, (const char *)$1); if (!$input) return $null; } } -%typemap(freearg, noblock=1) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } -%typemap(out, noblock=1) char * { if($1) $result = JCALL1(NewStringUTF, jenv, $1); } +%typemap(freearg, noblock=1) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); } +%typemap(out, noblock=1) char * { if($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); } %typemap(javadirectorin) char * "$jniinput" %typemap(javadirectorout) char * "$javacall" @@ -629,14 +629,14 @@ %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char[ANY], char[] { $input = 0; if ($1) { - $input = JCALL1(NewStringUTF, jenv, $1); + $input = JCALL1(NewStringUTF, jenv, (const char *)$1); if (!$input) return $null; } } %typemap(argout) char[ANY], char[] "" -%typemap(freearg, noblock=1) char[ANY], char[] { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } -%typemap(out, noblock=1) char[ANY], char[] { if($1) $result = JCALL1(NewStringUTF, jenv, $1); } +%typemap(freearg, noblock=1) char[ANY], char[] { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); } +%typemap(out, noblock=1) char[ANY], char[] { if($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); } %typemap(javadirectorin) char[ANY], char[] "$jniinput" %typemap(javadirectorout) char[ANY], char[] "$javacall" diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index 5b2dbdebc..47af5b2cd 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -67,10 +67,16 @@ %{ lua_pushboolean(L,(int)*$1); SWIG_arg++;%} // strings (char* and char[]) -%typemap(in,checkfn="lua_isstring") const char*, char*, const char[ANY], char[ANY] +%typemap(in,checkfn="lua_isstring") const char*, char* +%{$1 = ($1_type)lua_tostring(L, $input);%} + +%typemap(in,checkfn="lua_isstring") const char[ANY], char[ANY] %{$1 = (char*)lua_tostring(L, $input);%} -%typemap(out) const char*, char*, const char[ANY], char[ANY] +%typemap(out) const char*, char* +%{ lua_pushstring(L,(const char*)$1); SWIG_arg++;%} + +%typemap(out) const char[ANY], char[ANY] %{ lua_pushstring(L,$1); SWIG_arg++;%} // char's diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 53aeb95a1..b4f2bd7e2 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -35,7 +35,7 @@ if (!SWIG_IsOK(res)) { %argument_fail(res,"$type",$symname, $argnum); } - $1 = buf; + $1 = ($1_type)buf; } %typemap(freearg,noblock=1,match="in") Char *, const Char * { if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum); @@ -55,7 +55,7 @@ /* out */ %typemap(out,noblock=1,fragment=#SWIG_FromCharPtr) Char *, const Char* { - %set_output(SWIG_FromCharPtr($1)); + %set_output(SWIG_FromCharPtr((const Char *)$1)); } @@ -102,7 +102,7 @@ %set_varoutput(SWIG_FromCharPtr($1)); } -/* meberin */ +/* memberin */ %typemap(memberin,noblock=1) Char * { if ($1) %delete_array($1); @@ -159,7 +159,7 @@ %typemap(directorin,noblock=1,fragment=#SWIG_FromCharPtr) Char *, Char const*, Char *const, Char const *const, Char const *&, Char *const &, Char const *const & { - $input = SWIG_FromCharPtr($1_name); + $input = SWIG_FromCharPtr((const Char *)$1_name); } @@ -174,7 +174,7 @@ if (alloc == SWIG_NEWOBJ) { swig_acquire_ownership_array(buf); } - $result = buf; + $result = ($1_type)buf; } %typemap(directorfree,noblock=1) Char * {