Fix director typemaps for pointers so that NULL pointers are correctly marshalled to C#/Java null in director methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10662 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b2cea3c42a
commit
4887e7be7c
6 changed files with 127 additions and 20 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
Version 1.3.37 (in progress)
|
Version 1.3.37 (in progress)
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
2008-07-14: wsfultonn
|
||||||
|
[Java, C#] Fix director typemaps for pointers so that NULL pointers are correctly
|
||||||
|
marshalled to C#/Java null in director methods.
|
||||||
|
|
||||||
2008-07-04: olly
|
2008-07-04: olly
|
||||||
[PHP] For std_vector.i and std_map.i, rename empty() to is_empty()
|
[PHP] For std_vector.i and std_map.i, rename empty() to is_empty()
|
||||||
since "empty" is a PHP reserved word. Based of patch from Mark Klein
|
since "empty" is a PHP reserved word. Based of patch from Mark Klein
|
||||||
|
|
|
||||||
74
Examples/test-suite/csharp/director_basic_runme.cs
Normal file
74
Examples/test-suite/csharp/director_basic_runme.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace director_basicNamespace {
|
||||||
|
|
||||||
|
public class runme
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
runme r = new runme();
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
director_basic_MyFoo a = new director_basic_MyFoo();
|
||||||
|
|
||||||
|
if (a.ping() != "director_basic_MyFoo::ping()") {
|
||||||
|
throw new Exception ( "a.ping()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.pong() != "Foo::pong();director_basic_MyFoo::ping()") {
|
||||||
|
throw new Exception ( "a.pong()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
Foo b = new Foo();
|
||||||
|
|
||||||
|
if (b.ping() != "Foo::ping()") {
|
||||||
|
throw new Exception ( "b.ping()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b.pong() != "Foo::pong();Foo::ping()") {
|
||||||
|
throw new Exception ( "b.pong()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
A1 a1 = new A1(1, false);
|
||||||
|
a1.Dispose();
|
||||||
|
|
||||||
|
{
|
||||||
|
MyOverriddenClass my = new MyOverriddenClass();
|
||||||
|
|
||||||
|
my.expectNull = true;
|
||||||
|
if (MyClass.call_pmethod(my, null) != null)
|
||||||
|
throw new Exception("null pointer marshalling problem");
|
||||||
|
|
||||||
|
Bar myBar = new Bar();
|
||||||
|
my.expectNull = false;
|
||||||
|
Bar myNewBar = MyClass.call_pmethod(my, myBar);
|
||||||
|
if (myNewBar == null)
|
||||||
|
throw new Exception("non-null pointer marshalling problem");
|
||||||
|
myNewBar.x = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class director_basic_MyFoo : Foo {
|
||||||
|
public director_basic_MyFoo() : base() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ping() {
|
||||||
|
return "director_basic_MyFoo::ping()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyOverriddenClass : MyClass {
|
||||||
|
public bool expectNull = false;
|
||||||
|
public bool nonNullReceived = false;
|
||||||
|
public override Bar pmethod(Bar b) {
|
||||||
|
if ( expectNull && (b != null) )
|
||||||
|
throw new Exception("null not received as expected");
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -112,12 +112,14 @@ public:
|
||||||
return vmethod(b);
|
return vmethod(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static MyClass *get_self(MyClass *c)
|
static MyClass *get_self(MyClass *c)
|
||||||
{
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Bar * call_pmethod(MyClass *myclass, Bar *b) {
|
||||||
|
return myclass->pmethod(b);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
||||||
|
|
@ -14,28 +14,43 @@ public class director_basic_runme {
|
||||||
|
|
||||||
public static void main(String argv[]) {
|
public static void main(String argv[]) {
|
||||||
|
|
||||||
director_basic_MyFoo a = new director_basic_MyFoo();
|
director_basic_MyFoo a = new director_basic_MyFoo();
|
||||||
|
|
||||||
if (!a.ping().equals("director_basic_MyFoo::ping()")) {
|
if (!a.ping().equals("director_basic_MyFoo::ping()")) {
|
||||||
throw new RuntimeException ( "a.ping()" );
|
throw new RuntimeException ( "a.ping()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) {
|
if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) {
|
||||||
throw new RuntimeException ( "a.pong()" );
|
throw new RuntimeException ( "a.pong()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Foo b = new Foo();
|
Foo b = new Foo();
|
||||||
|
|
||||||
if (!b.ping().equals("Foo::ping()")) {
|
if (!b.ping().equals("Foo::ping()")) {
|
||||||
throw new RuntimeException ( "b.ping()" );
|
throw new RuntimeException ( "b.ping()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!b.pong().equals("Foo::pong();Foo::ping()")) {
|
if (!b.pong().equals("Foo::pong();Foo::ping()")) {
|
||||||
throw new RuntimeException ( "b.pong()" );
|
throw new RuntimeException ( "b.pong()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
A1 a1 = new A1(1, false);
|
A1 a1 = new A1(1, false);
|
||||||
a1.delete();
|
a1.delete();
|
||||||
|
|
||||||
|
{
|
||||||
|
MyOverriddenClass my = new MyOverriddenClass();
|
||||||
|
|
||||||
|
my.expectNull = true;
|
||||||
|
if (MyClass.call_pmethod(my, null) != null)
|
||||||
|
throw new RuntimeException("null pointer marshalling problem");
|
||||||
|
|
||||||
|
Bar myBar = new Bar();
|
||||||
|
my.expectNull = false;
|
||||||
|
Bar myNewBar = MyClass.call_pmethod(my, myBar);
|
||||||
|
if (myNewBar == null)
|
||||||
|
throw new RuntimeException("non-null pointer marshalling problem");
|
||||||
|
myNewBar.setX(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,3 +60,13 @@ class director_basic_MyFoo extends Foo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MyOverriddenClass extends MyClass {
|
||||||
|
public boolean expectNull = false;
|
||||||
|
public boolean nonNullReceived = false;
|
||||||
|
public Bar pmethod(Bar b) {
|
||||||
|
if ( expectNull && (b != null) )
|
||||||
|
throw new RuntimeException("null not received as expected");
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -428,7 +428,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
|
||||||
%typemap(directorin) SWIGTYPE &
|
%typemap(directorin) SWIGTYPE &
|
||||||
%{ $input = ($1_ltype) &$1; %}
|
%{ $input = ($1_ltype) &$1; %}
|
||||||
|
|
||||||
%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "new $csclassname($iminput, false)"
|
%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)"
|
||||||
|
%typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)"
|
||||||
%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
|
%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
|
||||||
|
|
||||||
/* Default array handling */
|
/* Default array handling */
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,8 @@
|
||||||
%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE &
|
%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE &
|
||||||
%{ *($&1_ltype)&$input = ($1_ltype) &$1; %}
|
%{ *($&1_ltype)&$input = ($1_ltype) &$1; %}
|
||||||
|
|
||||||
%typemap(javadirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "new $javaclassname($jniinput, false)"
|
%typemap(javadirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($jniinput == 0) ? null : new $javaclassname($jniinput, false)"
|
||||||
|
%typemap(javadirectorin) SWIGTYPE & "new $javaclassname($jniinput, false)"
|
||||||
%typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$javaclassname.getCPtr($javacall)"
|
%typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$javaclassname.getCPtr($javacall)"
|
||||||
|
|
||||||
/* Default array handling */
|
/* Default array handling */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue