diff --git a/CHANGES.current b/CHANGES.current index d0dc7e4da..e8b145673 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-19: wsfulton + [Perl] Patch #3260265 fixing overloading of non-primitive types and integers in + Perl 5.12 and later. + 2011-05-19: wsfulton [Ruby] Fix %import where one of the imported files %include one of the STL include files such as std_vector.i. diff --git a/Examples/test-suite/overload_simple.i b/Examples/test-suite/overload_simple.i index d23807641..6bedf6cef 100644 --- a/Examples/test-suite/overload_simple.i +++ b/Examples/test-suite/overload_simple.i @@ -208,3 +208,9 @@ long long ll(long long ull) { return ull; } } #endif + +%inline %{ + int int_object(Spam *s) { return 999; } + int int_object(int c) { return c; } +%} + diff --git a/Examples/test-suite/perl5/overload_simple_runme.pl b/Examples/test-suite/perl5/overload_simple_runme.pl index 27719aa00..624d428c6 100644 --- a/Examples/test-suite/perl5/overload_simple_runme.pl +++ b/Examples/test-suite/perl5/overload_simple_runme.pl @@ -2,7 +2,7 @@ use overload_simple; use vars qw/$DOWARN/; use strict; -use Test::More tests => 71; +use Test::More tests => 75; pass("loaded"); @@ -189,3 +189,10 @@ is(overload_simple::fid("3", 3), "fid:intint", "fid:fid(int,int)"); isnt(overload_simple::fbool(0), overload_simple::fbool(1), "fbool(bool)"); is(2, overload_simple::fbool(2), "fbool(int)"); + +# int and object overload + +is(overload_simple::int_object(1), 1, "int_object(1)"); +is(overload_simple::int_object(0), 0, "int_object(0)"); +is(overload_simple::int_object(undef), 999, "int_object(Spam*)"); +is(overload_simple::int_object($s), 999, "int_object(Spam*)"); diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index ecb1f5cd2..d89865665 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -274,8 +274,14 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_ return SWIG_OK; } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ if (!SvROK(sv)) { - *(ptr) = (void *) 0; - return SWIG_OK; + /* In Perl 5.12 and later, SVt_RV == SVt_IV, so sv could be a valid integer value. */ + if (SvIOK(sv)) { + return SWIG_ERROR; + } else { + /* NULL pointer (reference to undef). */ + *(ptr) = (void *) 0; + return SWIG_OK; + } } else { return SWIG_ERROR; }