-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type::Tiny::XS identifies non-ints as ints #8
Comments
Also, it's possible that some of those versions don't have
And the dev who ran the above confirmed that it appears to be related to |
I've reported on Twitter that with Perl versions 5.10, 16, 20, 22, 24, 26, 28, 30 from Dockerhub I get 'No / No / 3.14'. But when I install Type::Tiny::XS the result is 'No / Yes / 3.14' on all of them. |
Interesting. Pretty sure I stole the Int check from Mouse's XS, so I do wonder if the same bug exists there. Anybody got any thoughts about the best way to do an int check in XS code? |
Not sure, sorry. You might be able to do this: int is_IV(SV * maybe_num) {
if(!SvIOK(maybe_num)) return 0;
// extra logic here, but a naïve return 1 works
// if SvIOK really checks if it's an int (see below)
} But I suspect that might return true if the |
Update: I've posted to P5P asking for help. Dave Mitchell and demerphq have been discussing this prior to that. Hopefully something will come from that. |
I tried stealing code from the latest Mouse release, but that seems even worse, allowing |
This really should not be checking the
|
Actually, that would allow through some strings like
This is basically the same as what is in the released version, except not using the |
I'm actually surprised that SV containing |
I've pushed out 0.015 which fixes the reported issue and doesn't seem to cause any other problems. Whether or not Type::Tiny::XS should be checking the p flags is an issue for another day. |
This is originally identified by @Ovid as a bug in Type::Tiny::XS: If I call int($num) on a floating point number, that number is subsequently identified as an integer, even when it's not. I suspected this is because the pIOK flag is set, but this might be a red herring (more later). Here's sample code which fails on every version (even .001) of Type:Tiny::XS that I've tested. See: tobyink/p5-type-tiny-xs#8 But it turns out it is also reproducble with Mouse::XS -- not with Mouse::PurePerl though.
0.016 2019-09-05 [ Bug Fixes ] - Fix Int check on large unsigned integers. Graham Knop++ <tobyink/p5-type-tiny-xs#9> 0.015 2019-09-03 [ Bug Fixes ] - Casting a non-integer number to an integer elsewhere mistakenly caused the Int check to think the non-integer was an integer. Curtis "Ovid" Poe++ <tobyink/p5-type-tiny-xs#8>
0.016 2019-09-05 [ Bug Fixes ] - Fix Int check on large unsigned integers. Graham Knop++ <tobyink/p5-type-tiny-xs#9> 0.015 2019-09-03 [ Bug Fixes ] - Casting a non-integer number to an integer elsewhere mistakenly caused the Int check to think the non-integer was an integer. Curtis "Ovid" Poe++ <tobyink/p5-type-tiny-xs#8>
If I call
int($num)
on a floating point number, that number is subsequently identified as an integer, even when it's not. I suspected this is because thepIOK
flag is set, but this might be a red herring (more later). Here's sample code which fails on every version (even.001
) ofType:Tiny::XS
that I've tested.This code replicates the issue:
And the output:
And I suspect this is the cause of the same
int
bug reported by Peter Mottram. However, all versions of Perl we've tested havepIOK
set and this might be a red herring.I found the problem in a large codebase and reduced it to this:
On my box, that shows:
But one of our developers did this:
So I also asked my Twitter followers to run that
Types::Standard
snippet and they received similarly inconsistent results.So I don't know what's causing it, but at least I have a small test case for you in the first code snippet I posted above. I hope it helps because this is a serious issue in our current codebase.
The text was updated successfully, but these errors were encountered: