diff --git a/CHANGES.current b/CHANGES.current index f5ffd91e2..41824f3fa 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-07-12: wsfulton + [Perl] Add std::auto_ptr support in std_auto_ptr.i library file. + +2022-07-12: erezgeva + [Perl] Add std::unique_ptr support in std_unique_ptr.i library file. + 2022-07-07: olly [xml] #2213 XML has been moved to "Experimental" target language status. It's not in good shape and is likely to be removed unless diff --git a/Examples/test-suite/li_std_auto_ptr.i b/Examples/test-suite/li_std_auto_ptr.i index d83732af0..edfe2ccf5 100644 --- a/Examples/test-suite/li_std_auto_ptr.i +++ b/Examples/test-suite/li_std_auto_ptr.i @@ -12,7 +12,7 @@ #endif %} -#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) +#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGPERL) %include "std_auto_ptr.i" diff --git a/Examples/test-suite/perl5/li_std_auto_ptr_runme.pl b/Examples/test-suite/perl5/li_std_auto_ptr_runme.pl new file mode 100644 index 000000000..52cb23ac5 --- /dev/null +++ b/Examples/test-suite/perl5/li_std_auto_ptr_runme.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::More tests => 6; +BEGIN { use_ok('li_std_auto_ptr') } +require_ok('li_std_auto_ptr'); + +my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first"); +my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second"); +is(li_std_auto_ptr::Klass::getTotal_count, 2, "have 2 pointers"); + +undef $k1; +is(li_std_auto_ptr::Klass::getTotal_count, 1, "left 1 pointer"); + +is($k2->getLabel, "second", "proper label"); + +undef $k2; +is(li_std_auto_ptr::Klass::getTotal_count, 0, "remove all pointers"); diff --git a/Lib/perl5/std_auto_ptr.i b/Lib/perl5/std_auto_ptr.i new file mode 100644 index 000000000..ecaea2b0f --- /dev/null +++ b/Lib/perl5/std_auto_ptr.i @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------------- + * std_auto_ptr.i + * + * The typemaps here allow handling functions returning std::auto_ptr<>, + * which is the most common use of this type. If you have functions taking it + * as parameter, these typemaps can't be used for them and you need to do + * something else (e.g. use shared_ptr<> which SWIG supports fully). + * ----------------------------------------------------------------------------- */ + +%define %auto_ptr(TYPE) +%typemap (out) std::auto_ptr< TYPE > %{ + %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags)); +%} +%template() std::auto_ptr< TYPE >; +%enddef + +namespace std { + template class auto_ptr {}; +}