diff options
author | TAKAI Kousuke <62541129+t-a-k@users.noreply.github.com> | 2022-03-04 23:32:27 +0900 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2022-03-05 12:00:47 -0700 |
commit | def4fa880cb6467a2ba7fe51736a46f05e5e2d79 (patch) | |
tree | 42f24d541f776974ed12c7e872ba80678c4e0e21 /ext/XS-APItest | |
parent | b4603d09e3b40cd371926f222a143c4adf8a7a38 (diff) | |
download | perl-def4fa880cb6467a2ba7fe51736a46f05e5e2d79.tar.gz |
Add test for the previous commit fixing Perl_my_strtod
Perl core itself seems not to call my_strtod, so test it with XS::APItest.
Diffstat (limited to 'ext/XS-APItest')
-rw-r--r-- | ext/XS-APItest/numeric.xs | 15 | ||||
-rw-r--r-- | ext/XS-APItest/t/my_strtod.t | 16 |
2 files changed, 31 insertions, 0 deletions
diff --git a/ext/XS-APItest/numeric.xs b/ext/XS-APItest/numeric.xs index 847eb75d7c..fb5073272f 100644 --- a/ext/XS-APItest/numeric.xs +++ b/ext/XS-APItest/numeric.xs @@ -59,3 +59,18 @@ grok_atoUV(number, endsv) PUSHs(sv_2mortal(newSViv(0))); } } + +void +my_strtod(s) + SV *s + PREINIT: + SV *sv = newSVsv(s); + char *endptr = NULL; + NV nv; + PPCODE: + nv = my_strtod(SvPV_force_nolen(sv), &endptr); + PUSHs(sv_2mortal(newSVnv(nv))); + if (endptr) { + sv_chop(sv, endptr); + PUSHs(sv_2mortal(sv)); + } diff --git a/ext/XS-APItest/t/my_strtod.t b/ext/XS-APItest/t/my_strtod.t new file mode 100644 index 0000000000..d38c149d40 --- /dev/null +++ b/ext/XS-APItest/t/my_strtod.t @@ -0,0 +1,16 @@ +#!perl -w +use strict; + +use Test::More; +use Config; +use XS::APItest; + +my ($nv, $rest); + +# GH 19492 - d_strtod=undef build segfaults here +($nv, $rest) = my_strtod('17.265625x'); +# Note that .265625 is 17/64 so it can be represented exactly +is($nv, 17.265625, 'my_strtod("17.265625x", &e) returns 17.265625'); +is($rest, 'x', 'my_strtod("17.265625x", &e) sets e to "x"'); + +done_testing(); |