From 24a66e6125699499f4c6b7bf15df629e0655f0b7 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 6 Mar 2024 21:29:37 +0000
Subject: [PATCH] Add const std::unique_ptr & input typemaps
---
CHANGES.current | 5 ++
Doc/Manual/Library.html | 19 ++++++-
Examples/test-suite/cpp11_std_unique_ptr.i | 20 +++++++
.../csharp/cpp11_std_unique_ptr_runme.cs | 37 +++++++++++++
.../d/cpp11_std_unique_ptr_runme.2.d | 40 ++++++++++++++
.../java/cpp11_std_unique_ptr_runme.java | 43 +++++++++++++++
.../javascript/cpp11_std_unique_ptr_runme.js | 47 ++++++++++++++++
.../lua/cpp11_std_unique_ptr_runme.lua | 42 +++++++++++++++
.../mzscheme/cpp11_std_unique_ptr_runme.scm | 38 +++++++++++++
.../octave/cpp11_std_unique_ptr_runme.m | 45 ++++++++++++++++
.../perl5/cpp11_std_unique_ptr_runme.pl | 38 ++++++++++++-
.../php/cpp11_std_unique_ptr_runme.php | 32 +++++++++++
.../python/cpp11_std_unique_ptr_runme.py | 51 +++++++++++++++---
.../python/li_std_auto_ptr_runme.py | 2 +-
.../ruby/cpp11_std_unique_ptr_runme.rb | 53 +++++++++++++++++--
.../test-suite/ruby/li_std_auto_ptr_runme.rb | 2 +-
.../tcl/cpp11_std_unique_ptr_runme.tcl | 42 +++++++++++++++
Lib/csharp/std_unique_ptr.i | 25 ++++++---
Lib/d/std_unique_ptr.i | 28 +++++++---
Lib/guile/std_unique_ptr.i | 29 +++++++---
Lib/java/std_unique_ptr.i | 25 ++++++---
Lib/javascript/jsc/std_unique_ptr.i | 30 ++++++++---
Lib/javascript/napi/std_unique_ptr.i | 30 ++++++++---
Lib/javascript/v8/std_unique_ptr.i | 30 ++++++++---
Lib/lua/std_unique_ptr.i | 30 ++++++++---
Lib/mzscheme/std_unique_ptr.i | 30 ++++++++---
Lib/octave/std_unique_ptr.i | 30 ++++++++---
Lib/perl5/std_unique_ptr.i | 30 ++++++++---
Lib/php/std_unique_ptr.i | 30 ++++++++---
Lib/python/std_unique_ptr.i | 30 ++++++++---
Lib/ruby/std_unique_ptr.i | 30 ++++++++---
Lib/tcl/std_unique_ptr.i | 30 ++++++++---
Lib/unique_ptr.swg | 22 ++++++++
33 files changed, 879 insertions(+), 136 deletions(-)
create mode 100644 Lib/unique_ptr.swg
diff --git a/CHANGES.current b/CHANGES.current
index ad2130d17..a78c5e15d 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -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.
diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html
index f4fbb97a4..8a8b18c8a 100644
--- a/Doc/Manual/Library.html
+++ b/Doc/Manual/Library.html
@@ -2103,6 +2103,8 @@ The type T must be non-primitive.
This macro should be used before any code declaring or using type T.
Ordering requirements for using this smart pointer macro are the same as the
equivalent %shared_ptr(T) 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 std_unique_ptr.i library file.
@@ -2243,6 +2245,19 @@ void process(std::unique_ptr<Klass> &);
+
+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 std::unique_ptr or take ownership.
+Example:
+
+
+
+
+void use(const std::unique_ptr<Klass> &);
+
+
+
Move semantics are not provided when wrapping a C++ function that returns a std::unique_ptr 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:
-std::unique_ptr & LvalueRefReturn();
-std::unique_ptr && RvalueRefReturn();
+std::unique_ptr<Klass> & LvalueRefReturn();
+std::unique_ptr<Klass> && RvalueRefReturn();
diff --git a/Examples/test-suite/cpp11_std_unique_ptr.i b/Examples/test-suite/cpp11_std_unique_ptr.i
index fdd4dbabd..34b98925c 100644
--- a/Examples/test-suite/cpp11_std_unique_ptr.i
+++ b/Examples/test-suite/cpp11_std_unique_ptr.i
@@ -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& k) {
return s;
}
+std::string useRefKlassUniquePtr(const std::unique_ptr& 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& kover) {
+ return 1;
+}
+
+int useRefOverloadTest(Klass k) {
+ return 2;
+}
+
%}
#endif
diff --git a/Examples/test-suite/csharp/cpp11_std_unique_ptr_runme.cs b/Examples/test-suite/csharp/cpp11_std_unique_ptr_runme.cs
index 6e40dfa4a..6918bfba2 100644
--- a/Examples/test-suite/csharp/cpp11_std_unique_ptr_runme.cs
+++ b/Examples/test-suite/csharp/cpp11_std_unique_ptr_runme.cs
@@ -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")
diff --git a/Examples/test-suite/d/cpp11_std_unique_ptr_runme.2.d b/Examples/test-suite/d/cpp11_std_unique_ptr_runme.2.d
index a2afc360f..0faed9d2c 100644
--- a/Examples/test-suite/d/cpp11_std_unique_ptr_runme.2.d
+++ b/Examples/test-suite/d/cpp11_std_unique_ptr_runme.2.d
@@ -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")
diff --git a/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java b/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java
index 16d3e8877..fe3350026 100644
--- a/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java
+++ b/Examples/test-suite/java/cpp11_std_unique_ptr_runme.java
@@ -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"))
diff --git a/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js b/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js
index 833e73bac..bdd9cd4f3 100644
--- a/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js
+++ b/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js
@@ -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")
diff --git a/Examples/test-suite/lua/cpp11_std_unique_ptr_runme.lua b/Examples/test-suite/lua/cpp11_std_unique_ptr_runme.lua
index e8f4c8f2c..a55d85117 100644
--- a/Examples/test-suite/lua/cpp11_std_unique_ptr_runme.lua
+++ b/Examples/test-suite/lua/cpp11_std_unique_ptr_runme.lua
@@ -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")
diff --git a/Examples/test-suite/mzscheme/cpp11_std_unique_ptr_runme.scm b/Examples/test-suite/mzscheme/cpp11_std_unique_ptr_runme.scm
index 2e3b630d3..d6276a5f8 100644
--- a/Examples/test-suite/mzscheme/cpp11_std_unique_ptr_runme.scm
+++ b/Examples/test-suite/mzscheme/cpp11_std_unique_ptr_runme.scm
@@ -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"))
diff --git a/Examples/test-suite/octave/cpp11_std_unique_ptr_runme.m b/Examples/test-suite/octave/cpp11_std_unique_ptr_runme.m
index 6b608d955..8b3902c3f 100644
--- a/Examples/test-suite/octave/cpp11_std_unique_ptr_runme.m
+++ b/Examples/test-suite/octave/cpp11_std_unique_ptr_runme.m
@@ -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"))
diff --git a/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl b/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl
index 67d2fd3af..33453095c 100644
--- a/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl
+++ b/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl
@@ -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");
diff --git a/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php b/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php
index 4c9b9638f..d7f6caf06 100644
--- a/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php
+++ b/Examples/test-suite/php/cpp11_std_unique_ptr_runme.php
@@ -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");
diff --git a/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py b/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py
index 29a378ac7..6f01bc83b 100644
--- a/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py
+++ b/Examples/test-suite/python/cpp11_std_unique_ptr_runme.py
@@ -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
diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py
index dd8893f40..e2bbc557f 100644
--- a/Examples/test-suite/python/li_std_auto_ptr_runme.py
+++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py
@@ -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")
diff --git a/Examples/test-suite/ruby/cpp11_std_unique_ptr_runme.rb b/Examples/test-suite/ruby/cpp11_std_unique_ptr_runme.rb
index b0179adbb..114a4c4f2 100644
--- a/Examples/test-suite/ruby/cpp11_std_unique_ptr_runme.rb
+++ b/Examples/test-suite/ruby/cpp11_std_unique_ptr_runme.rb
@@ -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
diff --git a/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb b/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb
index 48276a888..e10737023 100644
--- a/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb
+++ b/Examples/test-suite/ruby/li_std_auto_ptr_runme.rb
@@ -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
diff --git a/Examples/test-suite/tcl/cpp11_std_unique_ptr_runme.tcl b/Examples/test-suite/tcl/cpp11_std_unique_ptr_runme.tcl
index 92f0fb4b4..dd6b7bd8d 100644
--- a/Examples/test-suite/tcl/cpp11_std_unique_ptr_runme.tcl
+++ b/Examples/test-suite/tcl/cpp11_std_unique_ptr_runme.tcl
@@ -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"]
diff --git a/Lib/csharp/std_unique_ptr.i b/Lib/csharp/std_unique_ptr.i
index 455d14a62..d264c1e7b 100644
--- a/Lib/csharp/std_unique_ptr.i
+++ b/Lib/csharp/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/d/std_unique_ptr.i b/Lib/d/std_unique_ptr.i
index b927dff8a..47a264642 100644
--- a/Lib/d/std_unique_ptr.i
+++ b/Lib/d/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/guile/std_unique_ptr.i b/Lib/guile/std_unique_ptr.i
index 4a46ff39a..485f423ee 100644
--- a/Lib/guile/std_unique_ptr.i
+++ b/Lib/guile/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/java/std_unique_ptr.i b/Lib/java/std_unique_ptr.i
index c8093080b..ded7b80bb 100644
--- a/Lib/java/std_unique_ptr.i
+++ b/Lib/java/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/javascript/jsc/std_unique_ptr.i b/Lib/javascript/jsc/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/javascript/jsc/std_unique_ptr.i
+++ b/Lib/javascript/jsc/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/javascript/napi/std_unique_ptr.i b/Lib/javascript/napi/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/javascript/napi/std_unique_ptr.i
+++ b/Lib/javascript/napi/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/javascript/v8/std_unique_ptr.i b/Lib/javascript/v8/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/javascript/v8/std_unique_ptr.i
+++ b/Lib/javascript/v8/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/lua/std_unique_ptr.i b/Lib/lua/std_unique_ptr.i
index 2cc7bd66f..6d2ed1523 100644
--- a/Lib/lua/std_unique_ptr.i
+++ b/Lib/lua/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/mzscheme/std_unique_ptr.i b/Lib/mzscheme/std_unique_ptr.i
index 8b7ef449c..8263e607b 100644
--- a/Lib/mzscheme/std_unique_ptr.i
+++ b/Lib/mzscheme/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/octave/std_unique_ptr.i b/Lib/octave/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/octave/std_unique_ptr.i
+++ b/Lib/octave/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/perl5/std_unique_ptr.i b/Lib/perl5/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/perl5/std_unique_ptr.i
+++ b/Lib/perl5/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/php/std_unique_ptr.i b/Lib/php/std_unique_ptr.i
index 6a361b503..dc8db3364 100644
--- a/Lib/php/std_unique_ptr.i
+++ b/Lib/php/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/python/std_unique_ptr.i b/Lib/python/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/python/std_unique_ptr.i
+++ b/Lib/python/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/ruby/std_unique_ptr.i b/Lib/ruby/std_unique_ptr.i
index 9cc6d630e..e3669bb4a 100644
--- a/Lib/ruby/std_unique_ptr.i
+++ b/Lib/ruby/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/tcl/std_unique_ptr.i b/Lib/tcl/std_unique_ptr.i
index a60d32783..ed2141cfb 100644
--- a/Lib/tcl/std_unique_ptr.i
+++ b/Lib/tcl/std_unique_ptr.i
@@ -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
+
%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 unique_ptr {};
-}
diff --git a/Lib/unique_ptr.swg b/Lib/unique_ptr.swg
new file mode 100644
index 000000000..a35038314
--- /dev/null
+++ b/Lib/unique_ptr.swg
@@ -0,0 +1,22 @@
+/* -----------------------------------------------------------------------------
+ * unique_ptr.swg
+ *
+ * Common std::unique_ptr support.
+ * Not for direct inclusion.
+ * ----------------------------------------------------------------------------- */
+
+
+%fragment("SwigNoDeleteUniquePtr", "header", fragment="") {
+namespace swig {
+ template
+ struct NoDeleteUniquePtr {
+ std::unique_ptr uptr;
+ NoDeleteUniquePtr(T *p = 0) : uptr(p) {}
+ ~NoDeleteUniquePtr() {uptr.release();}
+ };
+}
+}
+
+namespace std {
+ template class unique_ptr {};
+}