diff --git a/CHANGES.current b/CHANGES.current index 19caae55d..2a3e14d8b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ 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 [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 diff --git a/Examples/test-suite/csharp/director_basic_runme.cs b/Examples/test-suite/csharp/director_basic_runme.cs new file mode 100644 index 000000000..b9916108c --- /dev/null +++ b/Examples/test-suite/csharp/director_basic_runme.cs @@ -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; + } +} + +} diff --git a/Examples/test-suite/director_basic.i b/Examples/test-suite/director_basic.i index 986a1706f..12cb0db65 100644 --- a/Examples/test-suite/director_basic.i +++ b/Examples/test-suite/director_basic.i @@ -112,12 +112,14 @@ public: return vmethod(b); } - static MyClass *get_self(MyClass *c) { return c; } - + + static Bar * call_pmethod(MyClass *myclass, Bar *b) { + return myclass->pmethod(b); + } }; template diff --git a/Examples/test-suite/java/director_basic_runme.java b/Examples/test-suite/java/director_basic_runme.java index eafe20bec..16a46aa35 100644 --- a/Examples/test-suite/java/director_basic_runme.java +++ b/Examples/test-suite/java/director_basic_runme.java @@ -14,28 +14,43 @@ public class director_basic_runme { 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()")) { - throw new RuntimeException ( "a.ping()" ); - } + if (!a.ping().equals("director_basic_MyFoo::ping()")) { + throw new RuntimeException ( "a.ping()" ); + } - if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) { - throw new RuntimeException ( "a.pong()" ); - } + if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) { + throw new RuntimeException ( "a.pong()" ); + } - Foo b = new Foo(); + Foo b = new Foo(); - if (!b.ping().equals("Foo::ping()")) { - throw new RuntimeException ( "b.ping()" ); - } + if (!b.ping().equals("Foo::ping()")) { + throw new RuntimeException ( "b.ping()" ); + } - if (!b.pong().equals("Foo::pong();Foo::ping()")) { - throw new RuntimeException ( "b.pong()" ); - } + if (!b.pong().equals("Foo::pong();Foo::ping()")) { + throw new RuntimeException ( "b.pong()" ); + } - A1 a1 = new A1(1, false); - a1.delete(); + A1 a1 = new A1(1, false); + 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; + } +} + diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 35e5c26d7..e381ff9ae 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -428,7 +428,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { %typemap(directorin) SWIGTYPE & %{ $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" /* Default array handling */ diff --git a/Lib/java/java.swg b/Lib/java/java.swg index b7c5607c3..7d1808632 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -620,7 +620,8 @@ %typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE & %{ *($&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)" /* Default array handling */