Test/fixes to handle NULL pointer for unique_ptr/auto_ptr

Also add missing unique_ptr tests for Lua and Racket.
This commit is contained in:
William S Fulton 2022-08-31 08:35:55 +01:00
commit 7934561874
32 changed files with 434 additions and 6 deletions

View file

@ -63,7 +63,7 @@ std::string useKlassRawPtr(Klass* k) {
std::string takeKlassUniquePtr(std::unique_ptr<Klass> k) {
// std::cout << "takeKlassUniquePtr " << std::hex << (Klass*)k.get() << std::endl;
std::string s(k->getLabel());
std::string s(k ? k->getLabel() : "null smart pointer");
// std::cout << "takeKlassUniquePtr string: " << s << std::endl;
return s;
}
@ -84,6 +84,10 @@ std::unique_ptr<Klass> makeKlassUniquePtr(const char* label) {
return std::unique_ptr<Klass>(new Klass(label));
}
std::unique_ptr<Klass> makeNullUniquePtr() {
return std::unique_ptr<Klass>();
}
%}
#endif

View file

@ -87,6 +87,11 @@ public class cpp11_std_unique_ptr_runme {
} // Dispose should not fail, even though already deleted
checkCount(0);
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -110,5 +115,8 @@ public class cpp11_std_unique_ptr_runme {
k2.Dispose();
k2 = null;
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new Exception("null failure");
}
}

View file

@ -87,6 +87,11 @@ public class li_std_auto_ptr_runme {
} // Dispose should not fail, even though already deleted
checkCount(0);
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -110,5 +115,8 @@ public class li_std_auto_ptr_runme {
k2.Dispose();
k2 = null;
checkCount(0);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new Exception("null failure");
}
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(null);
takeKlassUniquePtr(make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullUniquePtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(null);
takeKlassUniquePtr(make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = makeKlassUniquePtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullUniquePtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(null);
takeKlassAutoPtr(make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullAutoPtr() !is null)
throw new Exception("null failure");
}

View file

@ -87,6 +87,11 @@ void main() {
} // dispose should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(null);
takeKlassAutoPtr(make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = makeKlassAutoPtr("first");
if (k1.getLabel() != "first")
@ -103,4 +108,7 @@ void main() {
k2.dispose();
checkCount(0);
if (makeNullAutoPtr() !is null)
throw new Exception("null failure");
}

View file

@ -107,6 +107,11 @@ public class cpp11_std_unique_ptr_runme {
checkCount(0);
}
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
Klass k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (!k1.getLabel().equals("first"))
@ -125,5 +130,8 @@ public class cpp11_std_unique_ptr_runme {
k2.delete();
k2 = null;
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new RuntimeException("null failure");
}
}

View file

@ -107,6 +107,11 @@ public class li_std_auto_ptr_runme {
checkCount(0);
}
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (!k1.getLabel().equals("first"))
@ -125,5 +130,8 @@ public class li_std_auto_ptr_runme {
k2.delete();
k2 = null;
checkCount(0);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new RuntimeException("null failure");
}
}

View file

@ -90,6 +90,11 @@ var checkCount = function(expected_count) {
checkCount(0);
}
cpp11_std_unique_ptr.takeKlassUniquePtr(null);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
// unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first");
if (k1.getLabel() !== "first")
@ -110,3 +115,6 @@ if (k2.getLabel() !== "second")
// Above not deleting the C++ object(node v12) - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(k2);
checkCount(0);
if (cpp11_std_unique_ptr.makeNullUniquePtr() != null)
throw new Error("null failure");

View file

@ -90,6 +90,11 @@ var checkCount = function(expected_count) {
checkCount(0);
}
li_std_auto_ptr.takeKlassAutoPtr(null);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
// auto_ptr as output
k1 = li_std_auto_ptr.makeKlassAutoPtr("first");
if (k1.getLabel() !== "first")
@ -109,4 +114,8 @@ if (k2.getLabel() !== "second")
// delete k2;
// Above not deleting the C++ object(node v12) - can't reliably control GC
li_std_auto_ptr.takeKlassAutoPtr(k2);
if (li_std_auto_ptr.makeNullAutoPtr() != null)
throw new Error("null failure");
checkCount(0);

View file

@ -110,11 +110,14 @@ std::string useKlassRawPtr(Klass* k) {
std::string takeKlassAutoPtr(std::auto_ptr<Klass> k) {
// std::cout << "takeKlassAutoPtr " << std::hex << (Klass*)k.get() << std::endl;
std::string s(k->getLabel());
std::string s(k.get() ? k->getLabel() : "null smart pointer");
// std::cout << "takeKlassAutoPtr string: " << s << std::endl;
return s;
}
Klass *make_null() {
return 0;
}
bool is_nullptr(Klass *p) {
return p == 0;
@ -128,6 +131,10 @@ std::auto_ptr<Klass> makeKlassAutoPtr(const char* label) {
return std::auto_ptr<Klass>(new Klass(label));
}
std::auto_ptr<Klass> makeNullAutoPtr() {
return std::auto_ptr<Klass>();
}
%}
#endif

View file

@ -0,0 +1,100 @@
require("import") -- the import fn
import("cpp11_std_unique_ptr") -- import code
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
function checkCount(expected_count)
-- call gc to make unused objects are collected
collectgarbage()
actual_count = cpp11_std_unique_ptr.Klass.getTotal_count()
if not (actual_count == expected_count) then
error("Counts incorrect, expected:"..expected_count.." actual:"..actual_count)
end
end
--Test raw pointer handling involving virtual inheritance
kini = cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = cpp11_std_unique_ptr.useKlassRawPtr(kini)
if not (s == "KlassInheritanceInput") then
error("Incorrect string: "..s)
end
kini = nil
checkCount(0)
-- unique_ptr as input
kin = cpp11_std_unique_ptr.Klass("KlassInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
checkCount(0)
if not (s == "KlassInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kin)) then
error("is_nullptr failed")
end
kin = nil -- Should not fail, even though already deleted
checkCount(0)
kin = cpp11_std_unique_ptr.Klass("KlassInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin)
checkCount(0)
if not (s == "KlassInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kin)) then
error("is_nullptr failed")
end
s, msg = pcall(function() cpp11_std_unique_ptr.takeKlassUniquePtr(kin) end)
assert(s == false and msg == "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' in takeKlassUniquePtr")
kin = nil -- Should not fail, even though already deleted
checkCount(0)
kin = cpp11_std_unique_ptr.Klass("KlassInput")
notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin)
s, msg = pcall(function() cpp11_std_unique_ptr.takeKlassUniquePtr(notowned) end)
assert(s == false and msg == "Cannot release ownership as memory is not owned for argument 1 of type 'Klass *' in takeKlassUniquePtr")
checkCount(1)
kin = nil
checkCount(0)
kini = cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput")
checkCount(1)
s = cpp11_std_unique_ptr.takeKlassUniquePtr(kini)
checkCount(0)
if not (s == "KlassInheritanceInput") then
error("Incorrect string: "..s)
end
if not (cpp11_std_unique_ptr.is_nullptr(kini)) then
error("is_nullptr failed")
end
kini = nil -- Should not fail, even though already deleted
checkCount(0)
cpp11_std_unique_ptr.takeKlassUniquePtr(nil);
cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null());
checkCount(0);
-- unique_ptr as output
k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first")
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")
checkCount(2)
k1 = nil
checkCount(1)
if not (k2:getLabel() == "second") then
error("wrong object label")
end
k2 = nil
checkCount(0)
assert(cpp11_std_unique_ptr.makeNullUniquePtr() == nil)

View file

@ -77,6 +77,11 @@ end
kini = nil -- Should not fail, even though already deleted
checkCount(0)
li_std_auto_ptr.takeKlassAutoPtr(nil);
li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null());
checkCount(0);
-- auto_ptr as output
k1 = li_std_auto_ptr.makeKlassAutoPtr("first")
k2 = li_std_auto_ptr.makeKlassAutoPtr("second")
@ -91,3 +96,5 @@ end
k2 = nil
checkCount(0)
assert(li_std_auto_ptr.makeNullAutoPtr() == nil)

View file

@ -0,0 +1,100 @@
(load-extension "cpp11_std_unique_ptr.so")
(require (lib "defmacro.ss"))
; Copied from ../schemerunme/cpp11_std_unique_ptr.scm and modified for exceptions
; Define an equivalent to Guile's gc procedure
(define-macro (gc)
`(collect-garbage 'major))
(define checkCount
(lambda (expected-count)
(define actual-count (Klass-getTotal-count))
(unless (= actual-count expected-count) (error (format "Counts incorrect, expected:~a actual:~a" expected-count actual-count)))))
; Test raw pointer handling involving virtual inheritance
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (useKlassRawPtr kini))
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(set! kini '()) (gc)
(checkCount 0)
; unique_ptr as input
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kin))
(checkCount 0)
(unless (string=? s "KlassInput")
(error "Incorrect string: " s))
(unless (is-nullptr kin)
(error "is_nullptr failed"))
(define exception_thrown "no exception thrown for kin")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(takeKlassUniquePtr kin))
(unless (string=? exception_thrown "takeKlassUniquePtr: cannot release ownership as memory is not owned for argument 1 of type 'Klass *'")
(error "Wrong or no exception thrown: " exception_thrown))
(set! kin '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define kin (new-Klass "KlassInput"))
(define notowned (get-not-owned-ptr kin))
(set! exception_thrown "no exception thrown for notowned")
(with-handlers ([exn:fail? (lambda (exn)
(set! exception_thrown (exn-message exn)))])
(takeKlassUniquePtr notowned))
(unless (string=? exception_thrown "takeKlassUniquePtr: cannot release ownership as memory is not owned for argument 1 of type 'Klass *'")
(error "Wrong or no exception thrown: " exception_thrown))
(checkCount 1)
(set! kin '()) (gc)
(checkCount 0)
(define kini (new-KlassInheritance "KlassInheritanceInput"))
(checkCount 1)
(define s (takeKlassUniquePtr kini))
(checkCount 0)
(unless (string=? s "KlassInheritanceInput")
(error "Incorrect string: " s))
(unless (is-nullptr kini)
(error "is_nullptr failed"))
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassUniquePtr null)
(takeKlassUniquePtr (make-null))
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))
(checkCount 2)
(set! k1 '()) (gc)
(checkCount 1)
(unless (string=? (Klass-getLabel k2) "second")
(error "wrong object label" ))
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullUniquePtr))
(error "null failure"))
(exit 0)

View file

@ -74,6 +74,12 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassAutoPtr null)
(takeKlassAutoPtr (make-null))
(checkCount 0)
; auto_ptr as output
(define k1 (makeKlassAutoPtr "first"))
(define k2 (makeKlassAutoPtr "second"))
@ -88,4 +94,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullAutoPtr))
(error "null failure"))
(exit 0)

View file

@ -93,6 +93,13 @@ endif
clear kini; # Should not fail, even though already deleted
checkCount(0);
null = []; # NULL pointer
null_ptr = make_null();
takeKlassUniquePtr([]);
takeKlassUniquePtr(null);
takeKlassUniquePtr(null_ptr);
checkCount(0);
# unique_ptr as output
k1 = makeKlassUniquePtr("first");
@ -112,3 +119,8 @@ endif
clear k2;
checkCount(0);
null_smart_prt = makeNullUniquePtr();
assert(ismatrix(null_smart_prt))
assert(size(null_smart_prt) == size([]))
assert(isequal([], null_smart_prt))

View file

@ -93,6 +93,13 @@ endif
clear kini; # Should not fail, even though already deleted
checkCount(0);
null = []; # NULL pointer
null_ptr = make_null();
takeKlassAutoPtr([]);
takeKlassAutoPtr(null);
takeKlassAutoPtr(null_ptr);
checkCount(0);
# auto_ptr as output
k1 = makeKlassAutoPtr("first");
@ -112,3 +119,8 @@ endif
clear k2;
checkCount(0);
null_smart_prt = makeNullAutoPtr();
assert(ismatrix(null_smart_prt))
assert(size(null_smart_prt) == size([]))
assert(isequal([], null_smart_prt))

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 28;
use Test::More tests => 30;
BEGIN { use_ok('cpp11_std_unique_ptr') }
require_ok('cpp11_std_unique_ptr');
@ -73,6 +73,11 @@ sub checkCount {
checkCount(0);
}
cpp11_std_unique_ptr::takeKlassUniquePtr(undef);
cpp11_std_unique_ptr::takeKlassUniquePtr(cpp11_std_unique_ptr::make_null());
checkCount(0);
# unique_ptr as output
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
@ -85,3 +90,5 @@ is($k2->getLabel, "second", "proper label");
undef $k2;
checkCount(0);
is(cpp11_std_unique_ptr::makeNullUniquePtr(), undef);

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 28;
use Test::More tests => 30;
BEGIN { use_ok('li_std_auto_ptr') }
require_ok('li_std_auto_ptr');
@ -73,6 +73,11 @@ sub checkCount {
checkCount(0);
}
li_std_auto_ptr::takeKlassAutoPtr(undef);
li_std_auto_ptr::takeKlassAutoPtr(li_std_auto_ptr::make_null());
checkCount(0);
# auto_ptr as output
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
@ -85,3 +90,5 @@ is($k2->getLabel, "second", "proper label");
undef $k2;
checkCount(0);
is(li_std_auto_ptr::makeNullAutoPtr(), undef);

View file

@ -79,6 +79,11 @@ try {
$kini = NULL; # Should not fail, even though already deleted
checkCount(0);
takeKlassUniquePtr(NULL);
takeKlassUniquePtr(make_null());
checkCount(0);
# unique_ptr as output
$k1 = makeKlassUniquePtr("first");
$k2 = makeKlassUniquePtr("second");
@ -92,4 +97,6 @@ check::equal($k2->getLabel(), "second", "proper label");
$k2 = NULL;
checkCount(0);
check::equal(makeNullUniquePtr(), NULL);
check::done();

View file

@ -79,6 +79,11 @@ try {
$kini = NULL; # Should not fail, even though already deleted
checkCount(0);
takeKlassAutoPtr(NULL);
takeKlassAutoPtr(make_null());
checkCount(0);
# auto_ptr as output
$k1 = makeKlassAutoPtr("first");
$k2 = makeKlassAutoPtr("second");
@ -92,4 +97,6 @@ check::equal($k2->getLabel(), "second", "proper label");
$k2 = NULL;
checkCount(0);
check::equal(makeNullAutoPtr(), NULL);
check::done();

View file

@ -77,6 +77,11 @@ if not is_nullptr(kini):
del kini # Should not fail, even though already deleted
checkCount(0)
takeKlassUniquePtr(None)
takeKlassUniquePtr(make_null())
checkCount(0)
# unique_ptr as output
k1 = makeKlassUniquePtr("first")
k2 = makeKlassUniquePtr("second")
@ -90,3 +95,6 @@ if k2.getLabel() != "second":
del k2
checkCount(0)
if (makeNullUniquePtr() != None):
raise RuntimeError("null failure")

View file

@ -77,6 +77,11 @@ if not is_nullptr(kini):
del kini # Should not fail, even though already deleted
checkCount(0)
takeKlassAutoPtr(None)
takeKlassAutoPtr(make_null())
checkCount(0)
# auto_ptr as output
k1 = makeKlassAutoPtr("first")
k2 = makeKlassAutoPtr("second")
@ -90,3 +95,6 @@ if k2.getLabel() != "second":
del k2
checkCount(0)
if (makeNullAutoPtr() != None):
raise RuntimeError("null failure")

View file

@ -116,6 +116,11 @@ end
kini = nil
checkCount(0)
Cpp11_std_unique_ptr::takeKlassUniquePtr(nil)
Cpp11_std_unique_ptr::takeKlassUniquePtr(Cpp11_std_unique_ptr::make_null())
checkCount(0)
# unique_ptr as output
k1 = Cpp11_std_unique_ptr::makeKlassUniquePtr("first")
k2 = Cpp11_std_unique_ptr::makeKlassUniquePtr("second")
@ -131,3 +136,4 @@ gc_check(1)
k2 = nil
gc_check(0)
swig_assert_equal_simple(Cpp11_std_unique_ptr::makeNullUniquePtr(), nil)

View file

@ -116,6 +116,11 @@ end
kini = nil
checkCount(0)
Li_std_auto_ptr::takeKlassAutoPtr(nil)
Li_std_auto_ptr::takeKlassAutoPtr(Li_std_auto_ptr::make_null())
checkCount(0)
# auto_ptr as output
k1 = Li_std_auto_ptr::makeKlassAutoPtr("first")
k2 = Li_std_auto_ptr::makeKlassAutoPtr("second")
@ -131,3 +136,4 @@ gc_check(1)
k2 = nil
gc_check(0)
swig_assert_equal_simple(Li_std_auto_ptr::makeNullAutoPtr(), nil)

View file

@ -58,6 +58,14 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassUniquePtr null)
(define nullnil #nil)
(takeKlassUniquePtr nullnil)
(takeKlassUniquePtr (make-null))
(checkCount 0)
; unique_ptr as output
(define k1 (makeKlassUniquePtr "first"))
(define k2 (makeKlassUniquePtr "second"))
@ -72,4 +80,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullUniquePtr))
(error "null failure"))
(exit 0)

View file

@ -58,6 +58,14 @@
(set! kini '()) (gc) ; Should not fail, even though already deleted
(checkCount 0)
(define null '())
(takeKlassAutoPtr null)
(define nullnil #nil)
(takeKlassAutoPtr nullnil)
(takeKlassAutoPtr (make-null))
(checkCount 0)
; auto_ptr as output
(define k1 (makeKlassAutoPtr "first"))
(define k2 (makeKlassAutoPtr "second"))
@ -72,4 +80,7 @@
(set! k2 '()) (gc)
(checkCount 0)
(unless (null? (makeNullAutoPtr))
(error "null failure"))
(exit 0)

View file

@ -126,6 +126,11 @@ if {![is_nullptr kini]} {
kini -delete # Should not fail, even though already deleted
checkCount 0
takeKlassUniquePtr "NULL"
takeKlassUniquePtr [make_null]
checkCount 0
# unique_ptr as output
set k1 [makeKlassUniquePtr "first"]
set k2 [makeKlassUniquePtr "second"]
@ -140,3 +145,7 @@ if {[$k2 getLabel] != "second"} {
$k2 -delete
checkCount 0
if {[makeNullUniquePtr] != "NULL"} {
error "null failure"
}

View file

@ -97,6 +97,11 @@ if {![is_nullptr kini]} {
kini -delete # Should not fail, even though already deleted
checkCount 0
takeKlassAutoPtr "NULL"
takeKlassAutoPtr [make_null]
checkCount 0
# auto_ptr as output
set k1 [makeKlassAutoPtr "first"]
set k2 [makeKlassAutoPtr "second"]
@ -111,3 +116,7 @@ if {[$k2 getLabel] != "second"} {
$k2 -delete
checkCount 0
if {[makeNullAutoPtr] != "NULL"} {
error "null failure"
}

View file

@ -9,7 +9,7 @@
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, checkfn="lua_isuserdata", noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
%typemap(in, checkfn="SWIG_isptrtype", noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {

View file

@ -9,7 +9,7 @@
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, checkfn="lua_isuserdata", noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
%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);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {