summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/POSIX/POSIX.xs3
-rw-r--r--ext/POSIX/lib/POSIX.pm2
-rw-r--r--perl.h6
-rw-r--r--t/run/locale.t17
4 files changed, 25 insertions, 3 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 3e77eb4483..08e459c8a9 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1482,7 +1482,7 @@ strtod(str)
double num;
char *unparsed;
PPCODE:
- SET_NUMERIC_LOCAL();
+ STORE_NUMERIC_STANDARD_FORCE_LOCAL();
num = strtod(str, &unparsed);
PUSHs(sv_2mortal(newSVnv(num)));
if (GIMME == G_ARRAY) {
@@ -1492,6 +1492,7 @@ strtod(str)
else
PUSHs(&PL_sv_undef);
}
+ RESTORE_NUMERIC_STANDARD();
void
strtol(str, base = 0)
diff --git a/ext/POSIX/lib/POSIX.pm b/ext/POSIX/lib/POSIX.pm
index 0dd8475eaf..d0bc3fd065 100644
--- a/ext/POSIX/lib/POSIX.pm
+++ b/ext/POSIX/lib/POSIX.pm
@@ -4,7 +4,7 @@ use warnings;
our ($AUTOLOAD, %SIGRT);
-our $VERSION = '1.37';
+our $VERSION = '1.38';
require XSLoader;
diff --git a/perl.h b/perl.h
index c777b1bb3c..b6e0c3eb28 100644
--- a/perl.h
+++ b/perl.h
@@ -5288,6 +5288,12 @@ typedef struct am_table_short AMTS;
bool was_standard = PL_numeric_standard && IN_SOME_LOCALE_FORM; \
if (was_standard) SET_NUMERIC_LOCAL();
+/* Rarely, we want to change to the underlying locale even outside of 'use
+ * locale'. This is principally in the POSIX:: functions */
+#define STORE_NUMERIC_STANDARD_FORCE_LOCAL() \
+ bool was_standard = PL_numeric_standard; \
+ if (was_standard) SET_NUMERIC_LOCAL();
+
#define RESTORE_NUMERIC_LOCAL() \
if (was_local) SET_NUMERIC_LOCAL();
diff --git a/t/run/locale.t b/t/run/locale.t
index d4419caa39..d61fbb9a98 100644
--- a/t/run/locale.t
+++ b/t/run/locale.t
@@ -20,6 +20,7 @@ BEGIN {
}
use Config;
my $have_setlocale = $Config{d_setlocale} eq 'define';
+my $have_strtod = $Config{d_strtod} eq 'define';
$have_setlocale = 0 if $@;
# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
# and mingw32 uses said silly CRT
@@ -221,8 +222,22 @@ EOF
print \$i, "\n";
EOF
"1,5\n2,5", {}, "Can do math when radix is a comma"); # [perl 115800]
+
+ unless ($have_strtod) {
+ skip("no strtod()", 1);
+ }
+ else {
+ fresh_perl_is(<<"EOF",
+ use POSIX;
+ POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma");
+ my \$one_point_5 = POSIX::strtod("1,5");
+ \$one_point_5 =~ s/0+\$//; # Remove any trailing zeros
+ print \$one_point_5, "\n";
+EOF
+ "1.5", {}, "POSIX::strtod() uses underlying locale");
+ }
}
} # SKIP
-sub last { 12 }
+sub last { 13 }