Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: [XS] Weird behaviour on some Linux systems

by syphilis (Bishop)
on Oct 10, 2019 at 13:35 UTC ( #11107307=note: print w/replies, xml ) Need Help??


in reply to Re: [XS] Weird behaviour on some Linux systems
in thread [XS] Weird behaviour on some Linux systems

Thanks for the quick feedback, Corion ... not so sure that you're on the right track, but I certainly can't prove otherwise.

Here's a clearer demo that contains only one instance of "sprintf", and no occurrences of "printf":
use strict; use warnings; use Devel::Peek; use Inline C => Config => BUILD_NOISY => 1, ; use Inline C => <<'EOC'; SV * foo(SV * arg) { SV * keysv; keysv = NEWSV(0, 32); /* Make sure arg is an NV */ if(!SvNOK(arg)) croak("Not a valid arg passed to foo for this demo") +; sv_setpvf(keysv, "%.19" NVgf, SvNV(arg)); return keysv; } SV * bar(SV * arg) { SV * keysv; char buff[30]; keysv = NEWSV(0, 32); /* Make sure arg is an NV */ if(!SvNOK(arg)) croak("Not a valid arg passed to bar for this demo" +); sprintf(buff, "%.19" NVgf, SvNV(arg)); sv_setpvf(keysv, "%s", buff); return keysv; } EOC my $sv_foo = foo(2 ** 63); my $sv_bar = bar(2 ** 63); Dump $sv_foo; print "#####################\n"; Dump $sv_bar;
On Windows 7 it produces (sanely, IMO):
SV = PV(0x72be48) at 0x39bfb8 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x33b748 "9223372036854775808"\0 CUR = 19 LEN = 34 ##################### SV = PV(0x72be98) at 0x33c638 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x33b8d8 "9223372036854775808"\0 CUR = 19 LEN = 34
On Ubuntu-18.04 I see the (insane) output of:
SV = PV(0x56545ac36fd0) at 0x56545ac5b728 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x56545ac57170 "9.2233720368547758e+18"\0 CUR = 22 LEN = 34 ##################### SV = PV(0x56545ac37070) at 0x56545acb8178 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x56545b64be20 "9223372036854775808"\0 CUR = 19 LEN = 34
Interestingly, on Ubuntu, it's the XSub containing the "sprintf" call that's producing the sane result.
(At least, it's producing the output that I expect and want ;-)

Cheers,
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11107307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-01-23 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?