char *& typemaps added

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10295 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-03-04 21:35:22 +00:00
commit 2cf3cb3dc9
6 changed files with 82 additions and 12 deletions

View file

@ -1,6 +1,12 @@
Version 1.3.35 (in progress)
============================
03/04/2008: wsfulton
[Java, C#] Add char *& typemaps.
03/04/2008: wsfulton
Fix occasional seg fault when attempting to report overloaded methods as being ignored.
02/29/2008: wsfulton
[Perl] Fix #1904537 Swig causes a Perl warning "x used only once" in Perl 5.10
reported by Ari Jolma

View file

@ -137,3 +137,22 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG;
}
%inline %{
// char *& tests
const char *&GetConstCharPointerRef() {
static const char str[] = CPLUSPLUS_MSG;
static const char *ptr = str;
return ptr;
}
bool SetConstCharPointerRef(const char *&str, unsigned int number) {
static char static_str[] = CPLUSPLUS_MSG;
strcpy(static_str, str);
return check(static_str, number);
}
%}

View file

@ -117,6 +117,18 @@ public class char_strings_runme {
if (char_strings.global_const_char_array2 != CPLUSPLUS_MSG)
throw new Exception("Test variables 6 failed, iteration " + i);
}
// char *& tests
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
throw new Exception("Test char pointer ref set failed, iteration " + i);
}
}
}

View file

@ -124,6 +124,18 @@ public class char_strings_runme {
if (!char_strings.getGlobal_const_char_array2().equals(CPLUSPLUS_MSG))
throw new RuntimeException("Test variables 6 failed, iteration " + i);
}
// char *& tests
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
if (!str.equals(CPLUSPLUS_MSG))
throw new RuntimeException("Test char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
throw new RuntimeException("Test char pointer ref set failed, iteration " + i);
}
}
}

View file

@ -107,9 +107,9 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(cstype) double, const double & "double"
%typemap(cstype) void "void"
%typemap(ctype) char *, char[ANY], char[] "char *"
%typemap(imtype) char *, char[ANY], char[] "string"
%typemap(cstype) char *, char[ANY], char[] "string"
%typemap(ctype) char *, char *&, char[ANY], char[] "char *"
%typemap(imtype) char *, char *&, char[ANY], char[] "string"
%typemap(cstype) char *, char *&, char[ANY], char[] "string"
/* Non primitive types */
%typemap(ctype) SWIGTYPE "void *"
@ -243,6 +243,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(csdirectorin) char * "$iminput"
%typemap(csdirectorout) char * "$cscall"
/* char *& - treat as String */
%typemap(in) char *& ($*1_ltype temp = 0) %{
temp = ($*1_ltype)$input;
$1 = &temp;
%}
%typemap(out) char *& %{ if ($1) $result = SWIG_csharp_string_callback((const char *)*$1); %}
%typemap(out, null="") void ""
%typemap(csdirectorin) void "$iminput"
%typemap(csdirectorout) void "$cscall"
@ -508,6 +515,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typecheck(SWIG_TYPECHECK_STRING)
char *,
char *&,
char[ANY],
char[]
""
@ -562,7 +570,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
float, const float &,
double, const double &
"$csinput"
%typemap(csin) char *, char[ANY], char[] "$csinput"
%typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
@ -632,7 +640,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
double ret = $imcall;$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
%typemap(csout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
string ret = $imcall;$excode
return ret;
}
@ -665,7 +673,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
$imcall;$excode
} %}
%typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
%typemap(csvarin, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
set {
$imcall;$excode
} %}
@ -742,7 +750,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
} %}
%typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
%typemap(csvarout, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
get {
string ret = $imcall;$excode
return ret;

View file

@ -63,9 +63,9 @@
%typemap(jstype) double, const double & "double"
%typemap(jstype) void "void"
%typemap(jni) char *, char[ANY], char[] "jstring"
%typemap(jtype) char *, char[ANY], char[] "String"
%typemap(jstype) char *, char[ANY], char[] "String"
%typemap(jni) char *, char *&, char[ANY], char[] "jstring"
%typemap(jtype) char *, char *&, char[ANY], char[] "String"
%typemap(jstype) char *, char *&, char[ANY], char[] "String"
/* JNI types */
%typemap(jni) jboolean "jboolean"
@ -368,6 +368,18 @@
%typemap(javadirectorin) char * "$jniinput"
%typemap(javadirectorout) char * "$javacall"
/* char *& - treat as String */
%typemap(in, noblock=1) char *& ($*1_ltype temp = 0) {
$1 = 0;
if ($input) {
temp = ($*1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
if (!temp) return $null;
}
$1 = &temp;
}
%typemap(freearg, noblock=1) char *& { if ($1 && *$1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)*$1); }
%typemap(out, noblock=1) char *& { if(*$1) $result = JCALL1(NewStringUTF, jenv, (const char *)*$1); }
%typemap(out) void ""
%typemap(javadirectorin) void "$jniinput"
%typemap(javadirectorout) void "$javacall"
@ -842,6 +854,7 @@
%typecheck(SWIG_TYPECHECK_STRING) /* Java String */
jstring,
char *,
char *&,
char[ANY],
char []
""
@ -933,7 +946,7 @@
float, const float &,
double, const double &
"$javainput"
%typemap(javain) char *, char[ANY], char[] "$javainput"
%typemap(javain) char *, char *&, char[ANY], char[] "$javainput"
%typemap(javain) jboolean,
jchar,
jbyte,
@ -975,7 +988,7 @@
double, const double & {
return $jnicall;
}
%typemap(javaout) char *, char[ANY], char[] {
%typemap(javaout) char *, char *&, char[ANY], char[] {
return $jnicall;
}
%typemap(javaout) jboolean,