Skip Menu |

This queue is for tickets about the Type-Tiny-XS CPAN distribution.

Report information
The Basics
Id: 130420
Status: resolved
Priority: 0/
Queue: Type-Tiny-XS

People
Owner: Nobody in particular
Requestors: ovid [...] cpan.org
SYSPETE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.001
  • 0.002
  • 0.003
  • 0.004
  • 0.005
  • 0.005-retry
  • 0.006
  • 0.006-retry
  • 0.007
  • 0.008
  • 0.009
  • 0.010
  • 0.011
  • 0.012
  • 0.013
  • 0.014
Fixed in: (no value)



Subject: Int type check can pass non-integer values
v0.009 does not display this behaviour but 0.010 and greater all do with all Perl versions I have tested so far. Problem does not exist with PP Type::Tiny. We have a GH ticket tracking this issue as it hit us in the Interchange6 project: https://github.com/interchange/Interchange6/issues/28 I must apologise that I haven't been able to repeat the following problem as a standalone test case. Here's the ugly workaround I've implemented which stringifies the value before testing it: https://github.com/interchange/Interchange6/blob/master/lib/Interchange6/Cart/Product.pm#L152-L166 Unit testing of our Cart::Product class does *not* have this problem as per this test: https://github.com/interchange/Interchange6/blob/master/t/unit/cart_product.t#L151 but when quantity is set via the writer method from a method in our Cart class here: https://github.com/interchange/Interchange6/blob/master/lib/Interchange6/Cart.pm#L487 then corresponding failing test (assuming Cart::Product quantity attribute isa is reset to simple 'PositiveInt'): https://github.com/interchange/Interchange6/blob/master/t/unit/cart.t#L349-L355 I'm willing to help debug as much as I am able though right now I don't have a clue where to start. R. PeteM
Added 2.3 to the test cases. Not much else I can do without more info. https://github.com/tobyink/p5-type-tiny-xs/commit/08b61cca8d0963b503b05db36af217ec76523b2b
On 2017-05-28 12:30:37, TOBYINK wrote: Show quoted text
> Added 2.3 to the test cases. Not much else I can do without more info. > > https://github.com/tobyink/p5-type-tiny- > xs/commit/08b61cca8d0963b503b05db36af217ec76523b2b
Looks like the cause was found -- the pIOK flag is being used but that flag's value can change as a side effect of calling int() (and it's internal/undocumented.. #p5p discussion suggests that XS code should not be looking at it).
Subject: Type::Tiny::XS identifies non-ints as ints
Originally reported on Github (https://github.com/tobyink/p5-type-tiny-xs/issues/8), but I think that's not where you want reports. I'm unsure. 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. This code replicates the issue: #!/usr/bin/env perl use Test::More; use Type::Tiny::XS; use Devel::Peek; diag $Type::Tiny::XS::VERSION; my $num = 3.14; Dump($num); ok !Type::Tiny::XS::Int($num), "$num should not be an integer"; Dump($num); { no warnings; int($num); } Dump($num); ok !Type::Tiny::XS::Int($num), "$num should not be an integer"; Dump($num); done_testing; And the output: type_tiny.t .. # 0.014 SV = NV(0x7fb6e4903088) at 0x7fb6e49030a0 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 3.14 ok 1 - 3.14 should not be an integer not ok 2 - 3.14 should not be an integer SV = PVNV(0x7fb6e48027f0) at 0x7fb6e49030a0 REFCNT = 1 FLAGS = (NOK,pNOK) IV = 0 NV = 3.14 PV = 0x7fb6e45df090 "3.14"\0 CUR = 4 LEN = 32 SV = PVNV(0x7fb6e48027f0) at 0x7fb6e49030a0 REFCNT = 1 FLAGS = (NOK,pIOK,pNOK) IV = 3 NV = 3.14 PV = 0x7fb6e45df090 "3.14"\0 CUR = 4 LEN = 32 # Failed test '3.14 should not be an integer' # at type_tiny.t line 16. SV = PVNV(0x7fb6e48027f0) at 0x7fb6e49030a0 REFCNT = 1 FLAGS = (NOK,pIOK,pNOK) IV = 3 NV = 3.14 PV = 0x7fb6e45df090 "3.14"\0 CUR = 4 LEN = 32 1..2 # Looks like you failed 1 test of 2. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/2 subtests And I suspect this is the cause of the same int bug reported by Peter Mottram. However, all versions of Perl we've tested have pIOK set and this might be a red herring. I found the problem in a large codebase and reduced it to this: perl -MTypes::Standard=is_Int -E \ 'my $num = 3.14; say is_Int($num)?"Yes":"No"; int($num); say is_Int($num)?"Yes":"No";say $num' On my box, that shows: No Yes 3.14 The code appears to be correct when we use the PP version of Type::Tiny, but is incorrect with the XS version.
Fixed in 0.015.