From 8e4868af75f4f5fd0c60a41cae92763ac8110e79 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 13 Feb 2022 22:55:27 +0000 Subject: [PATCH] More director const std::string& testing and C# leak fix Issue #998 --- .../csharp/director_property_runme.cs | 13 ++++++++ Examples/test-suite/director_property.i | 4 +-- .../java/director_property_runme.java | 12 +++++++ .../python/director_property_runme.py | 31 +++++++++++++++++++ Lib/csharp/std_string.i | 4 +-- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/csharp/director_property_runme.cs b/Examples/test-suite/csharp/director_property_runme.cs index ac8da049a..b93e8e29d 100644 --- a/Examples/test-suite/csharp/director_property_runme.cs +++ b/Examples/test-suite/csharp/director_property_runme.cs @@ -15,6 +15,10 @@ public class runme if (a.getA() != "Hello set from MyFoo") { throw new Exception( "Test failed" ); } + a.setAByRef("Hello"); + if (a.getA() != "Hello setAByRef from MyFoo") { + throw new Exception( "Test failed" ); + } a.Dispose(); } @@ -28,6 +32,10 @@ public class runme if (a.getA() != "Hello set from MyFoo") { throw new Exception( "Test failed" ); } + a.setAByRef("Hello"); + if (a.getA() != "Hello setAByRef from MyFoo") { + throw new Exception( "Test failed" ); + } a.Dispose(); } } @@ -44,6 +52,11 @@ public class MyFoo : Foo { base.setA(a + " set from MyFoo"); } + + public override void setAByRef(string a) + { + base.setA(a + " setAByRef from MyFoo"); + } } } diff --git a/Examples/test-suite/director_property.i b/Examples/test-suite/director_property.i index d64e0c439..3f4f57aaa 100644 --- a/Examples/test-suite/director_property.i +++ b/Examples/test-suite/director_property.i @@ -18,9 +18,9 @@ virtual std::string pong() { return "Foo::pong();" + ping(); } virtual std::string getA() { return this->a_; } virtual void setA(std::string a) { this->a_ = a; } + virtual void setAByRef(const std::string &a) { this->a_ = a; } static Foo* get_self(Foo *slf) {return slf;} - }; %} @@ -37,9 +37,9 @@ virtual std::string pong(); virtual std::string getA(); virtual void setA(std::string a); + virtual void setAByRef(const std::string &a); static Foo* get_self(Foo *slf); - }; %{ diff --git a/Examples/test-suite/java/director_property_runme.java b/Examples/test-suite/java/director_property_runme.java index 1dc6f91b1..cc8727740 100644 --- a/Examples/test-suite/java/director_property_runme.java +++ b/Examples/test-suite/java/director_property_runme.java @@ -23,6 +23,10 @@ public class director_property_runme { if (!a.getA().equals("Hello set from MyFoo")) { throw new RuntimeException( "Test failed" ); } + a.setAByRef("Hello"); + if (!a.getA().equals("Hello setAByRef from MyFoo")) { + throw new RuntimeException( "Test failed" ); + } a.delete(); } @@ -36,6 +40,10 @@ public class director_property_runme { if (!a.getA().equals("Hello set from MyFoo")) { throw new RuntimeException( "Test failed" ); } + a.setAByRef("Hello"); + if (!a.getA().equals("Hello setAByRef from MyFoo")) { + throw new RuntimeException( "Test failed" ); + } a.delete(); } } @@ -49,6 +57,10 @@ class director_property_MyFoo extends Foo { public void setA(String a) { super.setA(a + " set from MyFoo"); } + @Override + public void setAByRef(String a) { + super.setA(a + " setAByRef from MyFoo"); + } } diff --git a/Examples/test-suite/python/director_property_runme.py b/Examples/test-suite/python/director_property_runme.py index dbbe23cb6..2fa41968c 100644 --- a/Examples/test-suite/python/director_property_runme.py +++ b/Examples/test-suite/python/director_property_runme.py @@ -23,3 +23,34 @@ if foo.a != "BIBI": raise RuntimeError if foo.getA() != "BIBI": raise RuntimeError + + + +class MyFoo(director_property.Foo): + def setA(self, a): + director_property.Foo.setA(self, a + " set from MyFoo") + def setAByRef(self, a): + director_property.Foo.setA(self, a + " setAByRef from MyFoo") + +a = MyFoo() +if (a.getA() != ""): + raise RuntimeError("Test failed") +a.setA("Hello") +if (a.getA() != "Hello set from MyFoo"): + raise RuntimeError("Test failed") +a.setAByRef("Hello") +if (a.getA() != "Hello setAByRef from MyFoo"): + raise RuntimeError("Test failed") +del a + +a_original = MyFoo() +a = director_property.Foo.get_self(a_original) +if (a.getA() != ""): + raise RuntimeError("Test failed") +a.setA("Hello") +if (a.getA() != "Hello set from MyFoo"): + raise RuntimeError("Test failed") +a.setAByRef("Hello") +if (a.getA() != "Hello setAByRef from MyFoo"): + raise RuntimeError("Test failed") +del a diff --git a/Lib/csharp/std_string.i b/Lib/csharp/std_string.i index 79b71c4c5..c8920c09e 100644 --- a/Lib/csharp/std_string.i +++ b/Lib/csharp/std_string.i @@ -57,7 +57,7 @@ class string; return $null; %} // const string & -%typemap(ctype) const string & "char *" +%typemap(ctype) const string & "const char *" %typemap(imtype) const string & "string" %typemap(cstype) const string & "string" @@ -89,7 +89,7 @@ class string; $1_str = $input; $result = &$1_str; %} -%typemap(directorin) const string & %{ $input = SWIG_csharp_string_callback($1.c_str()); %} +%typemap(directorin) const string & %{ $input = $1.c_str(); %} %typemap(csvarin, excode=SWIGEXCODE2) const string & %{ set {