From: Ævar Arnfjörð Bjarmason Date: Sat, 27 Feb 2010 20:40:19 +0000 (+0000) Subject: Moose used an incorrect cast at the C-level resulting in errors with >2**32 IV's... X-Git-Tag: 0.50_05~4^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f1ccccdb5564d10867ffb11df17a5155999a62a;p=gitmo%2FMouse.git Moose used an incorrect cast at the C-level resulting in errors with >2**32 IV's on 32 bit systems --- diff --git a/Changes b/Changes index 1800c39..e75c32c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Mouse +0.50_05 Sat Feb 27 20:37:15 2010 + * Moose::Util::TypeConstraints + - Moose used an incorrect cast at the C-level which meant that + its idea of numbers was different from that of Perl's (and + Moose's). Notably > 2**32 Integers on 32 bit systems didn't + work. + 0.50_04 Fri Feb 26 18:57:24 2010 * All - Warnings are less noisy, as shown by example/warns.pl (gfx) diff --git a/t/900_bug/005_more_than_32_bit_int_on_32_bit_systems.t b/t/900_bug/005_more_than_32_bit_int_on_32_bit_systems.t new file mode 100644 index 0000000..2d65957 --- /dev/null +++ b/t/900_bug/005_more_than_32_bit_int_on_32_bit_systems.t @@ -0,0 +1,23 @@ +package MyInteger; +use Mouse; + +has a_int => ( + is => 'rw', + isa => 'Int', +); + +has a_num => ( + is => 'rw', + isa => 'Num', +); + +package main; +use Test::More tests => 212 * 2; + +for (my $i = 1; $i <= 10e100; $i += $i * 2) { + my $int = MyInteger->new( a_int => $i )->a_int; + cmp_ok($int, '==', $i, "Mouse groked the Int $i"); + + my $num = MyInteger->new( a_num => $i )->a_num; + cmp_ok($num, '==', $i, "Mouse groked the Num $i"); +} diff --git a/xs-src/MouseTypeConstraints.xs b/xs-src/MouseTypeConstraints.xs index 34ab1ea..a7ff390 100644 --- a/xs-src/MouseTypeConstraints.xs +++ b/xs-src/MouseTypeConstraints.xs @@ -120,13 +120,9 @@ mouse_tc_Num(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { int mouse_tc_Int(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) { assert(sv); - if(SvIOKp(sv)){ + if(SvIOKp(sv) || SvNOKp(sv)){ return TRUE; } - else if(SvNOKp(sv)){ - NV const nv = SvNVX(sv); - return nv > 0 ? (nv == (NV)(UV)nv) : (nv == (NV)(IV)nv); - } else if(SvPOKp(sv)){ int const num_type = grok_number(SvPVX(sv), SvCUR(sv), NULL); if(num_type){