SWIGTYPE && input typemaps now assume object has been moved
Change these typemaps to assume that after a function call, the parameter has been moved. The parameter's proxy class that owns the C++ object thus has the underlying pointer set to null so the object cannot be used again and the object is deleted. Scrap new javarelease typemap and move contents into javabody typemap.
This commit is contained in:
parent
6b361bf050
commit
bf761998ed
7 changed files with 150 additions and 18 deletions
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;
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
Loading…
Add table
Add a link
Reference in a new issue