Skip to content

Commit

Permalink
Port the fix for large unsigned integers.
Browse files Browse the repository at this point in the history
As @haarg demonstrated in tobyink/p5-type-tiny-xs#9,
previous "fix" breaks for large unsigned integers.

@haarg also pointed out that macro ended with "p" such as SvIOKp should be avoided,
since that check the flag for ["non-public integer values"][1], and the one without p ("SvIOK")
checks the flag for ["public integer values"][2]

[1]: https://perl5.git.perl.org/perl.git/blob/HEAD:/sv.h#l369
[2]: https://perl5.git.perl.org/perl.git/blob/HEAD:/sv.h#l364
  • Loading branch information
gugod committed Sep 4, 2019
1 parent d312930 commit 03d48ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions t/101_issues/Int.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ subtest "Int from integer literal: my \$num = 3", sub {
ok $Int->check($num), "\$num is still Int";
};

subtest "MAXUINT", sub {
my $maxuint = ~0;
ok $Int->check( $maxuint ), 'yes MAXUINT';
my $as_string = sprintf '%f', $maxuint;
ok $Int->check( $maxuint ), 'yes MAXUINT after use as float';
};

done_testing;
10 changes: 5 additions & 5 deletions xs-src/MouseTypeConstraints.xs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ S_nv_is_integer(pTHX_ NV const nv) {
int
mouse_tc_Int(pTHX_ SV* const data PERL_UNUSED_DECL, SV* const sv) {
assert(sv);
if(SvPOKp(sv)){
if(SvPOK(sv)){
int const num_type = grok_number(SvPVX(sv), SvCUR(sv), NULL);
return num_type && !(num_type & IS_NUMBER_NOT_INT);
}
else if(SvNOKp(sv)) {
return S_nv_is_integer(aTHX_ SvNVX(sv));
}
else if(SvIOKp(sv)){
else if(SvIOK(sv)){
return TRUE;
}
else if(SvNOK(sv)) {
return S_nv_is_integer(aTHX_ SvNVX(sv));
}
return FALSE;
}

Expand Down

0 comments on commit 03d48ef

Please sign in to comment.