From: <joe...@us...> - 2011-09-16 21:54:59
|
Revision: 12812 http://swig.svn.sourceforge.net/swig/?rev=12812&view=rev Author: joelandersson Date: 2011-09-16 21:54:50 +0000 (Fri, 16 Sep 2011) Log Message: ----------- merged in trunk changes to branch Modified Paths: -------------- branches/joelandersson-matlab/CHANGES.current branches/joelandersson-matlab/Doc/Manual/Warnings.html branches/joelandersson-matlab/Examples/test-suite/common.mk branches/joelandersson-matlab/Examples/test-suite/csharp/Makefile.in branches/joelandersson-matlab/Examples/test-suite/errors/expected.log branches/joelandersson-matlab/Examples/test-suite/errors/make.sh branches/joelandersson-matlab/Examples/test-suite/li_boost_intrusive_ptr.i branches/joelandersson-matlab/Examples/test-suite/perl5/li_typemaps_runme.pl branches/joelandersson-matlab/Lib/perl5/perlprimtypes.swg branches/joelandersson-matlab/Source/CParse/parser.y branches/joelandersson-matlab/Source/Include/swigwarn.h branches/joelandersson-matlab/Source/Modules/allocate.cxx branches/joelandersson-matlab/Source/Modules/lang.cxx Added Paths: ----------- branches/joelandersson-matlab/Examples/test-suite/errors/cpp_extend_destructors.i branches/joelandersson-matlab/Examples/test-suite/extend_constructor_destructor.i branches/joelandersson-matlab/Examples/test-suite/extend_typedef_class.i branches/joelandersson-matlab/Examples/test-suite/java/extend_constructor_destructor_runme.java branches/joelandersson-matlab/Examples/test-suite/java/extend_typedef_class_runme.java branches/joelandersson-matlab/Lib/csharp/boost_intrusive_ptr.i Property Changed: ---------------- branches/joelandersson-matlab/ Property changes on: branches/joelandersson-matlab ___________________________________________________________________ Modified: svn:mergeinfo - /branches/swig-2.0:11085-11086,11088-11089 /branches/szager-python-builtin:12331-12595 + /branches/swig-2.0:11085-11086,11088-11089 /branches/szager-python-builtin:12331-12595 /trunk:12799-12811 Modified: branches/joelandersson-matlab/CHANGES.current =================================================================== --- branches/joelandersson-matlab/CHANGES.current 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/CHANGES.current 2011-09-16 21:54:50 UTC (rev 12812) @@ -4,6 +4,45 @@ Version 2.0.5 (in progress) =========================== + +2011-09-14: wsfulton + [C#] Add boost_intrusive_ptr.i library contribution from patch #3401571. + +2011-09-13: wsfulton + Add warnings for badly named destructors, eg: + + struct KStruct { + ~NOT_KStruct() {} + }; + + cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored. + +2011-09-13: wsfulton + Fix %extend and destructors for templates. The destructor in %extend was not always wrapped, + for example: + + %extend FooT { + ~FooT() { delete $self; } // was not wrapped as expected + }; + template<class T> class FooT {}; + %template(FooTi) FooT<int>; + +2011-09-13: wsfulton + Fix special variables such as "$decl" and "$fulldecl" in destructors to include the ~ character. + +2011-09-10: talby + [perl5] SF bug #1481958 - Improve range checking for integer types. + Enhance li_typemaps_runme.pl + +2011-09-08: wsfulton + Fix %extend on typedef classes in a namespace using the typedef name, for example: + namespace Space { + %extend CStruct { + ... + } + typedef struct tagCStruct { ... } CStruct; + } + 2011-08-31: xavier98 [octave] patches from Karl Wette: improvements to module loading behavior; added example of friend operator to operator example; fixed octave panic/crash in 3.0.5; Modified: branches/joelandersson-matlab/Doc/Manual/Warnings.html =================================================================== --- branches/joelandersson-matlab/Doc/Manual/Warnings.html 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Doc/Manual/Warnings.html 2011-09-16 21:54:50 UTC (rev 12812) @@ -501,7 +501,7 @@ <li>501. Overloaded declaration ignored. <em>decl</em>. Previous declaration is <em>decl</em>. <li>502. Overloaded constructor ignored. <em>decl</em>. Previous declaration is <em>decl</em>. <li>503. Can't wrap '<em>identifier</em>' unless renamed to a valid identifier. -<li>504. Function <em>name</em> must have a return type. +<li>504. Function <em>name</em> must have a return type. Ignored. <li>505. Variable length arguments discarded. <li>506. Can't wrap varargs with keyword arguments enabled. <li>507. Adding native function <em>name</em> not supported (ignored). @@ -518,6 +518,7 @@ <li>518. Portability warning: File <em>file1</em> will be overwritten by <em>file2</em> on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed. <li>519. %template() contains no name. Template method ignored: <em>declaration</em> <li>520. <em>Base/Derived</em> class '<em>classname1</em>' of '<em>classname2</em>' is not similarly marked as a smart pointer. +<li>521. Illegal destructor name <em>name</em>. Ignored. </ul> <H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3> Modified: branches/joelandersson-matlab/Examples/test-suite/common.mk =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/common.mk 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/common.mk 2011-09-16 21:54:50 UTC (rev 12812) @@ -195,10 +195,12 @@ evil_diamond_prop \ exception_order \ extend \ + extend_constructor_destructor \ extend_default \ extend_placement \ extend_template \ extend_template_ns \ + extend_typedef_class \ extern_c \ extern_namespace \ extern_throws \ Modified: branches/joelandersson-matlab/Examples/test-suite/csharp/Makefile.in =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/csharp/Makefile.in 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/csharp/Makefile.in 2011-09-16 21:54:50 UTC (rev 12812) @@ -22,7 +22,8 @@ enum_thorough_simple \ enum_thorough_typesafe \ exception_partial_info \ - intermediary_classname + intermediary_classname \ + li_boost_intrusive_ptr include $(srcdir)/../common.mk Copied: branches/joelandersson-matlab/Examples/test-suite/errors/cpp_extend_destructors.i (from rev 12811, trunk/Examples/test-suite/errors/cpp_extend_destructors.i) =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/errors/cpp_extend_destructors.i (rev 0) +++ branches/joelandersson-matlab/Examples/test-suite/errors/cpp_extend_destructors.i 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,104 @@ +%module xxx + +///////////////////////////// +%extend AStruct { + ~AStruct() {} +} +struct AStruct { + ~AStruct() {} +}; + +///////////////////////////// +struct BStruct { + ~BStruct() {} + ~BStruct() {} +}; + +///////////////////////////// +struct CStruct { +}; + +%extend CStruct { + ~NOT_CStruct() { + delete $self; + } +} + +%extend DStruct { + ~NOT_DStruct() { + delete $self; + } +} + +struct DStruct { +}; + +///////////////////////////// +struct EStruct { + ~EStruct() {} +}; + +%extend EStruct { + ~NOT_EStruct() { + delete $self; + } +} + +%extend FStruct { + ~NOT_FStruct() { + delete $self; + } +} + +struct FStruct { + ~FStruct() {} +}; + +///////////////////////////// +struct GStruct { +}; + +%extend GStruct { + ~GStruct() {} + ~NOT_GStruct() { + delete $self; + } +} + +%extend HStruct { + ~HStruct() {} + ~NOT_HStruct() { + delete $self; + } +} + +struct HStruct { +}; + +///////////////////////////// +struct IStruct { + ~IStruct() {} + ~NOT_IStruct() {} +}; + +struct JStruct { + ~JStruct() {} + ~NOT_JStruct() {} + ~JStruct() {} +}; + +///////////////////////////// +struct KStruct { + ~NOT_KStruct() {} +}; + +///////////////////////////// +template<typename T> +struct LStruct { + ~LStruct() {} + ~NOT_LStruct() {} + ~LStruct() {} +}; +%template(LStructInt) LStruct<int>; +%template(LStructShort) LStruct<short>; + Modified: branches/joelandersson-matlab/Examples/test-suite/errors/expected.log =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/errors/expected.log 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/errors/expected.log 2011-09-16 21:54:50 UTC (rev 12812) @@ -209,6 +209,27 @@ cpp_bad_extern.i:5: Warning 313: Unrecognized extern type "INTERCAL". cpp_bad_extern.i:7: Warning 313: Unrecognized extern type "INTERCAL". +:::::::::::::::::::::::::::::::: cpp_extend_destructors.i ::::::::::::::::::::::::::::::::::: +cpp_extend_destructors.i:8: Warning 302: Identifier '~AStruct' redefined by %extend (ignored), +cpp_extend_destructors.i:5: Warning 302: %extend definition of '~AStruct'. +cpp_extend_destructors.i:14: Warning 302: Identifier '~BStruct' redefined (ignored), +cpp_extend_destructors.i:13: Warning 302: previous definition of '~BStruct'. +cpp_extend_destructors.i:87: Warning 302: Identifier '~JStruct' redefined (ignored), +cpp_extend_destructors.i:85: Warning 302: previous definition of '~JStruct'. +cpp_extend_destructors.i:100: Warning 302: Identifier '~LStruct' redefined (ignored), +cpp_extend_destructors.i:98: Warning 302: previous definition of '~LStruct'. +cpp_extend_destructors.i:24: Warning 521: Illegal destructor name ~NOT_CStruct. Ignored. +cpp_extend_destructors.i:30: Warning 521: Illegal destructor name ~NOT_DStruct. Ignored. +cpp_extend_destructors.i:44: Warning 521: Illegal destructor name ~NOT_EStruct. Ignored. +cpp_extend_destructors.i:50: Warning 521: Illegal destructor name ~NOT_FStruct. Ignored. +cpp_extend_destructors.i:65: Warning 521: Illegal destructor name ~NOT_GStruct. Ignored. +cpp_extend_destructors.i:72: Warning 521: Illegal destructor name ~NOT_HStruct. Ignored. +cpp_extend_destructors.i:81: Warning 521: Illegal destructor name ~NOT_IStruct. Ignored. +cpp_extend_destructors.i:86: Warning 521: Illegal destructor name ~NOT_JStruct. Ignored. +cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name ~NOT_LStruct< int >. Ignored. +cpp_extend_destructors.i:99: Warning 521: Illegal destructor name ~NOT_LStruct< short >. Ignored. + :::::::::::::::::::::::::::::::: cpp_extend_redefine.i ::::::::::::::::::::::::::::::::::: cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'. Modified: branches/joelandersson-matlab/Examples/test-suite/errors/make.sh =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/errors/make.sh 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/errors/make.sh 2011-09-16 21:54:50 UTC (rev 12812) @@ -63,6 +63,7 @@ # Files run in C++ mode CPPFILES=' cpp_bad_extern +cpp_extend_destructors cpp_extend_redefine cpp_extend_undefined cpp_inline_namespace Copied: branches/joelandersson-matlab/Examples/test-suite/extend_constructor_destructor.i (from rev 12811, trunk/Examples/test-suite/extend_constructor_destructor.i) =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/extend_constructor_destructor.i (rev 0) +++ branches/joelandersson-matlab/Examples/test-suite/extend_constructor_destructor.i 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,125 @@ +%module extend_constructor_destructor + +%inline %{ +int global = 0; + +namespace Space { + typedef struct tagAStruct { + int ivar; + } AStruct; + + struct BStruct { + int ivar; + }; + + typedef struct tagCStruct { + int ivar; + } CStruct; + + // Unnamed struct + typedef struct { + int ivar; + } DStruct; + +} + +typedef struct tagEStruct { + int ivar; +} EStruct; + +namespace Space { + template<typename T> + struct FFStruct { + int ivar; + }; +} +%} + +namespace Space { + +%extend tagAStruct { + tagAStruct(int ivar0) { + Space::AStruct *s = new Space::AStruct(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~tagAStruct() { + global = -$self->ivar; + delete $self; + } +} + +%extend BStruct { + BStruct(int ivar0) { + Space::BStruct *s = new Space::BStruct(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~BStruct() { + global = -$self->ivar; + delete $self; + } +} + +%extend CStruct { + CStruct(int ivar0) { + Space::CStruct *s = new Space::CStruct(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~CStruct() { + global = -$self->ivar; + delete $self; + } +} + +%extend DStruct { + DStruct(int ivar0) { + Space::DStruct *s = new Space::DStruct(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~DStruct() { + global = -$self->ivar; + delete $self; + } +} + +} + +%extend EStruct { + EStruct(int ivar0) { + EStruct *s = new EStruct(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~EStruct() { + global = -$self->ivar; + delete $self; + } +} + +namespace Space { +%extend FFStruct { + FFStruct(int ivar0) { + Space::FFStruct<T> *s = new Space::FFStruct<T>(); + s->ivar = ivar0; + global = ivar0; + return s; + } + ~FFStruct() { + global = -$self->ivar; + delete $self; + } +} + +} + +%template(FStruct) Space::FFStruct<long>; +%template(GStruct) Space::FFStruct<char>; + Copied: branches/joelandersson-matlab/Examples/test-suite/extend_typedef_class.i (from rev 12811, trunk/Examples/test-suite/extend_typedef_class.i) =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/extend_typedef_class.i (rev 0) +++ branches/joelandersson-matlab/Examples/test-suite/extend_typedef_class.i 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,81 @@ +%module extend_typedef_class + +// classes in global namespace +%inline %{ + typedef struct tagAClass { + int membervar; + } AClass; + + struct BClass { + int membervar; + }; + + typedef struct tagCClass { + int membervar; + } CClass; + + // Unnamed struct + typedef struct { + int membervar; + } DClass; +%} + +%extend tagAClass { + int getvar() { return $self->membervar; } +} + +%extend BClass { + int getvar() { return $self->membervar; } +} + +%extend CClass { + int getvar() { return $self->membervar; } +} + +%extend DClass { + int getvar() { return $self->membervar; } +} + + +// classes in a namespace +%inline %{ +namespace Space { + typedef struct tagAStruct { + int membervar; + } AStruct; + + struct BStruct { + int membervar; + }; + + typedef struct tagCStruct { + int membervar; + } CStruct; + + // Unnamed struct + typedef struct { + int membervar; + } DStruct; +} +%} + +namespace Space { + +%extend tagAStruct { + int getvar() { return $self->membervar; } +} + +%extend BStruct { + int getvar() { return $self->membervar; } +} + +%extend CStruct { + int getvar() { return $self->membervar; } +} + +%extend DStruct { + int getvar() { return $self->membervar; } +} + +} + Copied: branches/joelandersson-matlab/Examples/test-suite/java/extend_constructor_destructor_runme.java (from rev 12811, trunk/Examples/test-suite/java/extend_constructor_destructor_runme.java) =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/java/extend_constructor_destructor_runme.java (rev 0) +++ branches/joelandersson-matlab/Examples/test-suite/java/extend_constructor_destructor_runme.java 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,52 @@ +import extend_constructor_destructor.*; + +public class extend_constructor_destructor_runme { + + static { + try { + System.loadLibrary("extend_constructor_destructor"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + AStruct a = new AStruct(10); + checkGlobal(10); + BStruct b = new BStruct(20); + checkGlobal(20); + CStruct c = new CStruct(30); + checkGlobal(30); + DStruct d = new DStruct(40); + checkGlobal(40); + EStruct e = new EStruct(50); + checkGlobal(50); + FStruct f = new FStruct(60); + checkGlobal(60); + GStruct g = new GStruct(70); + checkGlobal(70); + + a.delete(); + checkGlobal(-10); + b.delete(); + checkGlobal(-20); + c.delete(); + checkGlobal(-30); + d.delete(); + checkGlobal(-40); + e.delete(); + checkGlobal(-50); + f.delete(); + checkGlobal(-60); + g.delete(); + checkGlobal(-70); + } + + public static void checkGlobal(int val) { + int global = extend_constructor_destructor.getGlobal(); + if (global != val) + throw new RuntimeException("global value incorrect. Expected: " + val + " got: " + global); + } +} + Copied: branches/joelandersson-matlab/Examples/test-suite/java/extend_typedef_class_runme.java (from rev 12811, trunk/Examples/test-suite/java/extend_typedef_class_runme.java) =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/java/extend_typedef_class_runme.java (rev 0) +++ branches/joelandersson-matlab/Examples/test-suite/java/extend_typedef_class_runme.java 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,65 @@ +import extend_typedef_class.*; + +public class extend_typedef_class_runme { + + static { + try { + System.loadLibrary("extend_typedef_class"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + // No namespace + { + AClass s = new AClass(); + s.setMembervar(10); + checkMatch(s.getvar(), 10); + } + { + BClass s = new BClass(); + s.setMembervar(20); + checkMatch(s.getvar(), 20); + } + { + CClass s = new CClass(); + s.setMembervar(30); + checkMatch(s.getvar(), 30); + } + { + DClass s = new DClass(); + s.setMembervar(40); + checkMatch(s.getvar(), 40); + } + + // In namespace + { + AStruct s = new AStruct(); + s.setMembervar(10); + checkMatch(s.getvar(), 10); + } + { + BStruct s = new BStruct(); + s.setMembervar(20); + checkMatch(s.getvar(), 20); + } + { + CStruct s = new CStruct(); + s.setMembervar(30); + checkMatch(s.getvar(), 30); + } + { + DStruct s = new DStruct(); + s.setMembervar(40); + checkMatch(s.getvar(), 40); + } + } + + public static void checkMatch(int expected, int got) { + if (expected != got) + throw new RuntimeException("Value incorrect. Expected: " + expected + " got: " + got); + } +} + Modified: branches/joelandersson-matlab/Examples/test-suite/li_boost_intrusive_ptr.i =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/li_boost_intrusive_ptr.i 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/li_boost_intrusive_ptr.i 2011-09-16 21:54:50 UTC (rev 12812) @@ -10,6 +10,8 @@ %module li_boost_intrusive_ptr %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); +%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived; +%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived; %inline %{ #include "boost/shared_ptr.hpp" @@ -37,7 +39,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) #define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED #endif @@ -50,6 +52,7 @@ %intrusive_ptr(Space::KlassDerivedDerived) //For the use_count shared_ptr functions +#if defined(SWIGJAVA) %typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{ $1 = $input ? *($&1_ltype)&$input : &tempnull; %} @@ -74,8 +77,12 @@ %typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived" %typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived.getCPtr($javainput)" +#elif defined(SWIGCSHARP) +// TODO! #endif +#endif + // TODO: // const intrusive_ptr // std::vector Modified: branches/joelandersson-matlab/Examples/test-suite/perl5/li_typemaps_runme.pl =================================================================== --- branches/joelandersson-matlab/Examples/test-suite/perl5/li_typemaps_runme.pl 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Examples/test-suite/perl5/li_typemaps_runme.pl 2011-09-16 21:54:50 UTC (rev 12812) @@ -1,74 +1,99 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More tests => 415; +use Test::More tests => 631; BEGIN { use_ok('li_typemaps') } require_ok('li_typemaps'); -sub batch { my($type, @values) = @_; - # this is a little ugly because I'm trying to be clever and save my - # wrists from hammering out all these tests. - for my $val (@values) { - for my $tst (qw( - in inr - out outr - inout inoutr - )) { - my $func = $tst . '_' . $type; - is(eval { li_typemaps->can($func)->($val) }, $val, "$func $val"); - if($@) { - my $err = $@; - $err =~ s/^/#\$\@# /mg; - print $err; - } +my @tests = qw( + in inr + out outr + inout inoutr +); + +sub should_pass { my($type, @values) = @_; + # verify that each value passes cleanly + for my $test (@tests) { + my $name = "${test}_${type}"; + my $func = li_typemaps->can($name); + for my $val (@values) { + my $rv = eval { $func->($val) }; + is($rv, $val, "$name $val"); } } } -batch('bool', '', 1); -# let's assume we're at least on a 32 bit machine -batch('int', -0x80000000, -1, 0, 1, 12, 0x7fffffff); -# long could be bigger, but it's at least this big -batch('long', -0x80000000, -1, 0, 1, 12, 0x7fffffff); -batch('short', -0x8000, -1, 0, 1, 12, 0x7fff); -batch('uint', 0, 1, 12, 0xffffffff); -batch('ushort', 0, 1, 12, 0xffff); -batch('ulong', 0, 1, 12, 0xffffffff); -batch('uchar', 0, 1, 12, 0xff); -batch('schar', -0x80, 0, 1, 12, 0x7f); +sub should_fail { my($type, @values) = @_; + # verify that all values trigger runtime errors + for my $test (@tests) { + my $name = "${test}_${type}"; + my $func = li_typemaps->can($name); + for my $val (@values) { + my $rv = eval { $func->($val) }; + like($@, qr/\b(?:Overflow|Type)Error\b/, "overflow $name $val"); + } + } +} -{ - use Math::BigInt qw(); - # the pack dance is to get plain old NVs out of the - # Math::BigInt objects. - my $inf = unpack 'd', pack 'd', Math::BigInt->binf(); - my $nan = unpack 'd', pack 'd', Math::BigInt->bnan(); - batch('float', - -(2 - 2 ** -23) * 2 ** 127, - -1, -2 ** -149, 0, 2 ** -149, 1, - (2 - 2 ** -23) * 2 ** 127, - $nan); - { local $TODO = "float typemaps don't pass infinity"; - # it seems as though SWIG is unwilling to pass infinity around - # because that value always fails bounds checking. I think that - # is a bug. - batch('float', $inf); - } - batch('double', - -(2 - 2 ** -53) ** 1023, - -1, -2 ** -1074, 0, 2 ** 1074, - (2 - 2 ** -53) ** 1023, - $nan, $inf); +sub pad { my($t, $s, $f) = @_; + my $nbytes = length pack $t, 0; + return unpack $t, $s . ($f x ($nbytes - 1)); } -batch('longlong', -1, 0, 1, 12); -batch('ulonglong', 0, 1, 12); + +# some edge case values: +my $nan = unpack 'f>', "\x7f\xc0\x00\x00"; +my $inf = unpack 'f>', "\x7f\x80\x00\x00"; +my $char_min = pad 'c', "\x80"; +my $char_max = pad 'c', "\x7f"; +my $char_umax = pad 'C', "\xff"; +my $short_min = pad 's!>', "\x80", "\x00"; +my $short_max = pad 's!>', "\x7f", "\xff"; +my $short_umax = pad 'S!>', "\xff", "\xff"; +my $int_min = pad 'i!>', "\x80", "\x00"; +my $int_max = pad 'i!>', "\x7f", "\xff"; +my $int_umax = pad 'I!>', "\xff", "\xff"; +my $long_min = pad 'l!>', "\x80", "\x00"; +my $long_max = pad 'l!>', "\x7f", "\xff"; +my $long_umax = pad 'L!>', "\xff", "\xff"; + +should_pass('bool', '', 1); +should_pass('int', $int_min, -1, 0, 1, 12, $int_max); +should_fail('int', $int_min - 1000, $int_max + 1000, $inf, $nan); +should_pass('long', $long_min, -1, 0, 1, 12, $long_max); +should_fail('long', $long_min - 8000, $long_max + 8000, $inf, $nan); +should_pass('short', $short_min, -1, 0, 1, 12, $short_max); +should_fail('short', $short_min - 1, $short_max + 1, $inf, $nan); +should_pass('uint', 0, 1, 12, $int_umax); +should_fail('uint', -1, $int_umax + 1000, $inf, $nan); +should_pass('ushort', 0, 1, 12, $short_umax); +should_fail('ushort', -1, $short_umax + 1, $inf, $nan); +should_pass('ulong', 0, 1, 12, $long_umax); +should_fail('ulong', -1, $long_umax + 8000, $inf, $nan); +should_pass('uchar', 0, 1, 12, $char_umax); +should_fail('uchar', -1, $char_umax + 1, $inf, $nan); +should_pass('schar', $char_min, -1, 0, 1, 12, $char_max); +should_fail('schar', $char_min - 1, $char_max + 1, $inf, $nan); +should_pass('float', -1, 0, 1, $nan); +TODO: { + local $TODO = "typemaps don't allow float infinity"; + should_pass('float', -$inf, $inf); +} +should_pass('double', -$inf, -1, 0, 1, $inf, $nan); +should_pass('longlong', -1, 0, 1, 12); +should_fail('longlong', $inf, $nan); +should_pass('ulonglong', 0, 1, 12); +should_fail('ulonglong', -1, $inf, $nan); SKIP: { - my $a = "8000000000000000"; - my $b = "7fffffffffffffff"; - my $c = "ffffffffffffffff"; - skip "not a 64bit Perl", 18 unless eval { pack 'q', 1 }; - batch('longlong', -hex($a), hex($b)); - batch('ulonglong', hex($c)); + my $llong_min = eval { pad 'q>', "\x80", "\x00" }; + my $llong_max = eval { pad 'q>', "\x7f", "\xff" }; + my $llong_umax = eval { pad 'Q>', "\xff", "\xff" }; + + skip 'not a 64 bit perl', 6 * 6 unless defined $llong_min; + + should_pass('longlong', $llong_min, $llong_max); + should_fail('longlong', $llong_min - 8000, $llong_max + 8000); + should_pass('ulonglong', $llong_umax); + should_fail('ulonglong', $llong_umax + 8000); } my($foo, $int) = li_typemaps::out_foo(10); @@ -79,4 +104,3 @@ my($a, $b) = li_typemaps::inoutr_int2(13, 31); is($a, 13); is($b, 31); - Copied: branches/joelandersson-matlab/Lib/csharp/boost_intrusive_ptr.i (from rev 12811, trunk/Lib/csharp/boost_intrusive_ptr.i) =================================================================== --- branches/joelandersson-matlab/Lib/csharp/boost_intrusive_ptr.i (rev 0) +++ branches/joelandersson-matlab/Lib/csharp/boost_intrusive_ptr.i 2011-09-16 21:54:50 UTC (rev 12812) @@ -0,0 +1,506 @@ +%include <intrusive_ptr.i> + +// Language specific macro implementing all the customisations for handling the smart pointer +%define SWIG_INTRUSIVE_PTR_TYPEMAPS(CONST, TYPE...) + +// %naturalvar is as documented for member variables +%naturalvar TYPE; +%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; + +// destructor wrapper customisation +%feature("unref") TYPE "(void)arg1; delete smartarg1;" + +// Typemap customisations... + +%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain value + argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; + if (!argp) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0); + return $null; + } + $1 = *argp; +%} +%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{ + //plain value(out) + $1_ltype* resultp = new $1_ltype(($1_ltype &)$1); + intrusive_ptr_add_ref(resultp); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >()); +%} + +%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain pointer + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; + $1 = (TYPE *)(smartarg ? smartarg->get() : 0); +%} +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{ + //plain pointer(out) + #if ($owner) + if ($1) { + intrusive_ptr_add_ref($1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + #endif +%} + +%typemap(in, canthrow=1) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain reference + $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + if(!$1) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type reference is null", 0); + return $null; + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{ + //plain reference(out) + #if ($owner) + if ($1) { + intrusive_ptr_add_ref($1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; + #endif +%} + +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + // plain pointer by reference + temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + $1 = &temp; +%} +%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{ + // plain pointer by reference(out) + #if ($owner) + if (*$1) { + intrusive_ptr_add_ref(*$1); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + #else + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0); + #endif +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by value + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + if (smartarg) { + $1 = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{ + if ($1) { + intrusive_ptr_add_ref(result.get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{ + // shared_ptr by value + smartarg = *($&1_ltype*)&$input; + if (smartarg) $1 = *smartarg; +%} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ + *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by reference + if ( $input ) { + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + $1 = &temp; + } else { + $1 = &tempnull; + } +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ + delete &($1); + if ($self) { + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); + $1 = *temp; + } +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{ + if (*$1) { + intrusive_ptr_add_ref($1->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by pointer + if ( $input ) { + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + $1 = &temp; + } else { + $1 = &tempnull; + } +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ + delete $1; + if ($self) $1 = new SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(*$input); +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{ + if ($1 && *$1) { + intrusive_ptr_add_ref($1->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } + if ($owner) delete $1; +%} + +%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{ + // intrusive_ptr by pointer reference + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >**)&$input; + if ($input) { + temp = SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true); + } + tempp = &temp; + $1 = &tempp; +%} +%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ + if ($self) $1 = *$input; +%} +%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{ + if (*$1 && **$1) { + intrusive_ptr_add_ref((*$1)->get()); + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >()); + } else { + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0; + } +%} + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%typemap (ctype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "void *" +%typemap (imtype, out="IntPtr") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "HandleRef" +%typemap (cstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(cstype, TYPE)" +%typemap(csin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *, + SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "$typemap(cstype, TYPE).getCPtr($csinput)" + +%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{ + get { + $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode + return ret; + } %} +%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >& %{ + get { + $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode + return ret; + } %} +%typemap(csvarout, excode=SWIGEXCODE2) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >* %{ + get { + $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode + return ret; + } %} + + +%typemap(csout, excode=SWIGEXCODE) CONST TYPE { + $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) CONST TYPE & { + $typemap(cstype, TYPE) ret = new $typemap(cstype, TYPE)($imcall, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) CONST TYPE * { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } +%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { + IntPtr cPtr = $imcall; + $typemap(cstype, TYPE) ret = (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode + return ret; + } + +// Base proxy classes +%typemap(csbody) TYPE %{ + private HandleRef swigCPtr; + private bool swigCMemOwnBase; + + public $csclassname(IntPtr cPtr, bool cMemoryOwn) { + swigCMemOwnBase = cMemoryOwn; + swigCPtr = new HandleRef(this, cPtr); + } + + internal static HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + } +%} + +// Derived proxy classes +%typemap(csbody_derived) TYPE %{ + private HandleRef swigCPtr; + private bool swigCMemOwnDerived; + + public $csclassname(IntPtr cPtr, bool cMemoryOwn) + : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { + + swigCMemOwnDerived = cMemoryOwn; + swigCPtr = new HandleRef(this, cPtr); + } + + internal static HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + } +%} + +%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { + lock(this) { + if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCMemOwnBase) { + swigCMemOwnBase = false; + $imcall; + } + swigCPtr = new HandleRef(null, IntPtr.Zero); + } + GC.SuppressFinalize(this); + } + } + +%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { + lock(this) { + if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCMemOwnDerived) { + swigCMemOwnDerived = false; + $imcall; + } + swigCPtr = new HandleRef(null, IntPtr.Zero); + } + GC.SuppressFinalize(this); + base.Dispose(); + } + } + +// CONST version needed ???? also for C# +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef" + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; +%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >; +%enddef + + +///////////////////////////////////////////////////////////////////// + + +%include <shared_ptr.i> + +%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(CONST, TYPE...) + +%naturalvar TYPE; +%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + +// destructor mods +%feature("unref") TYPE "(void)arg1; delete smartarg1;" + + +// plain value +%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{ + argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; + if (!argp) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0); + return $null; + } + $1 = *argp; %} +%typemap(out) CONST TYPE +%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %} + +// plain pointer +%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ + smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; + $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{ + *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; +%} + +// plain reference +%typemap(in, canthrow=1) CONST TYPE & %{ + $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + if (!$1) { + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type reference is null", 0); + return $null; + } %} +%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & +%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} + +// plain pointer by reference +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); + $1 = &temp; %} +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& +%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} + +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{ + // shared_ptr by value + smartarg = *($&1_ltype*)&$input; + if (smartarg) $1 = *smartarg; +%} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{ + *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; +%} + +// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug +%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} +%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ +#error "typemaps for $1_type not available" +%} + + +%typemap (ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "void *" +%typemap (imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "void *" +%typemap (cstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE)" +%typemap (csin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "$typemap(cstype, TYPE).getCPtr($csinput)" +%typemap(csout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + IntPtr cPtr = $imcall; + return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + } + +%typemap(csout, excode=SWIGEXCODE) CONST TYPE { + return new $typemap(cstype, TYPE)($imcall, true); + } +%typemap(csout, excode=SWIGEXCODE) CONST TYPE & { + return new $typemap(cstype, TYPE)($imcall, true); + } +%typemap(csout, excode=SWIGEXCODE) CONST TYPE * { + IntPtr cPtr = $imcall; + return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + } +%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { + IntPtr cPtr = $imcall; + return (cPtr == IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true); + } + +// Base proxy classes +%typemap(csbody) TYPE %{ + private HandleRef swigCPtr; + private bool swigCMemOwnBase; + + public $csclassname(IntPtr cPtr, bool cMemoryOwn) { + swigCMemOwnBase = cMemoryOwn; + swigCPtr = new HandleRef(this, cPtr); + } + + internal static HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + } +%} + +// Derived proxy classes +%typemap(csbody_derived) TYPE %{ + private HandleRef swigCPtr; + private bool swigCMemOwnDerived; + + public $csclassname(IntPtr cPtr, bool cMemoryOwn) + : base($imclassname.$csclazznameSWIGSmartPtrUpcast(cPtr), true) { + + swigCMemOwnDerived = cMemoryOwn; + swigCPtr = new HandleRef(this, cPtr); + } + + internal static HandleRef getCPtr($csclassname obj) { + return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; + } +%} + +%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") TYPE { + lock(this) { + if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCMemOwnBase) { + swigCMemOwnBase = false; + $imcall; + } + swigCPtr = new HandleRef(null, IntPtr.Zero); + } + GC.SuppressFinalize(this); + } + } + +%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE { + lock(this) { + if (swigCPtr.Handle != IntPtr.Zero) { + if (swigCMemOwnDerived) { + swigCMemOwnDerived = false; + $imcall; + } + swigCPtr = new HandleRef(null, IntPtr.Zero); + } + GC.SuppressFinalize(this); + base.Dispose(); + } + } + + +// CONST version needed ???? also for C# +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "HandleRef" +%typemap(imtype, nopgcpp="1") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "HandleRef" + + +%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; +%enddef + Modified: branches/joelandersson-matlab/Lib/perl5/perlprimtypes.swg =================================================================== --- branches/joelandersson-matlab/Lib/perl5/perlprimtypes.swg 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Lib/perl5/perlprimtypes.swg 2011-09-16 21:54:50 UTC (rev 12812) @@ -7,19 +7,12 @@ %fragment(SWIG_From_frag(bool),"header") { SWIGINTERNINLINE SV * SWIG_From_dec(bool)(bool value) -{ - SV *obj = sv_newmortal(); - if (value) { - sv_setsv(obj, &PL_sv_yes); - } else { - sv_setsv(obj, &PL_sv_no); - } - return obj; +{ + return boolSV(value); } } -%fragment(SWIG_AsVal_frag(bool),"header", - fragment="SWIG_CanCastAsInteger") { +%fragment(SWIG_AsVal_frag(bool),"header") { SWIGINTERN int SWIG_AsVal_dec(bool)(SV *obj, bool* val) { @@ -30,10 +23,9 @@ if (val) *val = false; return SWIG_OK; } else { - if (val) *val = SvTRUE(obj) ? true: false; + if (val) *val = SvTRUE(obj); return SWIG_AddCast(SWIG_OK); } - return SWIG_TypeError; } } @@ -43,10 +35,13 @@ %fragment(SWIG_From_frag(long),"header") { SWIGINTERNINLINE SV * SWIG_From_dec(long)(long value) -{ - SV *obj = sv_newmortal(); - sv_setiv(obj, (IV) value); - return obj; +{ + SV *sv; + if (value >= IV_MIN && value <= IV_MAX) + sv = newSViv(value); + else + sv = newSVpvf("%ld", value); + return sv_2mortal(sv); } } @@ -55,9 +50,20 @@ SWIGINTERN int SWIG_AsVal_dec(long)(SV *obj, long* val) { - if (SvIOK(obj)) { - if (val) *val = SvIV(obj); - return SWIG_OK; + if (SvUOK(obj)) { + UV v = SvUV(obj); + if (v <= LONG_MAX) { + if (val) *val = v; + return SWIG_OK; + } + return SWIG_OverflowError; + } else if (SvIOK(obj)) { + IV v = SvIV(obj); + if (v >= LONG_MIN && v <= LONG_MAX) { + if(val) *val = v; + return SWIG_OK; + } + return SWIG_OverflowError; } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); @@ -91,14 +97,16 @@ /* unsigned long */ -%fragment(SWIG_From_frag(unsigned long),"header", - fragment=SWIG_AsVal_frag(double)) { +%fragment(SWIG_From_frag(unsigned long),"header") { SWIGINTERNINLINE SV * SWIG_From_dec(unsigned long)(unsigned long value) -{ - SV *obj = sv_newmortal(); - sv_setuv(obj, (UV) value); - return obj; +{ + SV *sv; + if (value <= UV_MAX) + sv = newSVuv(value); + else + sv = newSVpvf("%lu", value); + return sv_2mortal(sv); } } @@ -108,16 +116,19 @@ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val) { if (SvUOK(obj)) { - if (val) *val = SvUV(obj); - return SWIG_OK; - } else if (SvIOK(obj)) { - long v = SvIV(obj); - if (v >= 0) { + UV v = SvUV(obj); + if (v <= ULONG_MAX) { if (val) *val = v; return SWIG_OK; - } else { - return SWIG_OverflowError; } + return SWIG_OverflowError; + } else if (SvIOK(obj)) { + IV v = SvIV(obj); + if (v >= 0 && v <= ULONG_MAX) { + if (val) *val = v; + return SWIG_OK; + } + return SWIG_OverflowError; } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); @@ -158,15 +169,12 @@ SWIGINTERNINLINE SV * SWIG_From_dec(long long)(long long value) { - if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) { - return SWIG_From(long)(%numeric_cast(value,long)); - } else { - char temp[256]; - SV *obj = sv_newmortal(); - sprintf(temp, "%lld", value); - sv_setpv(obj, temp); - return obj; - } + SV *sv; + if (value >= IV_MIN && value <= IV_MAX) + sv = newSViv(value); + else + sv = newSVpvf("%lld", value); + return sv_2mortal(sv); } } @@ -178,9 +186,20 @@ SWIGINTERN int SWIG_AsVal_dec(long long)(SV *obj, long long *val) { - if (SvIOK(obj)) { - if (val) *val = SvIV(obj); - return SWIG_OK; + if (SvUOK(obj)) { + UV v = SvUV(obj); + if (v < LLONG_MAX) { + if (val) *val = v; + return SWIG_OK; + } + return SWIG_OverflowError; + } else if (SvIOK(obj)) { + IV v = SvIV(obj); + if (v >= LLONG_MIN && v <= LLONG_MAX) { + if (val) *val = v; + return SWIG_OK; + } + return SWIG_OverflowError; } else { int dispatch = 0; const char *nptr = SvPV_nolen(obj); @@ -223,15 +242,12 @@ SWIGINTERNINLINE SV * SWIG_From_dec(unsigned long long)(unsigned long long value) { - if (value < (unsigned long long) LONG_MAX) { - return SWIG_From(long long)(%numeric_cast(value, long long)); - } else { - char temp[256]; - SV *obj = sv_newmortal(); - sprintf(temp, "%llu", value); - sv_setpv(obj, temp); - return obj; - } + SV *sv; + if (value <= UV_MAX) + sv = newSVuv(value); + else + sv = newSVpvf("%llu", value); + return sv_2mortal(sv); } } @@ -241,13 +257,13 @@ fragment="SWIG_CanCastAsInteger") { SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val) -{ +{ if (SvUOK(obj)) { if (val) *val = SvUV(obj); return SWIG_OK; } else if (SvIOK(obj)) { - long v = SvIV(obj); - if (v >= 0) { + IV v = SvIV(obj); + if (v >= 0 && v <= ULLONG_MAX) { if (val) *val = v; return SWIG_OK; } else { @@ -290,10 +306,8 @@ %fragment(SWIG_From_frag(double),"header") { SWIGINTERNINLINE SV * SWIG_From_dec(double)(double value) -{ - SV *obj = sv_newmortal(); - sv_setnv(obj, value); - return obj; +{ + return sv_2mortal(newSVnv(value)); } } Modified: branches/joelandersson-matlab/Source/CParse/parser.y =================================================================== --- branches/joelandersson-matlab/Source/CParse/parser.y 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Source/CParse/parser.y 2011-09-16 21:54:50 UTC (rev 12812) @@ -3560,20 +3560,25 @@ if (Cmp($1,"typedef") == 0) { if (!decltype || !Len(decltype)) { String *cname; + String *tdscopename; + String *class_scope = Swig_symbol_qualifiedscopename(cscope); name = Getattr($9,"name"); cname = Copy(name); Setattr($$,"tdname",cname); - Delete(cname); + tdscopename = class_scope ? NewStringf("%s::%s", class_scope, name) : Copy(name); /* Use typedef name as class name */ if (class_rename && (Strcmp(class_rename,$3) == 0)) { Delete(class_rename); class_rename = NewString(name); } - if (!Getattr(classes,name)) { - Setattr(classes,name,$$); + if (!Getattr(classes,tdscopename)) { + Setattr(classes,tdscopename,$$); } Setattr($$,"decl",decltype); + Delete(class_scope); + Delete(cname); + Delete(tdscopename); } } } Modified: branches/joelandersson-matlab/Source/Include/swigwarn.h =================================================================== --- branches/joelandersson-matlab/Source/Include/swigwarn.h 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Source/Include/swigwarn.h 2011-09-16 21:54:50 UTC (rev 12812) @@ -195,6 +195,7 @@ #define WARN_LANG_PORTABILITY_FILENAME 518 #define WARN_LANG_TEMPLATE_METHOD_IGNORE 519 #define WARN_LANG_SMARTPTR_MISSING 520 +#define WARN_LANG_ILLEGAL_DESTRUCTOR 521 /* -- Reserved (600-799) -- */ Modified: branches/joelandersson-matlab/Source/Modules/allocate.cxx =================================================================== --- branches/joelandersson-matlab/Source/Modules/allocate.cxx 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Source/Modules/allocate.cxx 2011-09-16 21:54:50 UTC (rev 12812) @@ -936,6 +936,9 @@ } else if (cplus_mode == PROTECTED) { Setattr(inclass, "allocate:default_base_destructor", "1"); } + } else { + Setattr(inclass, "allocate:has_destructor", "1"); + Setattr(inclass, "allocate:default_destructor", "1"); } return SWIG_OK; } Modified: branches/joelandersson-matlab/Source/Modules/lang.cxx =================================================================== --- branches/joelandersson-matlab/Source/Modules/lang.cxx 2011-09-15 08:32:26 UTC (rev 12811) +++ branches/joelandersson-matlab/Source/Modules/lang.cxx 2011-09-16 21:54:50 UTC (rev 12812) @@ -2288,9 +2288,7 @@ String *decl = NewString("f()."); String *symname = Swig_name_make(cn, cname, last, decl, 0); if (Strcmp(symname, "$ignore") != 0) { - if (!symname) { - symname = NewStringf("~%s", Getattr(n, "sym:name")); - } + String *possible_nonstandard_symname = NewStringf("~%s", Getattr(n, "sym:name")); Setattr(cn, "name", name); Setattr(cn, "sym:name", symname); @@ -2298,20 +2296,27 @@ Setattr(cn, "parentNode", n); Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); + Node *nonstandard_destructor = Equal(possible_nonstandard_symname, symname) ? 0 : Swig_symbol_clookup(possible_nonstandard_symname, 0); Node *on = Swig_symbol_add(symname, cn); Swig_symbol_setscope(oldscope); Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { - Node *access = NewHash(); - set_nodeType(access, "access"); - Setattr(access, "kind", "public"); - appendChild(n, access); - appendChild(n, cn); - Setattr(n, "has_destructor", "1"); - Setattr(n, "allocate:destructor", "1"); - Delete(access); + // SWIG accepts a non-standard named destructor in %extend that uses a typedef for the destructor name + // For example: typedef struct X {} XX; %extend X { ~XX() {...} } + // Don't add another destructor if a nonstandard one has been declared + if (!nonstandard_destructor) { + Node *access = NewHash(); + set_nodeType(access, "access"); + Setattr(access, "kind", "public"); + appendChild(n, access); + appendChild(n, cn); + Setattr(n, "has_destructor", "1"); + Setattr(n, "allocate:destructor", "1"); + Delete(access); + } } + Delete(possible_nonstandard_symname); } Delete(cn); Delete(last); @@ -2604,10 +2609,22 @@ } } } else { - if (name && (Cmp(Swig_scopename_last(name), Swig_scopename_last(ClassName))) && !(Getattr(n, "template"))) { - Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type. Ignored.\n", SwigType_namestr(name)); - Swig_restore(n); - return SWIG_NOWRAP; + String *expected_name = ClassName; + if (name && (!Equal(Swig_scopename_last(name), Swig_scopename_last(expected_name))) && !(Getattr(n, "template"))) { + bool illegal_name = true; + if (Extend) { + // SWIG extension - allow typedef names as constructor name in %extend - an unnamed struct declared with a typedef can thus be given a 'constructor'. + SwigType *name_resolved = SwigType_typedef_resolve_all(name); + SwigType *expected_name_resolved = SwigType_typedef_resolve_all(expected_name); + illegal_name = !Equal(name_resolved, expected_name_resolved); + Delete(name_resolved); + Delete(expected_name_resolved); + } + if (illegal_name) { ... [truncated message content] |