in reply to Re^11: unintentional conversion of signaling NaN to quiet NaN
in thread unintentional conversion of signaling NaN to quiet NaN
Having drawn my silly picture of the SV, it dawned on me that Dump() ought to work properly; because the high byte of the PV address should act as the required null byte terminator for the 'string' I'm pointing it at.
So then it pointed the finger at SvPV_set() as messing with stuff other than just the pointer it purports to set; so what happens if I bypass that macro/function? The result is the code below which successfully allows you (me, on 64-bit MSVC built perl) to dump the SV with devel peek:
#! perl -slw use strict; use Config; use Inline C => Config => BUILD_NOISY => 1, CCFLAGS => $Config{ccflags +}." -DDEBUG=1"; use Inline C => <<'END_C', NAME => 'ICexample', CLEAN_AFTER_BUILD =>0 +; static const unsigned __int64 i = 0x7ff0000000000001; SV*snan3() { // Allocate a new SvPV with some junk pv data SV *ret = newSVpvn( "JustJunk", 8 ); // Assign the SNaN bit pattern directly to the NV field bypassing +any dodgy macros *(unsigned __int64*)&( ( (XPVNV*)ret->sv_any )->xnv_u.xnv_nv ) = i +; // Set the NOK flag SvNOK_on( ret ); // Now point the PV pointer directly at the NV memory so we can ac +cess it // (the NV) from perl without going through pack 'd'/'F' // once again bypassing the API. (ret)->sv_u.svu_pv = (char*)&( ( (XPVNV*)ret->sv_any )->xnv_u.xnv_ +nv ); // make it persist SvREFCNT_inc_void_NN( ret ); // Make sure noone can mess with it. SvREADONLY( ret ); return ret; } END_C use Devel::Peek; ## Get an SNAN. my $snan = snan3(); ##Print its numeric value AND its bit pattern bypassing SVNV?() printf "%f\n%x\n", $snan, unpack 'Q', $snan; ## Same thing as the printf '%x', unpack 'Q' above ## that *might* work on 32-bit that doesn't have Q print scalar reverse unpack 'h*', $snan; Dump( $snan ); __END__ C:\test>snan-ic.pl ... Finished Build Compile Stage 1.#SNAN0 7ff0000000000001 7ff0000000000001 SV = PV(0xfbf60) at 0x157bc8 REFCNT = 1 FLAGS = (PADMY,NOK,POK,pNOK,pPOK) PV = 0x3db5d68 "\1\0\0\0\0\0\360\177"\0 CUR = 8 LEN = 16
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^13: unintentional conversion of signaling NaN to quiet NaN
by syphilis (Archbishop) on Jun 28, 2016 at 03:46 UTC |