Given the pretty CPAN Testers Christmas Tree, especially in the *BSD columns, I learned that not all 32-bit perls are created equal. After some more debug, I was able to show that it was those 32-bit perls with $Config{ivsize}==4 (32bit integers; aka perl -V:ivsize) that were failing, but those with $Config{ivsize}==8 (64bit integers in 32bit perl) would pass.
I had assumed (without looking) that the default ivsize on the 32bit perl was 4 bytes (32 bits), so thought that I had already tested and verified my IV weren't overflowing (or, if they were, they were promoting to NV). After seeing the problem, I discovered that when using left-shift, it would go from IV to NV... but it didn't. However, *=2 did promote the way I expected:
<berrybrew use perl-5.12.3_32> C:\Users\Peter>perl -MDevel::Peek -lE "$iv=1<<30; for(1..3) { Dump $iv +; $iv<<=1; }" SV = IV(0x68fc28) at 0x68fc2c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1073741824 SV = IV(0x68fc28) at 0x68fc2c REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 2147483648 SV = IV(0x68fc28) at 0x68fc2c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 <berrybrew use perl-5.12.3_32> C:\Users\Peter>perl -MDevel::Peek -lE "$iv=1<<30; for(1..3) { Dump $iv +; $iv*=2; }" SV = IV(0x24dfbe0) at 0x24dfbe4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1073741824 SV = IV(0x24dfbe0) at 0x24dfbe4 REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 2147483648 SV = PVNV(0x7ea464) at 0x24dfbe4 REFCNT = 1 FLAGS = (NOK,pNOK) IV = -2147483648 NV = 4294967296 PV = 0 <berrybrew use perl-5.12.3_32> C:\Users\Peter>perl -V:ivsize ivsize='4';
Conclusion: when doing a testing suite across versions, it's not always enough to just have a "32bit perl"; especially if you are dependent on integer sizes, also check that your test suite includes multiple ivsize values.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lesson Learned: not all 32b perls are created equal
by ikegami (Patriarch) on Sep 30, 2017 at 21:43 UTC | |
by pryrt (Abbot) on Sep 30, 2017 at 22:14 UTC |