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 |