diff options
author | Karl Williamson <khw@cpan.org> | 2014-06-01 14:05:48 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-06-05 11:23:00 -0600 |
commit | 4c28b29c7a1549f173177cdf69e91cc1acaa0969 (patch) | |
tree | 2e0acd888a404f38bc67ab77542b2e82e74615e7 /ext | |
parent | c5a7e38ee268d066630473beab3ef7aca53fd728 (diff) | |
download | perl-4c28b29c7a1549f173177cdf69e91cc1acaa0969.tar.gz |
Keep LC_NUMERIC in C locale, except for brief periods
This is for XS modules, so they don't have to worry about the radix
being a non-dot. When the locale needs to be in the underlying one, the
operation should be wrapped using macros for the purpose. That API may
change as we gain experience in 5.21, so I'm not including it now.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/XS-APItest/APItest.xs | 15 | ||||
-rw-r--r-- | ext/XS-APItest/t/locale.t | 35 |
2 files changed, 50 insertions, 0 deletions
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 31724f981f..a692c519da 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -4796,3 +4796,18 @@ test_toTITLE_utf8(SV * p) RETVAL = av; OUTPUT: RETVAL + +SV * +test_Gconvert(SV * number, SV * num_digits) + PREINIT: + char buffer[100]; + int len; + CODE: + len = (int) SvIV(num_digits); + if (len > 99) croak("Too long a number for test_Gconvert"); + PERL_UNUSED_RESULT(Gconvert(SvNV(number), len, + 0, /* No trailing zeroes */ + buffer)); + RETVAL = newSVpv(buffer, 0); + OUTPUT: + RETVAL diff --git a/ext/XS-APItest/t/locale.t b/ext/XS-APItest/t/locale.t new file mode 100644 index 0000000000..900fe74621 --- /dev/null +++ b/ext/XS-APItest/t/locale.t @@ -0,0 +1,35 @@ +BEGIN { + require '../../t/test.pl'; + require '../../t/loc_tools.pl'; # to find locales +} + +use XS::APItest; + +BEGIN { + eval { require POSIX; POSIX->import("locale_h") }; + if ($@) { + skip_all("could not load the POSIX module"); # running minitest? + } +} + +my @locales = eval { find_locales( &LC_NUMERIC ) }; +skip_all("no locales available") unless @locales; + +my $non_dot_locale; +for (@locales) { + use locale; + setlocale(LC_NUMERIC, $_) or next; + my $in = 4.2; # avoid any constant folding bugs + if (sprintf("%g", $in) ne "4.2") { + $non_dot_locale = $_; + last; + } +} + +skip_all("no non-dot radix locales available") unless $non_dot_locale; + +plan tests => 2; + +is(test_Gconvert(4.179, 2), "4.2", "Gconvert doesn't recognize underlying locale outside 'use locale'"); +use locale; +is(test_Gconvert(4.179, 2), "4.2", "Gconvert doesn't recognize underlying locale inside 'use locale'"); |