Movable and move-only types supported in "out" typemaps.

Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.

Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.

The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:

  SwigValueWrapper::operator T&() const;

to

  #if __cplusplus >=201103L
    SwigValueWrapper::operator T&&() const;
  #else
    SwigValueWrapper::operator T&() const;
  #endif

This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:

1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
   __cplusplus macro if all versions of C++ need to be supported.

Issue #999
Closes #1044

More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.

Ruby std::set fix for SwigValueWrapper C++11 changes.
This commit is contained in:
William S Fulton 2022-06-22 12:52:06 +01:00
commit bf36bf7d8a
34 changed files with 508 additions and 138 deletions

View file

@ -7,6 +7,39 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress) Version 4.1.0 (in progress)
=========================== ===========================
2022-06-29: wsfulton
#999 #1044 Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.
Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.
The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:
SwigValueWrapper::operator T&() const;
to
#if __cplusplus >=201103L
SwigValueWrapper::operator T&&() const;
#else
SwigValueWrapper::operator T&() const;
#endif
This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:
1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
__cplusplus macro if all versions of C++ need to be supported.
*** POTENTIAL INCOMPATIBILITY ***
2022-06-15: wsfulton 2022-06-15: wsfulton
#2039 Add move assignment operator to SwigValueWrapper used by the #2039 Add move assignment operator to SwigValueWrapper used by the
valuewrapper feature. valuewrapper feature.

View file

@ -15,6 +15,9 @@
<li><a href="#CPlusPlus11_core_language_changes">Core language changes</a> <li><a href="#CPlusPlus11_core_language_changes">Core language changes</a>
<ul> <ul>
<li><a href="#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a> <li><a href="#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<ul>
<li><a href="#CPlusPlus11_move_only">Movable and move-only types</a>
</ul>
<li><a href="#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a> <li><a href="#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
<li><a href="#CPlusPlus11_extern_template">Extern template</a> <li><a href="#CPlusPlus11_extern_template">Extern template</a>
<li><a href="#CPlusPlus11_initializer_lists">Initializer lists</a> <li><a href="#CPlusPlus11_initializer_lists">Initializer lists</a>
@ -123,6 +126,82 @@ example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid ide
</pre> </pre>
</div> </div>
<H4><a name="CPlusPlus11_move_only">7.2.1.1 Movable and move-only types</a></H4>
<p>
SWIG has traditionally relied on wrapped C++ types to be copy constructible or copy assignable, either via an explicit or implicit copy constructor and copy assignment operator.
Prior to C++11, a function could not return nor take a type by value that was not copyable.
In C++11 this is no longer the case. A type can also be movable if it has has a move constructor and a move assignment operator.
A move-only type is movable but not copyable; it has both the copy constructor and copy assignment operator deleted.
Movable types can appear in function signatures for passing 'by value' and in C++11 the object can then be moved rather than copied.
</p>
<p>
SWIG has been enhanced with support for both copyable and/or movable types but this is currently just for function return values.
</p>
<p>
The support for function return values is generically implemented in the "out" <tt>SWIGTYPE</tt> typemap which supports any type, including copyable, movable and move-only types.
The typemap code is very simple and written so that the compiler will call the move constructor if possible,
otherwise the copy constructor:
</p>
<div class="code"><pre>
%typemap(out) SWIGTYPE %{
$result = new $1_ltype($1);
%}
</pre></div>
<p>
The above typemap is for C# and when used to wrap a move-only type such as:
</p>
<div class="code"><pre>
struct MoveOnly {
int val;
MoveOnly(): val(0) {}
MoveOnly(const MoveOnly &amp;) = delete;
MoveOnly(MoveOnly &amp;&amp;) = default;
MoveOnly &amp; operator=(const MoveOnly &amp;) = delete;
MoveOnly &amp; operator=(MoveOnly &amp;&amp;) = default;
static MoveOnly create() { return MoveOnly(); }
};
</pre></div>
<p>
will generate wrapper code for the <tt>create</tt> factory method:
</p>
<div class="code"><pre>
SWIGEXPORT void * SWIGSTDCALL CSharp_MoveOnly_create() {
void * jresult ;
SwigValueWrapper&lt; MoveOnly &gt; result;
result = MoveOnly::create();
jresult = new MoveOnly(result);
return jresult;
}
</pre></div>
<p>
<tt>SwigValueWrapper</tt> is covered in <a href="SWIGPlus.html#SWIGPlus_nn19">Pass and return by value</a>.
Note that the generated code could be optimised further using the <a href="Typemaps.html#Typemaps_optimal">"optimal" attribute</a> in the "out" typemap.
</p>
<p>
There is currently only partial support for move-only types as
support for move-only types used as a parameter in a function, that are passed 'by value', is not yet available.
</p>
<p>
<b>Compatibility note:</b>
SWIG-4.1.0 introduced support for taking advantage of types with move semantics and wrapping functions that return movable or move-only types 'by value'.
</p>
<H3><a name="CPlusPlus11_generalized_constant_expressions">7.2.2 Generalized constant expressions</a></H3> <H3><a name="CPlusPlus11_generalized_constant_expressions">7.2.2 Generalized constant expressions</a></H3>

View file

@ -297,6 +297,9 @@
<li><a href="CPlusPlus11.html#CPlusPlus11_core_language_changes">Core language changes</a> <li><a href="CPlusPlus11.html#CPlusPlus11_core_language_changes">Core language changes</a>
<ul> <ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a> <li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_move_only">Movable and move-only types</a>
</ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a> <li><a href="CPlusPlus11.html#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_extern_template">Extern template</a> <li><a href="CPlusPlus11.html#CPlusPlus11_extern_template">Extern template</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_initializer_lists">Initializer lists</a> <li><a href="CPlusPlus11.html#CPlusPlus11_initializer_lists">Initializer lists</a>

View file

@ -584,7 +584,7 @@ automatically generate a wrapper for one.
<li> <li>
If a C++ class does not declare an explicit copy constructor, SWIG will If a C++ class does not declare an explicit copy constructor, SWIG will
automatically generate a wrapper for one if the <tt>%copyctor</tt> is used. automatically generate a wrapper for one if <tt>%copyctor</tt> is used.
</li> </li>
<li> <li>
@ -1352,16 +1352,19 @@ following:
<div class="code"> <div class="code">
<pre> <pre>
Vector *wrap_cross_product(Vector *a, Vector *b) { Vector *wrap_cross_product(Vector *a, Vector *b) {
Vector x = *a; Vector x;
Vector y = *b; Vector y;
Vector r = cross_product(x, y); Vector r;
x = *a;
y = *b;
r = cross_product(x, y);
return new Vector(r); return new Vector(r);
}</pre> }</pre>
</div> </div>
<p> <p>
In order for the wrapper code to compile, <tt>Vector</tt> must define a copy constructor and a In order for the wrapper code to compile, <tt>Vector</tt> must define a default constructor, copy assignment operator (and/or a move assignment operator for C++11 and later).
default constructor. The <a href="CPlusPlus11.html#CPlusPlus11_move_only">Movable and move-only types</a> section should be read regarding C++11 move semantics and return by value.
</p> </p>
<p> <p>
@ -1374,9 +1377,12 @@ called the "Fulton Transform". This produces a wrapper that looks like this:
<div class="code"> <div class="code">
<pre> <pre>
Vector cross_product(Vector *a, Vector *b) { Vector cross_product(Vector *a, Vector *b) {
SwigValueWrapper&lt;Vector&gt; x = *a; SwigValueWrapper&lt;Vector&gt; x;
SwigValueWrapper&lt;Vector&gt; y = *b; SwigValueWrapper&lt;Vector&gt; y;
SwigValueWrapper&lt;Vector&gt; r = cross_product(x, y); SwigValueWrapper&lt;Vector&gt; r;
x = *a;
y = *b;
r = cross_product(x, y);
return new Vector(r); return new Vector(r);
} }
</pre> </pre>

View file

@ -3364,7 +3364,7 @@ Consider running the following code through SWIG:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(out) SWIGTYPE %{ %typemap(out) SWIGTYPE %{
$result = new $1_ltype((const $1_ltype &amp;)$1); $result = new $1_ltype($1);
%} %}
%inline %{ %inline %{
@ -3414,7 +3414,7 @@ If the typemap code is kept the same and just the "optimal" attribute specified
<div class="code"> <div class="code">
<pre> <pre>
%typemap(out, optimal="1") SWIGTYPE %{ %typemap(out, optimal="1") SWIGTYPE %{
$result = new $1_ltype((const $1_ltype &amp;)$1); $result = new $1_ltype($1);
%} %}
</pre> </pre>
</div> </div>
@ -3441,7 +3441,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_XX_create() {
void * jresult ; void * jresult ;
XX result; XX result;
result = XX::create(); result = XX::create();
jresult = new XX((const XX &amp;)result); jresult = new XX(result);
return jresult; return jresult;
} }
@ -3456,7 +3456,7 @@ With the "optimal" attribute, the code is:
<pre> <pre>
SWIGEXPORT void * SWIGSTDCALL CSharp_XX_create() { SWIGEXPORT void * SWIGSTDCALL CSharp_XX_create() {
void * jresult ; void * jresult ;
jresult = new XX((const XX &amp;)XX::create()); jresult = new XX(XX::create());
return jresult; return jresult;
} }
</pre> </pre>
@ -3513,7 +3513,7 @@ It should be clear that the above code cannot be used as the argument to the cop
</p> </p>
<p> <p>
Secondly, if the typemaps uses <tt>$1</tt> more than once, then multiple calls to the wrapped function Secondly, if the typemap uses <tt>$1</tt> more than once, then multiple calls to the wrapped function
will be made. Obviously that is not very optimal. will be made. Obviously that is not very optimal.
In fact SWIG attempts to detect this and will issue a warning something like: In fact SWIG attempts to detect this and will issue a warning something like:
</p> </p>

View file

@ -597,6 +597,7 @@ CPP11_TEST_CASES += \
cpp11_initializer_list \ cpp11_initializer_list \
cpp11_initializer_list_extend \ cpp11_initializer_list_extend \
cpp11_lambda_functions \ cpp11_lambda_functions \
cpp11_move_only \
cpp11_move_only_valuewrapper \ cpp11_move_only_valuewrapper \
cpp11_noexcept \ cpp11_noexcept \
cpp11_null_pointer_constant \ cpp11_null_pointer_constant \

View file

@ -0,0 +1,52 @@
%module cpp11_move_only
#if defined(SWIGD)
%rename(trace) debug;
#endif
%include "cpp11_move_only_helper.i"
%ignore MoveOnly::operator=;
//%valuewrapper MoveOnly; // SWIG sets %valuewrapper by default for move-only types
%inline %{
#include <iostream>
using namespace std;
bool debug = false;
struct MoveOnly {
MoveOnly(int i = 0) { if (debug) cout << "MoveOnly(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
MoveOnly(const MoveOnly &other) = delete;
MoveOnly & operator=(const MoveOnly &other) = delete;
MoveOnly(MoveOnly &&other) noexcept { if (debug) cout << "MoveOnly(MoveOnly &&)" << " " << this << endl; Counter::move_constructor++; }
MoveOnly & operator=(MoveOnly &&other) noexcept { if (debug) cout << "operator=(MoveOnly &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
~MoveOnly() { if (debug) cout << "~MoveOnly()" << " " << this << endl; Counter::destructor++; }
static MoveOnly create() { return MoveOnly(111); }
// static const MoveOnly createConst() { return MoveOnly(111); } // not supported by default
};
%}
%ignore MovableCopyable::operator=;
%ignore MovableCopyable::MovableCopyable(MovableCopyable &&);
// %valuewrapper MovableCopyable; // SWIG does not use valuewrapper by default for copyable types with a default constructor
%inline %{
// Movable and Copyable
struct MovableCopyable {
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 MovableCopyable create() { return MovableCopyable(111); }
static const MovableCopyable createConst() { return MovableCopyable(111); }
};
%}

View file

@ -0,0 +1,71 @@
// Helper interface for cpp11_move_only.i and others
%include <std_string.i>
%catches(std::string) Counter::check_counts;
%inline %{
#include <sstream>
using namespace std;
struct Counter {
static int normal_constructor;
static int copy_constructor;
static int copy_assignment;
static int move_constructor;
static int move_assignment;
static int destructor;
static void reset_counts() {
normal_constructor = 0;
copy_constructor = 0;
copy_assignment = 0;
move_constructor = 0;
move_assignment = 0;
destructor = 0;
}
// Check against expected counts of constructor, assignment operators etc.
// Not observed during development, but compiler optimisation could change the expected values.
// Throws exception if not correct (use %catches to catch them)
static void check_counts(
int normal_constructor,
int copy_constructor,
int copy_assignment,
int move_constructor,
int move_assignment,
int destructor) {
bool match = (
normal_constructor == Counter::normal_constructor &&
copy_constructor == Counter::copy_constructor &&
copy_assignment == Counter::copy_assignment &&
move_constructor == Counter::move_constructor &&
move_assignment == Counter::move_assignment &&
destructor == Counter::destructor);
if (!match) {
std::stringstream ss;
ss << "check_counts failed" << std::endl <<
Counter::normal_constructor << " " <<
Counter::copy_constructor << " " <<
Counter::copy_assignment << " " <<
Counter::move_constructor << " " <<
Counter::move_assignment << " " <<
Counter::destructor << " " <<
" (actual)" << std::endl <<
normal_constructor << " " <<
copy_constructor << " " <<
copy_assignment << " " <<
move_constructor << " " <<
move_assignment << " " <<
destructor << " " <<
" (expected)" << std::endl;
throw ss.str();
}
}
};
int Counter::normal_constructor = 0;
int Counter::copy_constructor = 0;
int Counter::copy_assignment = 0;
int Counter::move_constructor = 0;
int Counter::move_assignment = 0;
int Counter::destructor = 0;
%}

View file

@ -37,82 +37,28 @@ namespace std {
#endif #endif
%} %}
%include <std_string.i> #if defined(SWIGD)
%rename(trace) debug;
#endif
%include "cpp11_move_only_helper.i"
%valuewrapper XXX; %valuewrapper XXX;
%ignore XXX::operator=; %ignore XXX::operator=;
%catches(std::string) XXX::check_counts;
%inline %{ %inline %{
bool debug = false; bool debug = false;
struct XXX { struct XXX {
XXX(int i = 0) { if (debug) cout << "XXX(" << i << ")" << " " << this << endl; normal_constructor_count++; } XXX(int i = 0) { if (debug) cout << "XXX(" << i << ")" << " " << this << endl; Counter::normal_constructor++; }
XXX(const XXX &other) { if (debug) cout << "XXX(const XXX &)" << " " << this << " " << &other << endl; copy_constructor_count++;} XXX(const XXX &other) { if (debug) cout << "XXX(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_constructor++;}
XXX & operator=(const XXX &other) { if (debug) cout << "operator=(const XXX &)" << " " << this << " " << &other << endl; copy_assignment_count++; return *this; } XXX & operator=(const XXX &other) { if (debug) cout << "operator=(const XXX &)" << " " << this << " " << &other << endl; Counter::copy_assignment++; return *this; }
#if defined(__cplusplus) && __cplusplus >= 201103L #if defined(__cplusplus) && __cplusplus >= 201103L
XXX(XXX &&other) noexcept { if (debug) cout << "XXX(XXX &&)" << " " << this << endl; move_constructor_count++; } XXX(XXX &&other) noexcept { if (debug) cout << "XXX(XXX &&)" << " " << this << endl; Counter::move_constructor++; }
XXX & operator=(XXX &&other) noexcept { if (debug) cout << "operator=(XXX &&)" << " " << this << endl; move_assignment_count++; return *this; } XXX & operator=(XXX &&other) noexcept { if (debug) cout << "operator=(XXX &&)" << " " << this << endl; Counter::move_assignment++; return *this; }
#endif #endif
~XXX() { if (debug) cout << "~XXX()" << " " << this << endl; destructor_count++; } ~XXX() { if (debug) cout << "~XXX()" << " " << this << endl; Counter::destructor++; }
static int normal_constructor_count;
static int copy_constructor_count;
static int copy_assignment_count;
static int move_constructor_count;
static int move_assignment_count;
static int destructor_count;
static void reset_counts() {
XXX::normal_constructor_count = 0;
XXX::copy_constructor_count = 0;
XXX::copy_assignment_count = 0;
XXX::move_constructor_count = 0;
XXX::move_assignment_count = 0;
XXX::destructor_count = 0;
}
// Check against expected counts of constructor, assignment operators etc.
// Not observed during development, but compiler optimisation could change the expected values.
// Throws exception if not correct (use %catches to catch them)
static void check_counts(
int normal_constructor_count,
int copy_constructor_count,
int copy_assignment_count,
int move_constructor_count,
int move_assignment_count,
int destructor_count) {
bool match = (
normal_constructor_count == XXX::normal_constructor_count &&
copy_constructor_count == XXX::copy_constructor_count &&
copy_assignment_count == XXX::copy_assignment_count &&
move_constructor_count == XXX::move_constructor_count &&
move_assignment_count == XXX::move_assignment_count &&
destructor_count == XXX::destructor_count);
if (!match) {
std::stringstream ss;
ss << "check_counts failed" << std::endl <<
XXX::normal_constructor_count << " " <<
XXX::copy_constructor_count << " " <<
XXX::copy_assignment_count << " " <<
XXX::move_constructor_count << " " <<
XXX::move_assignment_count << " " <<
XXX::destructor_count << " " <<
" (actual)" << std::endl <<
normal_constructor_count << " " <<
copy_constructor_count << " " <<
copy_assignment_count << " " <<
move_constructor_count << " " <<
move_assignment_count << " " <<
destructor_count << " " <<
" (expected)" << std::endl;
throw ss.str();
}
}
}; };
int XXX::normal_constructor_count = 0;
int XXX::copy_constructor_count = 0;
int XXX::copy_assignment_count = 0;
int XXX::move_constructor_count = 0;
int XXX::move_assignment_count = 0;
int XXX::destructor_count = 0;
bool has_cplusplus11() { bool has_cplusplus11() {
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
return true; return true;
@ -122,20 +68,8 @@ bool has_cplusplus11() {
} }
%} %}
#if defined(SWIGCSHARP)
%typemap(out) std::unique_ptr<XXX> %{
if (debug) cout << "out start" << endl;
#if __cplusplus >= 201103L
$result = new std::unique_ptr<XXX>(std::move(static_cast<std::unique_ptr<XXX>&>($1)));
#else
$result = new std::unique_ptr<XXX>((const std::unique_ptr<XXX> &)$1);
#endif
if (debug) cout << "out done" << endl;
%}
std::unique_ptr<XXX> makeUniqueXXX(); std::unique_ptr<XXX> makeUniqueXXX();
void cleanup(std::unique_ptr<XXX>* p); void cleanup(std::unique_ptr<XXX>* p);
#endif
%{ %{
std::unique_ptr<XXX> makeUniqueXXX() { std::unique_ptr<XXX> makeUniqueXXX() {
@ -145,6 +79,7 @@ std::unique_ptr<XXX> makeUniqueXXX() {
void cleanup(std::unique_ptr<XXX>* p) { void cleanup(std::unique_ptr<XXX>* p) {
delete p; delete p;
} }
typedef XXX UUU;
%} %}
%inline %{ %inline %{
@ -152,6 +87,16 @@ XXX createXXX() {
if (debug) cout << "createXXX()" << endl; if (debug) cout << "createXXX()" << endl;
return XXX(111); return XXX(111);
} }
XXX createXXX2() {
if (debug) cout << "createXXX2()" << endl;
return XXX(222);
}
UUU createUnknownType() {
if (debug) cout << "createXXX2()" << endl;
return XXX(222);
}
struct YYY {};
void inputByValue(UUU uuu, XXX xxx, YYY yyy) {}
%} %}
@ -165,32 +110,32 @@ XXX createXXX() {
%inline %{ %inline %{
// 'unit tests' for SwigValueWrapper // 'unit tests' for SwigValueWrapper
void test1() { void test1() {
XXX::reset_counts(); Counter::reset_counts();
{ {
SwigValueWrapper<XXX> x; SwigValueWrapper<XXX> x;
x = XXX(); x = XXX();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
XXX::check_counts(1, 0, 0, 1, 0, 2); // was same as < c++11 counts below before move assignment operator added to SwigValueWrapper Counter::check_counts(1, 0, 0, 1, 0, 2); // was same as < c++11 counts below before move assignment operator added to SwigValueWrapper
#else #else
XXX::check_counts(1, 1, 0, 0, 0, 2); Counter::check_counts(1, 1, 0, 0, 0, 2);
#endif #endif
} }
void test2() { void test2() {
XXX::reset_counts(); Counter::reset_counts();
{ {
SwigValueWrapper<XXX> x; SwigValueWrapper<XXX> x;
x = XXX(); x = XXX();
x = XXX(); x = XXX();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
XXX::check_counts(2, 0, 0, 2, 0, 4); Counter::check_counts(2, 0, 0, 2, 0, 4);
#else #else
XXX::check_counts(2, 2, 0, 0, 0, 4); Counter::check_counts(2, 2, 0, 0, 0, 4);
#endif #endif
} }
void test3() { void test3() {
XXX::reset_counts(); Counter::reset_counts();
{ {
SwigValueWrapper<XXX> x; SwigValueWrapper<XXX> x;
XXX a(999); XXX a(999);
@ -199,41 +144,41 @@ void test3() {
#endif #endif
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
XXX::check_counts(1, 0, 0, 1, 0, 2); Counter::check_counts(1, 0, 0, 1, 0, 2);
#endif #endif
} }
void test4() { void test4() {
XXX::reset_counts(); Counter::reset_counts();
{ {
SwigValueWrapper<std::unique_ptr<XXX> > x; SwigValueWrapper<std::unique_ptr<XXX> > x;
x = std::unique_ptr<XXX>(new XXX(444)); x = std::unique_ptr<XXX>(new XXX(444));
} }
XXX::check_counts(1, 0, 0, 0, 0, 1); Counter::check_counts(1, 0, 0, 0, 0, 1);
} }
void test5() { void test5() {
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
XXX::reset_counts(); Counter::reset_counts();
{ {
SwigValueWrapper<std::unique_ptr<XXX> > x; SwigValueWrapper<std::unique_ptr<XXX> > x;
x = std::unique_ptr<XXX>(new XXX(550)); x = std::unique_ptr<XXX>(new XXX(550));
std::unique_ptr<XXX> x2(new XXX(555)); std::unique_ptr<XXX> x2(new XXX(555));
x = std::move(x2); x = std::move(x2);
} }
XXX::check_counts(2, 0, 0, 0, 0, 2); Counter::check_counts(2, 0, 0, 0, 0, 2);
#endif #endif
} }
void test6() { void test6() {
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
XXX::reset_counts(); Counter::reset_counts();
{ {
// emulates how std::unique_ptr typemaps could be wrapped with SwigValueWrapper // emulates how std::unique_ptr typemaps could be wrapped with SwigValueWrapper
void *ptr = 0; void *ptr = 0;
SwigValueWrapper<std::unique_ptr<XXX> > x; // SWIG generated if std::unique_ptr<> definition not parsed SwigValueWrapper<std::unique_ptr<XXX> > x; // SWIG generated if std::unique_ptr<> definition not parsed
x = makeUniqueXXX(); // SWIG generated code wrapping function returning std::unique_ptr x = makeUniqueXXX(); // SWIG generated code wrapping function returning std::unique_ptr
ptr = new std::unique_ptr<XXX>(std::move((std::unique_ptr<XXX>&)x)); // 'out' typemap (move std::unique_ptr from stack to the heap), note non-const cast std::unique_tr<XXX>& ptr = new std::unique_ptr<XXX>(x); // 'out' typemap (move std::unique_ptr from stack to the heap)
delete (std::unique_ptr<XXX> *)ptr; // Final cleanup (user needs to call this) delete (std::unique_ptr<XXX> *)ptr; // Final cleanup (user needs to call this)
} }
XXX::check_counts(1, 0, 0, 0, 0, 1); Counter::check_counts(1, 0, 0, 0, 0, 1);
#endif #endif
} }
%} %}

View file

@ -0,0 +1,23 @@
using System;
using cpp11_move_onlyNamespace;
public class cpp11_move_only_runme {
public static void Main() {
Counter.reset_counts();
using (MoveOnly mo = MoveOnly.create()) {
}
Counter.check_counts(1, 0, 0, 2, 0, 3);
Counter.reset_counts();
using (MovableCopyable mo = MovableCopyable.create()) {
}
Counter.check_counts(2, 1, 0, 0, 1, 3);
// Move semantics not used
Counter.reset_counts();
using (MovableCopyable mo = MovableCopyable.createConst()) {
}
Counter.check_counts(2, 1, 1, 0, 0, 3);
}
}

View file

@ -4,11 +4,18 @@ using cpp11_move_only_valuewrapperNamespace;
public class cpp11_move_only_valuewrapper_runme { public class cpp11_move_only_valuewrapper_runme {
public static void Main() { public static void Main() {
XXX.reset_counts(); Counter.reset_counts();
using (XXX xxx = cpp11_move_only_valuewrapper.createXXX()) { using (XXX xxx = cpp11_move_only_valuewrapper.createXXX()) {
} }
if (cpp11_move_only_valuewrapper.has_cplusplus11()) if (cpp11_move_only_valuewrapper.has_cplusplus11())
XXX.check_counts(1, 1, 0, 1, 0, 3); // Was (1, 2, 0, 0, 0, 3) before SwigValueWrapper::operator=(T &&) was added. // Was (1, 2, 0, 0, 0, 3) before SwigValueWrapper::operator=(T &&) was added.
// Was (1, 1, 0, 1, 0, 3) before SwigValueWrapper::operator T&&() was added with new "out" typemaps
Counter.check_counts(1, 0, 0, 2, 0, 3);
Counter.reset_counts();
using (XXX xxx = cpp11_move_only_valuewrapper.createXXX2()) {
}
if (cpp11_move_only_valuewrapper.has_cplusplus11())
Counter.check_counts(1, 0, 0, 2, 0, 3);
cpp11_move_only_valuewrapper.test1(); cpp11_move_only_valuewrapper.test1();
cpp11_move_only_valuewrapper.test2(); cpp11_move_only_valuewrapper.test2();
cpp11_move_only_valuewrapper.test3(); cpp11_move_only_valuewrapper.test3();
@ -16,10 +23,11 @@ public class cpp11_move_only_valuewrapper_runme {
cpp11_move_only_valuewrapper.test5(); cpp11_move_only_valuewrapper.test5();
cpp11_move_only_valuewrapper.test6(); cpp11_move_only_valuewrapper.test6();
// C# only test (SwigValueWrapper and custom typemaps for std::unique_ptr) // Tests SwigValueWrapper, std::unique_ptr (SWIG not parsing a type that is move-only)
Counter.reset_counts();
SWIGTYPE_p_std__unique_ptrT_XXX_t ptr = cpp11_move_only_valuewrapper.makeUniqueXXX(); SWIGTYPE_p_std__unique_ptrT_XXX_t ptr = cpp11_move_only_valuewrapper.makeUniqueXXX();
cpp11_move_only_valuewrapper.cleanup(ptr); cpp11_move_only_valuewrapper.cleanup(ptr);
Counter.check_counts(1, 0, 0, 0, 0, 1);
} }
} }

View file

@ -3,10 +3,14 @@ using typemap_out_optimalNamespace;
public class typemap_out_optimal_runme { public class typemap_out_optimal_runme {
public static XX x = null;
public static void Main() { public static void Main() {
XX.debug = false; XX.debug = false;
x = XX.create(); if (XX.debug)
Console.WriteLine("calling create()");
using (XX x = XX.create()) { }
if (XX.debug)
Console.WriteLine("calling createConst()");
using (XX x = XX.createConst()) { }
} }
} }

View file

@ -6,4 +6,5 @@ void main() {
XX x; XX x;
XX.trace = false; XX.trace = false;
x = XX.create(); x = XX.create();
x = XX.createConst();
} }

View file

@ -6,4 +6,5 @@ void main() {
XX x; XX x;
XX.trace = false; XX.trace = false;
x = XX.create(); x = XX.create();
x = XX.createConst();
} }

View file

@ -5,4 +5,5 @@ import . "swigtests/typemap_out_optimal"
func main() { func main() {
SetXXDebug(false) SetXXDebug(false)
_ = XXCreate() _ = XXCreate()
_ = XXCreateConst()
} }

View file

@ -0,0 +1,39 @@
import cpp11_move_only.*;
public class cpp11_move_only_runme {
static {
try {
System.loadLibrary("cpp11_move_only");
} 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();
MoveOnly mo = MoveOnly.create();
mo.delete();
Counter.check_counts(1, 0, 0, 2, 0, 3);
}
{
Counter.reset_counts();
MovableCopyable mo = MovableCopyable.create();
mo.delete();
Counter.check_counts(2, 1, 0, 0, 1, 3);
}
// Move semantics not used
{
Counter.reset_counts();
MovableCopyable mo = MovableCopyable.createConst();
mo.delete();
Counter.check_counts(2, 1, 1, 0, 0, 3);
}
}
}

View file

@ -0,0 +1,44 @@
import cpp11_move_only_valuewrapper.*;
public class cpp11_move_only_valuewrapper_runme {
static {
try {
System.loadLibrary("cpp11_move_only_valuewrapper");
} 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();
{
XXX xxx = cpp11_move_only_valuewrapper.createXXX();
xxx.delete();
}
if (cpp11_move_only_valuewrapper.has_cplusplus11())
// Was (1, 2, 0, 0, 0, 3) before SwigValueWrapper::operator=(T &&) was added.
// Was (1, 1, 0, 1, 0, 3) before SwigValueWrapper::operator T&&() was added with new "out" typemaps
Counter.check_counts(1, 0, 0, 2, 0, 3);
Counter.reset_counts();
{
XXX xxx = cpp11_move_only_valuewrapper.createXXX2();
xxx.delete();
}
if (cpp11_move_only_valuewrapper.has_cplusplus11())
Counter.check_counts(1, 0, 0, 2, 0, 3);
cpp11_move_only_valuewrapper.test1();
cpp11_move_only_valuewrapper.test2();
cpp11_move_only_valuewrapper.test3();
cpp11_move_only_valuewrapper.test4();
cpp11_move_only_valuewrapper.test5();
cpp11_move_only_valuewrapper.test6();
// Tests SwigValueWrapper, std::unique_ptr (SWIG not parsing a type that is move-only)
Counter.reset_counts();
SWIGTYPE_p_std__unique_ptrT_XXX_t ptr = cpp11_move_only_valuewrapper.makeUniqueXXX();
cpp11_move_only_valuewrapper.cleanup(ptr);
Counter.check_counts(1, 0, 0, 0, 0, 1);
}
}

View file

@ -12,10 +12,16 @@ public class typemap_out_optimal_runme {
} }
} }
public static XX x = null;
public static void main(String argv[]) { public static void main(String argv[]) {
XX.setDebug(false); XX.setDebug(false);
x = XX.create(); {
XX x = XX.create();
x.delete();
}
{
XX x = XX.createConst();
x.delete();
}
} }
} }

View file

@ -0,0 +1,17 @@
from cpp11_move_only import *
Counter.reset_counts()
mo = MoveOnly.create()
del mo
Counter.check_counts(1, 0, 0, 2, 0, 3)
Counter.reset_counts()
mo = MovableCopyable.create()
del mo
Counter.check_counts(2, 1, 0, 0, 1, 3)
# Move semantics not used
Counter.reset_counts()
mo = MovableCopyable.createConst()
del mo
Counter.check_counts(2, 1, 1, 0, 0, 3)

View file

@ -2,3 +2,6 @@ from typemap_out_optimal import *
cvar.XX_debug = False cvar.XX_debug = False
x = XX.create() x = XX.create()
del x
x = XX.createConst()
del x

View file

@ -4,15 +4,15 @@
// Just the following languages tested // Just the following languages tested
#if defined (SWIGCSHARP) || defined (SWIGD) #if defined (SWIGCSHARP) || defined (SWIGD)
%typemap(out, optimal="1") SWIGTYPE %{ %typemap(out, optimal="1") SWIGTYPE %{
$result = new $1_ltype((const $1_ltype &)$1); $result = new $1_ltype($1);
%} %}
#elif defined (SWIGJAVA) #elif defined (SWIGJAVA)
%typemap(out, optimal="1") SWIGTYPE %{ %typemap(out, optimal="1") SWIGTYPE %{
*($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); *($&1_ltype*)&$result = new $1_ltype($1);
%} %}
#elif defined (SWIGUTL) #elif defined (SWIGUTL)
%typemap(out,noblock="1", optimal="1") SWIGTYPE { %typemap(out,noblock="1", optimal="1") SWIGTYPE {
%set_output(SWIG_NewPointerObj(%new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags)); %set_output(SWIG_NewPointerObj(new $1_ltype($1), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
} }
#endif #endif
@ -32,9 +32,14 @@ struct XX {
XX(const XX &other) { if (debug) cout << "XX(const XX &)" << endl; } XX(const XX &other) { if (debug) cout << "XX(const XX &)" << endl; }
XX& operator =(const XX &other) { if (debug) cout << "operator=(const XX &)" << endl; return *this; } XX& operator =(const XX &other) { if (debug) cout << "operator=(const XX &)" << endl; return *this; }
~XX() { if (debug) cout << "~XX()" << endl; } ~XX() { if (debug) cout << "~XX()" << endl; }
static XX create() {
// Note: best observed RVO for C#, Java and Python with g++-6 to g++-10 (just one constructor and one destructor call)
static XX create() {
return XX(123); return XX(123);
} }
static const XX createConst() {
return XX(456);
}
static bool debug; static bool debug;
}; };
bool XX::debug = true; bool XX::debug = true;

View file

@ -90,7 +90,8 @@
enum SWIGTYPE, SWIGTYPE *, enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;"; SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;";
#ifdef __cplusplus #ifdef __cplusplus
%typemap(out) SWIGTYPE "$result = new $1_type($1);"; %typemap(out) SWIGTYPE
%{ $result = new $1_ltype($1); %}
#else #else
%typemap(out) SWIGTYPE { %typemap(out) SWIGTYPE {
$result = ($&1_ltype) malloc(sizeof($1_type)); $result = ($&1_ltype) malloc(sizeof($1_type));

View file

@ -399,7 +399,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %} %{ $result = new $1_ltype($1); %}
#else #else
{ {
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));

View file

@ -52,7 +52,7 @@
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %} %{ $result = new $1_ltype($1); %}
#else #else
{ {
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));

View file

@ -130,7 +130,7 @@
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype((const $1_ltype &) $1); resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
} }
#else #else
@ -145,8 +145,7 @@
%typemap(varout) SWIGTYPE %typemap(varout) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr = ($&1_ltype)&$1;
resultptr = new $1_ltype((const $1_ltype&) $1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
} }
#else #else

View file

@ -665,7 +665,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
%{ *($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %} %{ *($&1_ltype*)&$result = new $1_ltype($1); %}
#else #else
{ {
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));

View file

@ -217,7 +217,7 @@ $1=($1_ltype)&temp;%}
#ifdef __cplusplus #ifdef __cplusplus
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
{ {
$&1_ltype resultptr = new $1_ltype((const $1_ltype &) $1); $&1_ltype resultptr = new $1_ltype($1);
SWIG_NewPointerObj(L,(void *) resultptr,$&1_descriptor,1); SWIG_arg++; SWIG_NewPointerObj(L,(void *) resultptr,$&1_descriptor,1); SWIG_arg++;
} }
#else #else

View file

@ -127,7 +127,7 @@
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1); resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
} }
#else #else

View file

@ -93,10 +93,14 @@
$1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ; $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
} }
%typemap(varout) SWIGTYPE {
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)&$1, $&1_descriptor);
}
#ifdef __cplusplus #ifdef __cplusplus
%typemap(out) SWIGTYPE { %typemap(out) SWIGTYPE {
$&1_ltype temp = new $ltype((const $1_ltype &) $1); $&1_ltype temp = new $1_ltype($1);
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)temp, $&1_descriptor); $result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)temp, $&1_descriptor);
} }
@ -110,6 +114,10 @@
#endif #endif
%typemap(varout) SWIGTYPE * {
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)$1, $1_descriptor);
}
%typemap(directorin) SWIGTYPE { %typemap(directorin) SWIGTYPE {
$&ltype temp = new $ltype((const $ltype &)$1); $&ltype temp = new $ltype((const $ltype &)$1);
swig_result = SWIG_Ocaml_ptr_to_val("create_$ltype_from_ptr", (void *)temp, $&1_descriptor); swig_result = SWIG_Ocaml_ptr_to_val("create_$ltype_from_ptr", (void *)temp, $&1_descriptor);

View file

@ -83,9 +83,18 @@ class wstring;
$result = caml_val_string_len($1.c_str(),$1.size()); $result = caml_val_string_len($1.c_str(),$1.size());
} }
%typemap(varout) string {
$result = caml_val_string_len($1.c_str(),$1.size());
}
%typemap(out) string * { %typemap(out) string * {
$result = caml_val_string_len((*$1).c_str(),(*$1).size()); $result = caml_val_string_len((*$1).c_str(),(*$1).size());
} }
%typemap(varout) string * {
$result = caml_val_string_len((*$1).c_str(),(*$1).size());
}
%typemap(typecheck) string, const string & = char *; %typemap(typecheck) string, const string & = char *;
} }

View file

@ -443,7 +443,7 @@
%typemap(out, phptype="SWIGTYPE") SWIGTYPE %typemap(out, phptype="SWIGTYPE") SWIGTYPE
{ {
#ifdef __cplusplus #ifdef __cplusplus
$&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); $&1_ltype resultobj = new $1_ltype($1);
#else #else
$&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type)); $&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type));
memcpy(resultobj, &$1, sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type));

View file

@ -180,17 +180,14 @@
// Redefine std::set iterator/reverse_iterator typemap // Redefine std::set iterator/reverse_iterator typemap
%typemap(out,noblock=1) iterator, reverse_iterator { %typemap(out,noblock=1) iterator, reverse_iterator {
$result = SWIG_NewPointerObj(swig::make_set_nonconst_iterator(%static_cast($1,const $type &), $result = SWIG_NewPointerObj((swig::make_set_nonconst_iterator<$type>($1, self)), swig::Iterator::descriptor(), SWIG_POINTER_OWN);
self),
swig::Iterator::descriptor(),SWIG_POINTER_OWN);
} }
// Redefine std::set std::pair<iterator, bool> typemap // Redefine std::set std::pair<iterator, bool> typemap
%typemap(out,noblock=1,fragment="RubyPairBoolOutputIterator") %typemap(out,noblock=1,fragment="RubyPairBoolOutputIterator")
std::pair<iterator, bool> { std::pair<iterator, bool> {
$result = rb_ary_new2(2); $result = rb_ary_new2(2);
rb_ary_push($result, SWIG_NewPointerObj(swig::make_set_nonconst_iterator(%static_cast($1,$type &).first), rb_ary_push($result, SWIG_NewPointerObj((swig::make_set_nonconst_iterator($1.first)), swig::Iterator::descriptor(), SWIG_POINTER_OWN));
swig::Iterator::descriptor(),SWIG_POINTER_OWN));
rb_ary_push($result, SWIG_From(bool)(%static_cast($1,const $type &).second)); rb_ary_push($result, SWIG_From(bool)(%static_cast($1,const $type &).second));
} }

View file

@ -677,10 +677,12 @@ template<typename T> class SwigValueWrapper {
public: public:
SwigValueWrapper() : pointer(0) { } SwigValueWrapper() : pointer(0) { }
SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; } SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; }
#if __cplusplus >= 201103L #if __cplusplus >=201103L
SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; } SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
#endif operator T&&() const { return std::move(*pointer.ptr); }
#else
operator T&() const { return *pointer.ptr; } operator T&() const { return *pointer.ptr; }
#endif
T *operator&() { return pointer.ptr; } T *operator&() { return pointer.ptr; }
};%} };%}

View file

@ -146,9 +146,15 @@
} }
/* Return by value */ /* Return by value */
#ifdef __cplusplus
%typemap(out, noblock=1) SWIGTYPE { %typemap(out, noblock=1) SWIGTYPE {
%set_output(SWIG_NewPointerObj(%new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags)); %set_output(SWIG_NewPointerObj((new $1_ltype($1)), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
} }
#else
%typemap(out, noblock=1) SWIGTYPE {
%set_output(SWIG_NewPointerObj(%new_copy($1, $1_ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
}
#endif
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* --- Variable input --- * --- Variable input ---
@ -534,7 +540,7 @@
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%typemap(throws,noblock=1) SWIGTYPE { %typemap(throws,noblock=1) SWIGTYPE {
%raise(SWIG_NewPointerObj(%new_copy($1, $ltype),$&descriptor,SWIG_POINTER_OWN), "$type", $&descriptor); %raise(SWIG_NewPointerObj(%new_copy($1, $1_ltype),$&descriptor,SWIG_POINTER_OWN), "$type", $&descriptor);
} }
%typemap(throws,noblock=1) SWIGTYPE * { %typemap(throws,noblock=1) SWIGTYPE * {
@ -703,9 +709,15 @@
/* INSTANCE typemap */ /* INSTANCE typemap */
#ifdef __cplusplus
%typemap(out,noblock=1) SWIGTYPE INSTANCE {
%set_output(SWIG_NewInstanceObj((new $1_ltype($1)), $&1_descriptor, SWIG_POINTER_OWN | %newinstance_flags));
}
#else
%typemap(out,noblock=1) SWIGTYPE INSTANCE { %typemap(out,noblock=1) SWIGTYPE INSTANCE {
%set_output(SWIG_NewInstanceObj(%new_copy($1, $1_ltype), $&1_descriptor, SWIG_POINTER_OWN | %newinstance_flags)); %set_output(SWIG_NewInstanceObj(%new_copy($1, $1_ltype), $&1_descriptor, SWIG_POINTER_OWN | %newinstance_flags));
} }
#endif
%typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[] { %typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[] {
%set_output(SWIG_NewInstanceObj(%as_voidptr($1), $1_descriptor, $owner | %newinstance_flags)); %set_output(SWIG_NewInstanceObj(%as_voidptr($1), $1_descriptor, $owner | %newinstance_flags));