Last active
December 31, 2015 13:18
-
-
Save run4flat/7991591 to your computer and use it in GitHub Desktop.
Weird XSness fails to fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ToTest; | |
use 5.008_008; | |
use strict; | |
use warnings; | |
our $VERSION = '0.01'; | |
require XSLoader; | |
XSLoader::load('ToTest', $VERSION); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "EXTERN.h" | |
#include "perl.h" | |
#include "XSUB.h" | |
#include "ppport.h" | |
MODULE = ToTest PACKAGE = ToTest | |
void | |
check_float_stuff(SV * constant_SV) | |
PROTOTYPE: $ | |
PREINIT: | |
float real_const, constant; | |
double constant_d; | |
CODE: | |
real_const = atof(SvPV_nolen(constant_SV)); | |
printf("The string interpretation of constant_SV is %s; the floating point is %f\n", | |
SvPV_nolen(constant_SV), SvNV_nomg(constant_SV)); | |
constant = (float) SvNV_nomg(constant_SV); | |
constant_d = SvNV_nomg(constant_SV); | |
printf(" -> when cast to a float, we have %f; to a double, %f\n", constant, constant_d); | |
printf(" -> when directly printed as %%f: %f\n", SvNV(constant_SV)); | |
printf(" -> real_constant is %f\n", real_const); | |
sv_dump(constant_SV); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use ToTest; | |
ToTest::check_float_stuff(5); | |
ToTest::check_float_stuff(0.25); |
Perl v5.18.1, ExtUtils::nvcc as the compiler, Debian:
perl -Mblib test-xs.pl
The string interpretation of constant_SV is 5; the floating point is 5.000000
-> when cast to a float, we have 0.000000; to a double, 0.000000
-> when directly printed as %f: 0.000000
-> real_constant is 5.000000
SV = PVNV(0x876bfc0) at 0x86ed308
REFCNT = 1
FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK)
IV = 5
NV = 5
PV = 0x86e7f30 "5"\0
CUR = 1
LEN = 12
The string interpretation of constant_SV is 0.25; the floating point is 0.000000
-> when cast to a float, we have 0.000000; to a double, 0.000000
-> when directly printed as %f: 0.000000
-> real_constant is 0.250000
SV = PVNV(0x876bfd4) at 0x86ed298
REFCNT = 1
FLAGS = (NOK,POK,READONLY,pNOK,pPOK)
IV = 0
NV = 0.25
PV = 0x8784238 "0.25"\0
CUR = 4
LEN = 36
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perl v5.18.1, g++, Debian: