Add const std::unique_ptr & input typemaps

This commit is contained in:
William S Fulton 2024-03-06 21:29:37 +00:00
parent 846b40793e
commit 24a66e6125
33 changed files with 879 additions and 136 deletions

View File

@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.3.0 (in progress)
===========================
2024-02-06: wsfulton
Add support for std::unique_ptr & typemaps. Non-const inputs implement
move semantics from proxy class to C++ layer, otherwise const inputs
and all reference returns behave like any other lvalue reference to a class.
2024-02-02: wsfulton
[Javascript, MzScheme, Octave] Support NULL being passed into char* typemaps.

View File

@ -2103,6 +2103,8 @@ The type <tt>T</tt> must be non-primitive.
This macro should be used before any code declaring or using type <tt>T</tt>.
Ordering requirements for using this smart pointer macro are the same as the
equivalent <tt>%shared_ptr(T)</tt> macro covered in the previous section.
The ownership and move semantics described here can of course be modified if not suitable
by copying and customising the typemaps in the appropriate <tt>std_unique_ptr.i</tt> library file.
</p>
<H4><a name="Library_std_unique_ptr_by_value">12.4.6 unique_ptr passed by value</a></H4>
@ -2243,6 +2245,19 @@ void process(std::unique_ptr&lt;Klass&gt; &amp;);
</pre>
</div>
<p>
Passing const lvalue references into a function works much like passing any wrapped class.
The proxy class owning the underling C++ object continues to own the underying C++ object
after calling the function, the function cannot modify the <tt>std::unique_ptr</tt> or take ownership.
Example:
</p>
<div class="code">
<pre>
void use(const std::unique_ptr&lt;Klass&gt; &amp;);
</pre>
</div>
<p>
Move semantics are not provided when wrapping a C++ function that returns a <tt>std::unique_ptr</tt> by reference.
The target language proxy class wrapper that is returned does not own the underlying C++ object.
@ -2251,8 +2266,8 @@ This applies to all reference types, such as:
<div class="code">
<pre>
std::unique_ptr<Klass> &amp; LvalueRefReturn();
std::unique_ptr<Klass> &amp;&amp; RvalueRefReturn();
std::unique_ptr&lt;Klass&gt; &amp; LvalueRefReturn();
std::unique_ptr&lt;Klass&gt; &amp;&amp; RvalueRefReturn();
</pre>
</div>

View File

@ -5,6 +5,7 @@
%warnfilter(509, 516) overloadTest(Klass);
%warnfilter(509, 516) moveOverloadTest(Klass);
%warnfilter(509, 516) moveRefOverloadTest(Klass);
%warnfilter(509, 516) useRefOverloadTest(Klass);
%include "std_string.i"
%include "std_unique_ptr.i"
@ -86,6 +87,13 @@ std::string moveRefKlassUniquePtr(std::unique_ptr<Klass>& k) {
return s;
}
std::string useRefKlassUniquePtr(const std::unique_ptr<Klass>& k) {
// std::cout << "useRefKlassUniquePtr " << std::hex << (Klass*)k.get() << std::endl;
std::string s(k ? k->getLabel() : "null smart pointer");
// std::cout << "useRefKlassUniquePtr string: " << s << std::endl;
return s;
}
Klass *make_null() {
return nullptr;
}
@ -164,6 +172,18 @@ int moveRefOverloadTest(Klass k) {
return 2;
}
int useRefOverloadTest() {
return 0;
}
int useRefOverloadTest(const std::unique_ptr<Klass>& kover) {
return 1;
}
int useRefOverloadTest(Klass k) {
return 2;
}
%}
#endif

View File

@ -253,6 +253,43 @@ public class cpp11_std_unique_ptr_runme {
checkCount(0);
///// INPUT BY CONST LVALUE REF /////
// unique_ptr as input
using (Klass kin = new Klass("KlassInput")) {
checkCount(1);
string s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kin);
checkCount(1);
if (s != "KlassInput")
throw new ApplicationException("Incorrect string: " + s);
}
checkCount(0);
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
checkCount(1);
string s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kini);
checkCount(1);
if (s != "KlassInheritanceInput")
throw new ApplicationException("Incorrect string: " + s);
}
checkCount(0);
cpp11_std_unique_ptr.useRefKlassUniquePtr(null);
cpp11_std_unique_ptr.useRefKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// overloaded parameters
if (cpp11_std_unique_ptr.useRefOverloadTest() != 0)
throw new ApplicationException("useRefOverloadTest failed");
if (cpp11_std_unique_ptr.useRefOverloadTest(null) != 1)
throw new ApplicationException("useRefOverloadTest failed");
using (Klass kin = new KlassInheritance("OverloadInput")) {
if (cpp11_std_unique_ptr.useRefOverloadTest(kin) != 1)
throw new ApplicationException("useRefOverloadTest failed");
checkCount(1);
}
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() != "first")

View File

@ -260,6 +260,46 @@ void main() {
checkCount(0);
///// INPUT BY CONST LVALUE REF /////
// unique_ptr as input
{
scope Klass kin = new Klass("KlassInput");
checkCount(1);
string s = useRefKlassUniquePtr(kin);
checkCount(1);
if (s != "KlassInput")
throw new Exception("Incorrect string: " ~ s);
}
checkCount(0);
{
scope KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
checkCount(1);
string s = useRefKlassUniquePtr(kini);
checkCount(1);
if (s != "KlassInheritanceInput")
throw new Exception("Incorrect string: " ~ s);
}
checkCount(0);
useRefKlassUniquePtr(null);
useRefKlassUniquePtr(make_null());
checkCount(0);
// overloaded parameters
if (useRefOverloadTest() != 0)
throw new Exception("useRefOverloadTest failed");
if (useRefOverloadTest(null) != 1)
throw new Exception("useRefOverloadTest failed");
{
scope Klass kin = new Klass("over");
if (useRefOverloadTest(kin) != 1)
throw new Exception("useRefOverloadTest failed");
checkCount(1);
}
checkCount(0);
// unique_ptr as output
Klass k1 = makeKlassUniquePtr("first");
if (k1.getLabel() != "first")

View File

@ -290,6 +290,49 @@ public class cpp11_std_unique_ptr_runme {
checkCount(0);
///// INPUT BY CONST LVALUE REF /////
// unique_ptr as input
{
Klass kin = new Klass("KlassInput");
checkCount(1);
String s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kin);
checkCount(1);
if (!s.equals("KlassInput"))
throw new RuntimeException("Incorrect string: " + s);
kin.delete();
checkCount(0);
}
{
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
checkCount(1);
String s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kini);
checkCount(1);
if (!s.equals("KlassInheritanceInput"))
throw new RuntimeException("Incorrect string: " + s);
kini.delete();
checkCount(0);
}
cpp11_std_unique_ptr.useRefKlassUniquePtr(null);
cpp11_std_unique_ptr.useRefKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// overloaded parameters
if (cpp11_std_unique_ptr.useRefOverloadTest() != 0)
throw new RuntimeException("useRefOverloadTest failed");
if (cpp11_std_unique_ptr.useRefOverloadTest(null) != 1)
throw new RuntimeException("useRefOverloadTest failed");
{
Klass kin = new Klass("over");
if (cpp11_std_unique_ptr.useRefOverloadTest(kin) != 1)
throw new RuntimeException("useRefOverloadTest failed");
checkCount(1);
kin.delete();
}
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (!k1.getLabel().equals("first"))

View File

@ -275,6 +275,53 @@ if (cpp11_std_unique_ptr.moveRefOverloadTest(new cpp11_std_unique_ptr.Klass("ove
checkCount(0);
///// INPUT BY CONST LVALUE REF /////
// unique_ptr as input
{
kin = new cpp11_std_unique_ptr.Klass("KlassInput");
checkCount(1);
s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kin);
checkCount(1);
if (s !== "KlassInput")
throw new Error("Incorrect string: " + s);
// delete kin;
// Above not deleting the C++ object(node v12) - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
checkCount(0);
}
{
kini = new cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput");
checkCount(1);
s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kini);
checkCount(1);
if (s !== "KlassInheritanceInput")
throw new Error("Incorrect string: " + s);
// delete kini;
// Above not deleting the C++ object - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(kini);
checkCount(0);
}
cpp11_std_unique_ptr.useRefKlassUniquePtr(null);
cpp11_std_unique_ptr.useRefKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// overloaded parameters
if (cpp11_std_unique_ptr.useRefOverloadTest() != 0)
throw new RuntimeException("useRefOverloadTest failed");
if (cpp11_std_unique_ptr.useRefOverloadTest(null) != 1)
throw new RuntimeException("useRefOverloadTest failed");
kin = new cpp11_std_unique_ptr.Klass("over")
if (cpp11_std_unique_ptr.useRefOverloadTest(kin) != 1)
throw new RuntimeException("useRefOverloadTest failed");
checkCount(1);
// delete kin;
// Above not deleting the C++ object - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(kin);
checkCount(0);
// unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() !== "first")

View File

@ -233,6 +233,48 @@ end
checkCount(0)
--- ---- INPUT BY CONST LVALUE REF ---
-- unique_ptr as input
kin = cpp11_std_unique_ptr.Klass("KlassInput")
checkCount(1)
s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kin)
checkCount(1)
if not (s == "KlassInput") then
error("Incorrect string: "..s)
end
kin = nil
checkCount(0)
kini = cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = cpp11_std_unique_ptr.useRefKlassUniquePtr(kini)
checkCount(1)
if not (s == "KlassInheritanceInput") then
error("Incorrect string: "..s)
end
kini = nil
checkCount(0)
cpp11_std_unique_ptr.useRefKlassUniquePtr(nil);
cpp11_std_unique_ptr.useRefKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
-- overloaded parameters
if not (cpp11_std_unique_ptr.useRefOverloadTest() == 0) then
error("useRefOverloadTest failed")
end
if not (cpp11_std_unique_ptr.useRefOverloadTest(nil) == 1) then
error("useRefOverloadTest failed")
end
kin = cpp11_std_unique_ptr.Klass("over")
if not (cpp11_std_unique_ptr.useRefOverloadTest(kin) == 1) then
error("useRefOverloadTest failed")
end
checkCount(1)
kin = nil
checkCount(0)
-- unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first")
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")

View File

@ -228,6 +228,44 @@
(checkCount 0)
; ;;;; INPUT BY CONST LVALUE REF ;;;;
; unique_ptr as input
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (useRefKlassUniquePtr kin))
(checkCount 1)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(set! kin '()) (gc)
(checkCount 0)
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (useRefKlassUniquePtr kini))
(checkCount 1)
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(set! kini '()) (gc)
(checkCount 0)
(define null '())
(useRefKlassUniquePtr null)
(useRefKlassUniquePtr (make-null))
(checkCount 0)
; overloaded parameters
(unless (= (useRefOverloadTest) 0)
(error "useRefOverloadTest failed"))
(unless (= (useRefOverloadTest null) 1)
(error "useRefOverloadTest failed"))
(define kin (new-Klass "over"))
(unless (= (useRefOverloadTest kin) 1)
(error "useRefOverloadTest failed"))
(checkCount 1)
(set! kin '()) (gc)
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))

View File

@ -296,6 +296,51 @@ endif
checkCount(0);
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
kin = Klass("KlassInput");
checkCount(1);
s = useRefKlassUniquePtr(kin);
checkCount(1);
if (!strcmp(s, "KlassInput"))
error("Incorrect string: %s", s);
endif
clear kin;
checkCount(0);
kini = KlassInheritance("KlassInheritanceInput");
checkCount(1);
s = useRefKlassUniquePtr(kini);
checkCount(1);
if (!strcmp(s, "KlassInheritanceInput"))
error("Incorrect string: %s", s);
endif
clear kini;
checkCount(0);
null = []; # NULL pointer
null_ptr = make_null();
useRefKlassUniquePtr([]);
useRefKlassUniquePtr(null);
useRefKlassUniquePtr(null_ptr);
checkCount(0);
# overloaded parameters
if (useRefOverloadTest() != 0)
error("useRefOverloadTest failed");
endif
if (useRefOverloadTest(null) != 1)
error("useRefOverloadTest failed");
endif
kin = Klass("over");
if (useRefOverloadTest(kin) != 1)
error("useRefOverloadTest failed");
endif
checkCount(1);
clear kin
checkCount(0);
# unique_ptr as output
k1 = makeKlassUniquePtr("first");
if (!strcmp(k1.getLabel(), "first"))

View File

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 86;
use Test::More tests => 100;
BEGIN { use_ok('cpp11_std_unique_ptr') }
require_ok('cpp11_std_unique_ptr');
@ -209,6 +209,42 @@ is(cpp11_std_unique_ptr::moveRefOverloadTest(new cpp11_std_unique_ptr::Klass("ov
checkCount(0);
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
{
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
checkCount(1);
my $s = cpp11_std_unique_ptr::useRefKlassUniquePtr($kin);
checkCount(1);
is($s, "KlassInput", "Incorrect string: $s");
undef $kin;
checkCount(0);
}
{
my $kini = new cpp11_std_unique_ptr::KlassInheritance("KlassInheritanceInput");
checkCount(1);
my $s = cpp11_std_unique_ptr::useRefKlassUniquePtr($kini);
checkCount(1);
is($s, "KlassInheritanceInput", "Incorrect string: $s");
undef $kini;
checkCount(0);
}
cpp11_std_unique_ptr::useRefKlassUniquePtr(undef);
cpp11_std_unique_ptr::useRefKlassUniquePtr(cpp11_std_unique_ptr::make_null());
checkCount(0);
# overloaded parameters
is(cpp11_std_unique_ptr::useRefOverloadTest(), 0, "useRefOverloadTest failed");
is(cpp11_std_unique_ptr::useRefOverloadTest(undef), 1, "useRefOverloadTest failed");
my $kin = new cpp11_std_unique_ptr::Klass("over");
is(cpp11_std_unique_ptr::useRefOverloadTest($kin), 1, "useRefOverloadTest failed");
checkCount(1);
undef $kin;
checkCount(0);
# unique_ptr as output
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");

View File

@ -241,6 +241,38 @@ check::equal(moveRefOverloadTest(new Klass("over")), 1, "moveRefOverloadTest fai
checkCount(0);
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
$kin = new Klass("KlassInput");
checkCount(1);
$s = useRefKlassUniquePtr($kin);
checkCount(1);
check::equal($s, "KlassInput", "Incorrect string: $s");
$kin = NULL;
checkCount(0);
$kini = new KlassInheritance("KlassInheritanceInput");
checkCount(1);
$s = useRefKlassUniquePtr($kini);
checkCount(1);
check::equal($s, "KlassInheritanceInput", "Incorrect string: $s");
$kini = NULL;
checkCount(0);
useRefKlassUniquePtr(NULL);
useRefKlassUniquePtr(make_null());
checkCount(0);
# overloaded parameters
check::equal(useRefOverloadTest(), 0, "useRefOverloadTest failed");
check::equal(useRefOverloadTest(NULL), 1, "useRefOverloadTest failed");
$kin = new Klass("over");
check::equal(useRefOverloadTest($kin), 1, "useRefOverloadTest failed");
checkCount(1);
$kin = NULL;
checkCount(0);
# unique_ptr as output
$k1 = makeKlassUniquePtr("first");
$k2 = makeKlassUniquePtr("second");

View File

@ -3,7 +3,7 @@ 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)
raise RuntimeError("Counts incorrect, expected: {} actual:{}".format(expected_count, actual_count))
# Test raw pointer handling involving virtual inheritance
kini = KlassInheritance("KlassInheritanceInput")
@ -45,7 +45,7 @@ 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");
raise RuntimeError("incorrect exception message")
exception_thrown = True
if not exception_thrown:
raise RuntimeError("double usage of takeKlassUniquePtr should have been an error")
@ -89,7 +89,7 @@ if overloadTest(None) != 1:
raise RuntimeError("overloadTest failed")
if overloadTest(Klass("over")) != 1:
raise RuntimeError("overloadTest failed")
checkCount(0);
checkCount(0)
# #### INPUT BY RVALUE REF ####
@ -122,7 +122,7 @@ try:
s = moveKlassUniquePtr(kin)
except RuntimeError as e:
if "cannot release ownership as memory is not owned" not in str(e):
raise RuntimeError("incorrect exception message");
raise RuntimeError("incorrect exception message")
exception_thrown = True
if not exception_thrown:
raise RuntimeError("double usage of moveKlassUniquePtr should have been an error")
@ -166,7 +166,7 @@ if moveOverloadTest(None) != 1:
raise RuntimeError("moveOverloadTest failed")
if moveOverloadTest(Klass("over")) != 1:
raise RuntimeError("moveOverloadTest failed")
checkCount(0);
checkCount(0)
# #### INPUT BY NON-CONST LVALUE REF ####
@ -199,7 +199,7 @@ try:
s = moveRefKlassUniquePtr(kin)
except RuntimeError as e:
if "cannot release ownership as memory is not owned" not in str(e):
raise RuntimeError("incorrect exception message");
raise RuntimeError("incorrect exception message")
exception_thrown = True
if not exception_thrown:
raise RuntimeError("double usage of moveRefKlassUniquePtr should have been an error")
@ -243,7 +243,44 @@ if moveRefOverloadTest(None) != 1:
raise RuntimeError("moveRefOverloadTest failed")
if moveRefOverloadTest(Klass("over")) != 1:
raise RuntimeError("moveRefOverloadTest failed")
checkCount(0);
checkCount(0)
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
kin = Klass("KlassInput")
checkCount(1)
s = useRefKlassUniquePtr(kin)
checkCount(1)
if s != "KlassInput":
raise RuntimeError("Incorrect string: " + s)
del kin
checkCount(0)
kini = KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = useRefKlassUniquePtr(kini)
checkCount(1)
if s != "KlassInheritanceInput":
raise RuntimeError("Incorrect string: " + s)
del kini
checkCount(0)
useRefKlassUniquePtr(None)
useRefKlassUniquePtr(make_null())
checkCount(0)
# overloaded parameters
if useRefOverloadTest() != 0:
raise RuntimeError("useRefOverloadTest failed")
if useRefOverloadTest(None) != 1:
raise RuntimeError("useRefOverloadTest failed")
kin = Klass("over")
if useRefOverloadTest(kin) != 1:
raise RuntimeError("useRefOverloadTest failed")
checkCount(1)
del kin
checkCount(0)
# unique_ptr as output

View File

@ -3,7 +3,7 @@ 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)
raise RuntimeError("Counts incorrect, expected: {} actual:{}".format(expected_count, actual_count))
# Test raw pointer handling involving virtual inheritance
kini = KlassInheritance("KlassInheritanceInput")

View File

@ -14,7 +14,7 @@ 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
raise RuntimeError, "Counts incorrect, expected:#{expected_count} actual:#{actual_count}"
end
end
@ -131,7 +131,7 @@ end
if (Cpp11_std_unique_ptr::overloadTest(Cpp11_std_unique_ptr::Klass.new("over")) != 1)
raise RuntimeError, "overloadTest failed"
end
checkCount(0);
checkCount(0)
# #### INPUT BY RVALUE REF ####
@ -235,7 +235,7 @@ end
if (Cpp11_std_unique_ptr::moveOverloadTest(Cpp11_std_unique_ptr::Klass.new("over")) != 1)
raise RuntimeError, "moveOverloadTest failed"
end
checkCount(0);
checkCount(0)
# #### INPUT BY NON-CONST LVALUE REF ####
@ -339,7 +339,52 @@ end
if (Cpp11_std_unique_ptr::moveRefOverloadTest(Cpp11_std_unique_ptr::Klass.new("over")) != 1)
raise RuntimeError, "moveRefOverloadTest failed"
end
checkCount(0);
checkCount(0)
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
checkCount(1)
s = Cpp11_std_unique_ptr.useRefKlassUniquePtr(kin)
checkCount(1)
if (s != "KlassInput")
raise RuntimeError, "Incorrect string: " + s
end
# kin = nil
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.useRefKlassUniquePtr(kini)
checkCount(1)
if (s != "KlassInheritanceInput")
raise RuntimeError, "Incorrect string: " + s
end
# kini = nil
Cpp11_std_unique_ptr.takeKlassUniquePtr(kini) # Ensure object is deleted (can't rely on GC)
checkCount(0)
Cpp11_std_unique_ptr::useRefKlassUniquePtr(nil)
Cpp11_std_unique_ptr::useRefKlassUniquePtr(Cpp11_std_unique_ptr::make_null())
checkCount(0)
# overloaded parameters
if (Cpp11_std_unique_ptr::useRefOverloadTest() != 0)
raise RuntimeError, "useRefOverloadTest failed"
end
if (Cpp11_std_unique_ptr::useRefOverloadTest(nil) != 1)
raise RuntimeError, "useRefOverloadTest failed"
end
kin = Cpp11_std_unique_ptr::Klass.new("over")
if (Cpp11_std_unique_ptr::useRefOverloadTest(kin) != 1)
raise RuntimeError, "useRefOverloadTest failed"
end
checkCount(1)
# kin = nil
Cpp11_std_unique_ptr.takeKlassUniquePtr(kin) # Ensure object is deleted (can't rely on GC)
checkCount(0)
# unique_ptr as output

View File

@ -14,7 +14,7 @@ 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
raise RuntimeError, "Counts incorrect, expected:#{expected_count} actual:#{actual_count}"
end
end

View File

@ -328,6 +328,48 @@ if {[moveRefOverloadTest [Klass k "over"]] != 1} {
checkCount 0
# #### INPUT BY CONST LVALUE REF ####
# unique_ptr as input
Klass kin "KlassInput"
checkCount 1
set s [useRefKlassUniquePtr kin]
checkCount 1
if {$s != "KlassInput"} {
error "Incorrect string: $s"
}
kin -delete
checkCount 0
KlassInheritance kini "KlassInheritanceInput"
checkCount 1
set s [useRefKlassUniquePtr kini]
checkCount 1
if {$s != "KlassInheritanceInput"} {
error "Incorrect string: $s"
}
kini -delete
checkCount 0
useRefKlassUniquePtr "NULL"
useRefKlassUniquePtr [make_null]
checkCount 0
# overloaded parameters
if {[useRefOverloadTest] != 0} {
error "useRefOverloadTest failed"
}
if {[useRefOverloadTest "NULL"] != 1} {
error "useRefOverloadTest failed"
}
Klass kin "over"
if {[useRefOverloadTest kin] != 1} {
error "useRefOverloadTest failed"
}
checkCount 1
kin -delete
checkCount 0
# unique_ptr as output
set k1 [makeKlassUniquePtr "first"]
set k2 [makeKlassUniquePtr "second"]

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap (ctype) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "void *"
%typemap (imtype, out="System.IntPtr") std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "global::System.Runtime.InteropServices.HandleRef"
@ -18,8 +27,12 @@
%typemap(in) std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > &&
%{ $*1_ltype $1_uptr((TYPE *)$input);
$1 = &$1_uptr; %}
%typemap(in, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > &
%{ swig::NoDeleteUniquePtr< TYPE > $1_ndup((TYPE *)$input);
$1 = &$1_ndup.uptr; %}
%typemap(csin) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "$typemap(cstype, TYPE).swigRelease($csinput)"
%typemap(csin) const std::unique_ptr< TYPE > & "$typemap(cstype, TYPE).getCPtr($csinput)"
%typemap (out) std::unique_ptr< TYPE > %{
$result = (void *)$1.release();
@ -45,7 +58,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap (ctype) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "void *"
%typemap (imtype) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "void*"
@ -18,10 +27,17 @@
%typemap(in) std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > &&
%{ $*1_ltype $1_uptr((TYPE *)$input);
$1 = &$1_uptr; %}
%typemap(in, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > &
%{ swig::NoDeleteUniquePtr< TYPE > $1_ndup((TYPE *)$input);
$1 = &$1_ndup.uptr; %}
%typemap(din,
nativepointer="cast(void*)$dinput"
) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "$typemap(dtype, TYPE).swigRelease($dinput)"
%typemap(din,
nativepointer="cast(void*)$dinput"
) const std::unique_ptr< TYPE > & "$typemap(dtype, TYPE).swigGetCPtr($dinput)"
%typemap (out) std::unique_ptr< TYPE > %{
$result = (void *)$1.release();
@ -51,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
@ -33,6 +42,14 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
@ -49,7 +66,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap (jni) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "jlong"
@ -20,8 +29,12 @@
%typemap(in) std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > &&
%{ $*1_ltype $1_uptr((TYPE *)$input);
$1 = &$1_uptr; %}
%typemap(in, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > &
%{ swig::NoDeleteUniquePtr< TYPE > $1_ndup((TYPE *)$input);
$1 = &$1_ndup.uptr; %}
%typemap(javain) std::unique_ptr< TYPE >, std::unique_ptr< TYPE > &, std::unique_ptr< TYPE > && "$typemap(jstype, TYPE).swigRelease($javainput)"
%typemap(javain) const std::unique_ptr< TYPE > & "$typemap(jstype, TYPE).getCPtr($javainput)"
%typemap (out) std::unique_ptr< TYPE > %{
jlong lpp = 0;
@ -48,7 +61,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, checkfn="SWIG_isptrtype", noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, checkfn="SWIG_isptrtype", noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
SWIG_fail_ptr("$symname", $argnum, $descriptor(TYPE *));
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
SWIG_NewPointerObj(L, $1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN); SWIG_arg++;
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
@ -38,6 +47,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
zend_type_error("Expected $descriptor(TYPE *) for argument $argnum of $symname");
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
SWIG_SetPointerZval($result, (void *)$1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN);
%}
@ -53,7 +71,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View File

@ -2,12 +2,21 @@
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
*
* Returning a std::unique_ptr from a wrapped function:
* Memory ownership is passed (moved) from the std::unique_ptr in the C++ layer
* to the proxy class when returning a std::unique_ptr by value from a function.
* Memory ownership is not moved when returning by any sort of reference.
*
* Passing a std::unique_ptr as a parameter to a wrapped function:
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter by value, rvalue reference or non-const
* lvalue reference. Memory ownership is not transferred when passing by const
* lvalue reference.
* ----------------------------------------------------------------------------- */
%include <unique_ptr.swg>
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
@ -34,6 +43,15 @@
$1 = &uptr;
}
%typemap(in, noblock=1, fragment="SwigNoDeleteUniquePtr") const std::unique_ptr< TYPE > & (void *argp = 0, int res = 0, swig::NoDeleteUniquePtr< TYPE > ndup) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), 0);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
ndup.uptr.reset((TYPE *)argp);
$1 = &ndup.uptr;
}
%typemap (out) std::unique_ptr< TYPE > %{
Tcl_SetObjResult(interp, SWIG_NewInstanceObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
@ -49,7 +67,3 @@
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

22
Lib/unique_ptr.swg Normal file
View File

@ -0,0 +1,22 @@
/* -----------------------------------------------------------------------------
* unique_ptr.swg
*
* Common std::unique_ptr support.
* Not for direct inclusion.
* ----------------------------------------------------------------------------- */
%fragment("SwigNoDeleteUniquePtr", "header", fragment="<memory>") {
namespace swig {
template<typename T>
struct NoDeleteUniquePtr {
std::unique_ptr<T> uptr;
NoDeleteUniquePtr(T *p = 0) : uptr(p) {}
~NoDeleteUniquePtr() {uptr.release();}
};
}
}
namespace std {
template <class T> class unique_ptr {};
}