Merge branch 'unique_ptr-inputs'
* unique_ptr-inputs: std::unique_ptr std::auto_ptr tidyup Add support for std::auto_ptr inputs Cosmetic formatting and doc updates in std_unique_ptr.i files Add Perl support for std::unique_ptr inputs Add Ruby support for std::unique_ptr inputs Add Python support for std::unique_ptr inputs Add C# support std::unique_ptr inputs Java unique_ptr test ownership enhancement to test Java unique_ptr enhance test for double release SWIGTYPE && input typemaps now assume object has been moved Add Java support for std::unique<T> for input parameters. Closes #692 Conflicts: CHANGES.current
This commit is contained in:
commit
8b654afdef
37 changed files with 1291 additions and 116 deletions
|
|
@ -610,6 +610,7 @@ CPP11_TEST_CASES += \
|
|||
cpp11_rvalue_reference \
|
||||
cpp11_rvalue_reference2 \
|
||||
cpp11_rvalue_reference3 \
|
||||
cpp11_rvalue_reference_move_input \
|
||||
cpp11_sizeof_object \
|
||||
cpp11_static_assert \
|
||||
cpp11_std_array \
|
||||
|
|
|
|||
41
Examples/test-suite/cpp11_rvalue_reference_move_input.i
Normal file
41
Examples/test-suite/cpp11_rvalue_reference_move_input.i
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
%module cpp11_rvalue_reference_move_input
|
||||
|
||||
// Testcase for testing rvalue reference input typemaps which assume the object is moved during a function call
|
||||
|
||||
#if defined(SWIGD)
|
||||
%rename(trace) debug;
|
||||
#endif
|
||||
|
||||
%include "cpp11_move_only_helper.i"
|
||||
|
||||
%rename(MoveAssign) MovableCopyable::operator=(MovableCopyable &&);
|
||||
%ignore MovableCopyable::operator=(const MovableCopyable &); // ignore copy assignment operator, keep move assignment operator
|
||||
%ignore MovableCopyable::MovableCopyable(const MovableCopyable &); // ignore copy constructor, keep the move constructor
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
bool debug = false;
|
||||
|
||||
class MovableCopyable {
|
||||
public:
|
||||
MovableCopyable(int i = 0) { if (debug) cout << "MovableCopyable(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
|
||||
|
||||
MovableCopyable(const MovableCopyable &other) { if (debug) cout << "MovableCopyable(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
|
||||
MovableCopyable & operator=(const MovableCopyable &other) { if (debug) cout << "operator=(const MovableCopyable &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
|
||||
|
||||
MovableCopyable(MovableCopyable &&other) noexcept { if (debug) cout << "MovableCopyable(MovableCopyable &&)" << " " << this << endl; Counter::move_constructor++; }
|
||||
MovableCopyable & operator=(MovableCopyable &&other) noexcept { if (debug) cout << "operator=(MovableCopyable &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
|
||||
~MovableCopyable() { if (debug) cout << "~MovableCopyable()" << " " << this << endl; Counter::destructor++; }
|
||||
|
||||
static void movein(MovableCopyable &&mcin) {
|
||||
MovableCopyable mc = std::move(mcin);
|
||||
}
|
||||
|
||||
static bool is_nullptr(MovableCopyable *p) {
|
||||
return p == nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGPERL)
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_unique_ptr.i"
|
||||
|
||||
%unique_ptr(Klass)
|
||||
|
|
@ -22,7 +23,7 @@ public:
|
|||
|
||||
const char* getLabel() const { return m_label.c_str(); }
|
||||
|
||||
~Klass()
|
||||
virtual ~Klass()
|
||||
{
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
total_count--;
|
||||
|
|
@ -44,6 +45,26 @@ int Klass::total_count = 0;
|
|||
|
||||
%inline %{
|
||||
|
||||
// Virtual inheritance used as this usually results in different values for Klass* and KlassInheritance*
|
||||
// for testing class inheritance and unique_ptr
|
||||
struct KlassInheritance : virtual Klass {
|
||||
KlassInheritance(const char* label) : Klass(label) {
|
||||
// std::cout << "ptrs.... " << std::hex << (Klass*)this << " " << (KlassInheritance*)this << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
std::string takeKlassUniquePtr(std::unique_ptr<Klass> k) {
|
||||
return std::string(k->getLabel());
|
||||
}
|
||||
|
||||
bool is_nullptr(Klass *p) {
|
||||
return p == nullptr;
|
||||
}
|
||||
|
||||
Klass *get_not_owned_ptr(Klass *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::unique_ptr<Klass> makeKlassUniquePtr(const char* label) {
|
||||
return std::unique_ptr<Klass>(new Klass(label));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,75 @@ public class cpp11_std_unique_ptr_runme {
|
|||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
private static void checkCount(int expected_count)
|
||||
{
|
||||
int actual_count = Klass.getTotal_count();
|
||||
if (actual_count != expected_count)
|
||||
throw new ApplicationException("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
// unique_ptr as input
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
checkCount(1);
|
||||
string s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
checkCount(0);
|
||||
if (s != "KlassInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kin))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
checkCount(1);
|
||||
string s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
checkCount(0);
|
||||
if (s != "KlassInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kin))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
} catch (ApplicationException e) {
|
||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
||||
throw new ApplicationException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new ApplicationException("double usage of takeKlassUniquePtr should have been an error");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
||||
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
||||
} catch (ApplicationException e) {
|
||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
||||
throw new ApplicationException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||
}
|
||||
checkCount(0);
|
||||
|
||||
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
|
||||
checkCount(1);
|
||||
string s = cpp11_std_unique_ptr.takeKlassUniquePtr(kini);
|
||||
checkCount(0);
|
||||
if (s != "KlassInheritanceInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kini))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
// unique_ptr as output
|
||||
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
|
||||
if (k1.getLabel() != "first")
|
||||
throw new Exception("wrong object label");
|
||||
|
|
|
|||
|
|
@ -9,8 +9,75 @@ public class li_std_auto_ptr_runme {
|
|||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
private static void checkCount(int expected_count)
|
||||
{
|
||||
int actual_count = Klass.getTotal_count();
|
||||
if (actual_count != expected_count)
|
||||
throw new ApplicationException("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
// auto_ptr as input
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
checkCount(1);
|
||||
string s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (s != "KlassInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
checkCount(1);
|
||||
string s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (s != "KlassInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
} catch (ApplicationException e) {
|
||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
||||
throw new ApplicationException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new ApplicationException("double usage of takeKlassAutoPtr should have been an error");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
using (Klass kin = new Klass("KlassInput")) {
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
||||
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
||||
} catch (ApplicationException e) {
|
||||
if (!e.Message.Contains("Cannot release ownership as memory is not owned"))
|
||||
throw new ApplicationException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||
}
|
||||
checkCount(0);
|
||||
|
||||
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
|
||||
checkCount(1);
|
||||
string s = li_std_auto_ptr.takeKlassAutoPtr(kini);
|
||||
checkCount(0);
|
||||
if (s != "KlassInheritanceInput")
|
||||
throw new ApplicationException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kini))
|
||||
throw new ApplicationException("is_nullptr failed");
|
||||
} // Dispose should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
|
||||
// auto_ptr as output
|
||||
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
|
||||
if (k1.getLabel() != "first")
|
||||
throw new Exception("wrong object label");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
import cpp11_rvalue_reference_move_input.*;
|
||||
|
||||
public class cpp11_rvalue_reference_move_input_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp11_rvalue_reference_move_input");
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
{
|
||||
Counter.reset_counts();
|
||||
MovableCopyable mo = new MovableCopyable(222);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MovableCopyable.movein(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
if (!MovableCopyable.is_nullptr(mo))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
mo.delete();
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
|
||||
{
|
||||
// Move constructor test
|
||||
Counter.reset_counts();
|
||||
MovableCopyable mo = new MovableCopyable(222);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MovableCopyable mo_moved = new MovableCopyable(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 1);
|
||||
if (!MovableCopyable.is_nullptr(mo))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
mo.delete();
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 1);
|
||||
mo_moved.delete();
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
|
||||
{
|
||||
// Move assignment operator test
|
||||
Counter.reset_counts();
|
||||
MovableCopyable mo111 = new MovableCopyable(111);
|
||||
MovableCopyable mo222 = new MovableCopyable(222);
|
||||
Counter.check_counts(2, 0, 0, 0, 0, 0);
|
||||
mo111.MoveAssign(mo222);
|
||||
Counter.check_counts(2, 0, 0, 0, 1, 1);
|
||||
if (!MovableCopyable.is_nullptr(mo222))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
mo222.delete();
|
||||
Counter.check_counts(2, 0, 0, 0, 1, 1);
|
||||
mo111.delete();
|
||||
Counter.check_counts(2, 0, 0, 0, 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,8 +20,82 @@ public class cpp11_std_unique_ptr_runme {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkCount(int expected_count) {
|
||||
int actual_count = Klass.getTotal_count();
|
||||
if (actual_count != expected_count)
|
||||
throw new RuntimeException("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws Throwable
|
||||
{
|
||||
// unique_ptr as input
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
|
||||
} catch (RuntimeException e) {
|
||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
||||
throw new RuntimeException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("double usage of takeKlassUniquePtr should have been an error");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin);
|
||||
cpp11_std_unique_ptr.takeKlassUniquePtr(notowned);
|
||||
} catch (RuntimeException e) {
|
||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
||||
throw new RuntimeException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||
kin.delete();
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
String s = cpp11_std_unique_ptr.takeKlassUniquePtr(kini);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInheritanceInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!cpp11_std_unique_ptr.is_nullptr(kini))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kini.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
// unique_ptr as output
|
||||
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
|
||||
if (!k1.getLabel().equals("first"))
|
||||
throw new RuntimeException("wrong object label");
|
||||
|
|
|
|||
|
|
@ -20,8 +20,82 @@ public class li_std_auto_ptr_runme {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkCount(int expected_count) {
|
||||
int actual_count = Klass.getTotal_count();
|
||||
if (actual_count != expected_count)
|
||||
throw new RuntimeException("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws Throwable
|
||||
{
|
||||
// auto_ptr as input
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
checkCount(1);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kin))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
li_std_auto_ptr.takeKlassAutoPtr(kin);
|
||||
} catch (RuntimeException e) {
|
||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
||||
throw new RuntimeException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("double usage of takeKlassAutoPtr should have been an error");
|
||||
kin.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
Klass kin = new Klass("KlassInput");
|
||||
boolean exception_thrown = false;
|
||||
try {
|
||||
Klass notowned = li_std_auto_ptr.get_not_owned_ptr(kin);
|
||||
li_std_auto_ptr.takeKlassAutoPtr(notowned);
|
||||
} catch (RuntimeException e) {
|
||||
if (!e.getMessage().contains("Cannot release ownership as memory is not owned"))
|
||||
throw new RuntimeException("incorrect exception message");
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new RuntimeException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||
kin.delete();
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
String s = li_std_auto_ptr.takeKlassAutoPtr(kini);
|
||||
checkCount(0);
|
||||
if (!s.equals("KlassInheritanceInput"))
|
||||
throw new RuntimeException("Incorrect string: " + s);
|
||||
if (!li_std_auto_ptr.is_nullptr(kini))
|
||||
throw new RuntimeException("is_nullptr failed");
|
||||
kini.delete(); // Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
// auto_ptr as output
|
||||
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
|
||||
if (!k1.getLabel().equals("first"))
|
||||
throw new RuntimeException("wrong object label");
|
||||
|
|
|
|||
|
|
@ -193,6 +193,37 @@ try {
|
|||
}
|
||||
%}
|
||||
|
||||
%typemap(javabody) SWIGTYPE %{
|
||||
private transient long swigCPtr;
|
||||
protected transient boolean swigCMemOwn;
|
||||
|
||||
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
||||
swigCMemOwn = cMemoryOwn;
|
||||
swigCPtr = cPtr;
|
||||
}
|
||||
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
|
||||
protected static long swigRelease($javaclassname obj) {
|
||||
long ptr = 0;
|
||||
if (obj != null) {
|
||||
if (!obj.swigCMemOwn)
|
||||
throw new RuntimeException("Cannot release ownership as memory is not owned");
|
||||
ptr = obj.swigCPtr;
|
||||
obj.swigCMemOwn = false;
|
||||
try {
|
||||
obj.delete();
|
||||
} catch (MyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
struct NoExceptTest {
|
||||
unsigned int noExceptionPlease() { return 123; }
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGPERL)
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_auto_ptr.i"
|
||||
|
||||
%auto_ptr(Klass)
|
||||
|
|
@ -27,10 +28,13 @@ namespace std {
|
|||
template <class T> class auto_ptr {
|
||||
T *ptr;
|
||||
public:
|
||||
auto_ptr(T *ptr = 0) : ptr(ptr) {}
|
||||
explicit auto_ptr(T *p = 0) : ptr(p) {}
|
||||
auto_ptr(auto_ptr&& a) : ptr(a.ptr) { a.ptr = 0;}
|
||||
~auto_ptr() { delete ptr; }
|
||||
T *release() { T *p = ptr; ptr = 0; return p; }
|
||||
void reset(T *p = 0) { delete ptr; ptr = p; }
|
||||
T &operator*() const { return *ptr; }
|
||||
T *operator->() const { return ptr; }
|
||||
auto_ptr& operator=(auto_ptr&& a) { if (&a != this) { delete ptr; ptr = a.ptr; a.ptr = 0; } return *this; }
|
||||
};
|
||||
}
|
||||
|
|
@ -53,7 +57,7 @@ public:
|
|||
|
||||
const char* getLabel() const { return m_label.c_str(); }
|
||||
|
||||
~Klass()
|
||||
virtual ~Klass()
|
||||
{
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
total_count--;
|
||||
|
|
@ -73,10 +77,28 @@ int Klass::total_count = 0;
|
|||
|
||||
%}
|
||||
|
||||
%template(KlassAutoPtr) std::auto_ptr<Klass>;
|
||||
|
||||
%inline %{
|
||||
|
||||
// Virtual inheritance used as this usually results in different values for Klass* and KlassInheritance*
|
||||
// for testing class inheritance and auto_ptr
|
||||
struct KlassInheritance : virtual Klass {
|
||||
KlassInheritance(const char* label) : Klass(label) {
|
||||
// std::cout << "ptrs.... " << std::hex << (Klass*)this << " " << (KlassInheritance*)this << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
std::string takeKlassAutoPtr(std::auto_ptr<Klass> k) {
|
||||
return std::string(k->getLabel());
|
||||
}
|
||||
|
||||
bool is_nullptr(Klass *p) {
|
||||
return p == 0;
|
||||
}
|
||||
|
||||
Klass *get_not_owned_ptr(Klass *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::auto_ptr<Klass> makeKlassAutoPtr(const char* label) {
|
||||
return std::auto_ptr<Klass>(new Klass(label));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,67 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 24;
|
||||
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
||||
require_ok('cpp11_std_unique_ptr');
|
||||
|
||||
# adapted from ../java/cpp11_std_unique_ptr_runme.java
|
||||
|
||||
sub checkCount {
|
||||
my($expected_count) = @_;
|
||||
my $actual_count = cpp11_std_unique_ptr::Klass::getTotal_count();
|
||||
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
||||
}
|
||||
|
||||
# unique_ptr as input
|
||||
{
|
||||
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = cpp11_std_unique_ptr::takeKlassUniquePtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(cpp11_std_unique_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = cpp11_std_unique_ptr::takeKlassUniquePtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(cpp11_std_unique_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
eval {
|
||||
cpp11_std_unique_ptr::takeKlassUniquePtr($kin);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassUniquePtr should be an error");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
||||
eval {
|
||||
my $notowned = cpp11_std_unique_ptr::get_not_owned_ptr($kin);
|
||||
cpp11_std_unique_ptr::takeKlassUniquePtr($notowned);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassUniquePtr should be an error");
|
||||
undef $kin;
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kini = new cpp11_std_unique_ptr::KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
my $s = cpp11_std_unique_ptr::takeKlassUniquePtr($kini);
|
||||
checkCount(0);
|
||||
is($s, "KlassInheritanceInput", "Incorrect string: $s");
|
||||
is(cpp11_std_unique_ptr::is_nullptr($kini), 1, "is_nullptr failed");
|
||||
undef $kini; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
# unique_ptr as output
|
||||
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
|
||||
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
|
||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,67 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 24;
|
||||
BEGIN { use_ok('li_std_auto_ptr') }
|
||||
require_ok('li_std_auto_ptr');
|
||||
|
||||
# adapted from ../java/li_std_auto_ptr_runme.java
|
||||
|
||||
sub checkCount {
|
||||
my($expected_count) = @_;
|
||||
my $actual_count = li_std_auto_ptr::Klass::getTotal_count();
|
||||
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
||||
}
|
||||
|
||||
# auto_ptr as input
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
checkCount(0);
|
||||
is($s, "KlassInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kin), 1, "is_nullptr check");
|
||||
eval {
|
||||
li_std_auto_ptr::takeKlassAutoPtr($kin);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassAutoPtr should be an error");
|
||||
undef $kin; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||
eval {
|
||||
my $notowned = li_std_auto_ptr::get_not_owned_ptr($kin);
|
||||
li_std_auto_ptr::takeKlassAutoPtr($notowned);
|
||||
};
|
||||
like($@, qr/\bcannot release ownership as memory is not owned\b/, "double usage of takeKlassAutoPtr should be an error");
|
||||
undef $kin;
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
{
|
||||
my $kini = new li_std_auto_ptr::KlassInheritance("KlassInheritanceInput");
|
||||
checkCount(1);
|
||||
my $s = li_std_auto_ptr::takeKlassAutoPtr($kini);
|
||||
checkCount(0);
|
||||
is($s, "KlassInheritanceInput", "Incorrect string: $s");
|
||||
is(li_std_auto_ptr::is_nullptr($kini), 1, "is_nullptr failed");
|
||||
undef $kini; # Should not fail, even though already deleted
|
||||
checkCount(0);
|
||||
}
|
||||
|
||||
# auto_ptr as output
|
||||
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
|
||||
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
|
||||
is(li_std_auto_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,72 @@
|
|||
from cpp11_std_unique_ptr import *
|
||||
|
||||
def checkCount(expected_count):
|
||||
actual_count = Klass.getTotal_count()
|
||||
if (actual_count != expected_count):
|
||||
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
||||
|
||||
# unique_ptr as input
|
||||
kin = Klass("KlassInput")
|
||||
checkCount(1)
|
||||
s = takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if kin.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kin):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
del kin # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
kin = Klass("KlassInput")
|
||||
checkCount(1)
|
||||
s = takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if kin.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kin):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
exception_thrown = False
|
||||
try:
|
||||
s = takeKlassUniquePtr(kin)
|
||||
except RuntimeError as e:
|
||||
if "cannot release ownership as memory is not owned" not in str(e):
|
||||
raise RuntimeError("incorrect exception message");
|
||||
exception_thrown = True
|
||||
if not exception_thrown:
|
||||
raise RuntimeError("double usage of takeKlassUniquePtr should have been an error")
|
||||
del kin # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
kin = Klass("KlassInput")
|
||||
exception_thrown = False
|
||||
try:
|
||||
notowned = get_not_owned_ptr(kin)
|
||||
takeKlassUniquePtr(notowned)
|
||||
except RuntimeError as e:
|
||||
exception_thrown = True
|
||||
if not exception_thrown:
|
||||
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
||||
del kin
|
||||
checkCount(0)
|
||||
|
||||
kini = KlassInheritance("KlassInheritanceInput")
|
||||
checkCount(1)
|
||||
s = takeKlassUniquePtr(kini)
|
||||
checkCount(0)
|
||||
if kini.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInheritanceInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kini):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
del kini # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
# unique_ptr as output
|
||||
k1 = makeKlassUniquePtr("first")
|
||||
k2 = makeKlassUniquePtr("second")
|
||||
if Klass.getTotal_count() != 2:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,72 @@
|
|||
from li_std_auto_ptr import *
|
||||
|
||||
def checkCount(expected_count):
|
||||
actual_count = Klass.getTotal_count()
|
||||
if (actual_count != expected_count):
|
||||
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
||||
|
||||
# auto_ptr as input
|
||||
kin = Klass("KlassInput")
|
||||
checkCount(1)
|
||||
s = takeKlassAutoPtr(kin)
|
||||
checkCount(0)
|
||||
if kin.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kin):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
del kin # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
kin = Klass("KlassInput")
|
||||
checkCount(1)
|
||||
s = takeKlassAutoPtr(kin)
|
||||
checkCount(0)
|
||||
if kin.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kin):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
exception_thrown = False
|
||||
try:
|
||||
s = takeKlassAutoPtr(kin)
|
||||
except RuntimeError as e:
|
||||
if "cannot release ownership as memory is not owned" not in str(e):
|
||||
raise RuntimeError("incorrect exception message");
|
||||
exception_thrown = True
|
||||
if not exception_thrown:
|
||||
raise RuntimeError("double usage of takeKlassAutoPtr should have been an error")
|
||||
del kin # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
kin = Klass("KlassInput")
|
||||
exception_thrown = False
|
||||
try:
|
||||
notowned = get_not_owned_ptr(kin)
|
||||
takeKlassAutoPtr(notowned)
|
||||
except RuntimeError as e:
|
||||
exception_thrown = True
|
||||
if not exception_thrown:
|
||||
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
||||
del kin
|
||||
checkCount(0)
|
||||
|
||||
kini = KlassInheritance("KlassInheritanceInput")
|
||||
checkCount(1)
|
||||
s = takeKlassAutoPtr(kini)
|
||||
checkCount(0)
|
||||
if kini.thisown:
|
||||
raise RuntimeError("thisown should be false")
|
||||
if s != "KlassInheritanceInput":
|
||||
raise RuntimeError("Incorrect string: " + s)
|
||||
if not is_nullptr(kini):
|
||||
raise RuntimeError("is_nullptr failed")
|
||||
del kini # Should not fail, even though already deleted
|
||||
checkCount(0)
|
||||
|
||||
# auto_ptr as output
|
||||
k1 = makeKlassAutoPtr("first")
|
||||
k2 = makeKlassAutoPtr("second")
|
||||
if Klass.getTotal_count() != 2:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,100 @@ def gc_check(expected_count)
|
|||
# swig_assert_equal_simple(expected_count, Cpp11_std_unique_ptr::Klass::getTotal_count())
|
||||
end
|
||||
|
||||
def checkCount(expected_count)
|
||||
actual_count = Cpp11_std_unique_ptr::Klass.getTotal_count()
|
||||
if (actual_count != expected_count)
|
||||
raise RuntimeError, "Counts incorrect, expected:" + expected_count + " actual:" + actual_count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# unique_ptr as input
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
|
||||
rescue RuntimeError => e
|
||||
# puts e.message
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "double usage of takeKlassUniquePtr should have been an error"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||
exception_thrown = false
|
||||
begin
|
||||
notowned = Cpp11_std_unique_ptr::get_not_owned_ptr(kin)
|
||||
Cpp11_std_unique_ptr::takeKlassUniquePtr(notowned)
|
||||
rescue RuntimeError => e
|
||||
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
||||
raise RuntimeError, "incorrect exception message"
|
||||
end
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||
end
|
||||
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
|
||||
checkCount(0)
|
||||
|
||||
kini = Cpp11_std_unique_ptr::KlassInheritance.new("KlassInheritanceInput")
|
||||
checkCount(1)
|
||||
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kini)
|
||||
checkCount(0)
|
||||
if (s != "KlassInheritanceInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_std_unique_ptr.is_nullptr(kini)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kini = nil
|
||||
checkCount(0)
|
||||
|
||||
# unique_ptr as output
|
||||
k1 = Cpp11_std_unique_ptr::makeKlassUniquePtr("first")
|
||||
k2 = Cpp11_std_unique_ptr::makeKlassUniquePtr("second")
|
||||
swig_assert_equal_simple(2, Cpp11_std_unique_ptr::Klass::getTotal_count())
|
||||
|
|
|
|||
|
|
@ -11,6 +11,100 @@ def gc_check(expected_count)
|
|||
# swig_assert_equal_simple(expected_count, Li_std_auto_ptr::Klass::getTotal_count())
|
||||
end
|
||||
|
||||
def checkCount(expected_count)
|
||||
actual_count = Li_std_auto_ptr::Klass.getTotal_count()
|
||||
if (actual_count != expected_count)
|
||||
raise RuntimeError, "Counts incorrect, expected:" + expected_count + " actual:" + actual_count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# auto_ptr as input
|
||||
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Li_std_auto_ptr.takeKlassAutoPtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Li_std_auto_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
||||
checkCount(1)
|
||||
s = Li_std_auto_ptr.takeKlassAutoPtr(kin)
|
||||
checkCount(0)
|
||||
if (s != "KlassInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Li_std_auto_ptr.is_nullptr(kin)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Li_std_auto_ptr.takeKlassAutoPtr(kin)
|
||||
rescue RuntimeError => e
|
||||
# puts e.message
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "double usage of takeKlassAutoPtr should have been an error"
|
||||
end
|
||||
kin = nil
|
||||
checkCount(0)
|
||||
|
||||
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
||||
exception_thrown = false
|
||||
begin
|
||||
notowned = Li_std_auto_ptr::get_not_owned_ptr(kin)
|
||||
Li_std_auto_ptr::takeKlassAutoPtr(notowned)
|
||||
rescue RuntimeError
|
||||
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
||||
raise RuntimeError, "incorrect exception message"
|
||||
end
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||
end
|
||||
Li_std_auto_ptr.takeKlassAutoPtr(kin) # Ensure object is deleted (can't rely on GC)
|
||||
checkCount(0)
|
||||
|
||||
kini = Li_std_auto_ptr::KlassInheritance.new("KlassInheritanceInput")
|
||||
checkCount(1)
|
||||
s = Li_std_auto_ptr.takeKlassAutoPtr(kini)
|
||||
checkCount(0)
|
||||
if (s != "KlassInheritanceInput")
|
||||
raise RuntimeError, "Incorrect string: " + s
|
||||
end
|
||||
exception_thrown = false
|
||||
begin
|
||||
Li_std_auto_ptr.is_nullptr(kini)
|
||||
rescue ObjectPreviouslyDeleted
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "is_nullptr failed to throw"
|
||||
end
|
||||
kini = nil
|
||||
checkCount(0)
|
||||
|
||||
# auto_ptr as output
|
||||
k1 = Li_std_auto_ptr::makeKlassAutoPtr("first")
|
||||
k2 = Li_std_auto_ptr::makeKlassAutoPtr("second")
|
||||
swig_assert_equal_simple(2, Li_std_auto_ptr::Klass::getTotal_count())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue