From bc8ec7cc020d0562094a551b280fd3f32bf5eb04 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 11 Dec 2013 16:25:02 -0700 Subject: [PATCH] PATCH: [perl #120723] Setting LC_NUMERIC breaks parsing of constants This is the final patch for [perl #120723], and adds tests for it. LC_NUMERIC Locale handling was broken for code during the compilation phase, such as BEGIN {} blocks. This is because, for some reason, perl.c set LC_NUMERIC unconditionally back to the C locale right after locale initialization. I suspect that was to allow the core's parsing to not be affected by locale. However, earlier commits in this series have added code to change/restore the locale during sections of the parsing where this might matter, so this setting to the C locale is not needed. --- perl.c | 1 - t/run/locale.t | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/perl.c b/perl.c index f0bfac1..5590761 100644 --- a/perl.c +++ b/perl.c @@ -254,7 +254,6 @@ perl_construct(pTHXx) STATUS_ALL_SUCCESS; init_i18nl10n(1); - SET_NUMERIC_STANDARD(); #if defined(LOCAL_PATCH_COUNT) PL_localpatches = local_patches; /* For possible -v */ diff --git a/t/run/locale.t b/t/run/locale.t index d61fbb9..63a6973 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -48,6 +48,9 @@ fresh_perl_is("for (qw(@locales)) {\n" . <<'EOF', EOF "", {}, "no locales where LC_NUMERIC breaks"); +{ + local $ENV{LC_NUMERIC}; + local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC fresh_perl_is("for (qw(@locales)) {\n" . <<'EOF', use POSIX qw(locale_h); use locale; @@ -57,8 +60,8 @@ fresh_perl_is("for (qw(@locales)) {\n" . <<'EOF', print "$_ $s\n"; } EOF - "", {}, "LC_NUMERIC without setlocale() has no effect in any locale"); - + "", {}, "LC_NUMERIC without environment nor setlocale() has no effect in any locale"); +} # try to find out a locale where LC_NUMERIC makes a difference my $original_locale = setlocale(LC_NUMERIC); @@ -194,6 +197,33 @@ EOF "sprintf() and printf() look at LC_NUMERIC regardless of constant folding"); } + for ($different) { + local $ENV{LC_NUMERIC} = $_; + local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC + fresh_perl_is(<<"EOF", + use POSIX qw(locale_h); + + BEGIN { setlocale(LC_NUMERIC, \"$_\"); }; + setlocale(LC_ALL, "C"); + use 5.008; + print setlocale(LC_NUMERIC); +EOF + "C", { }, + "No compile error on v-strings when setting the locale to non-dot radix at compile time when default environment has non-dot radix"); + } + + for ($different) { + local $ENV{LC_NUMERIC} = $_; + local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC + fresh_perl_is(<<"EOF", + use POSIX qw(locale_h); + + BEGIN { print setlocale(LC_NUMERIC), "\n"; }; +EOF + $_, { }, + "Passed in LC_NUMERIC is valid at compilation time"); + } + unless ($comma) { skip("no locale available where LC_NUMERIC is a comma", 2); } @@ -240,4 +270,4 @@ EOF } # SKIP -sub last { 13 } +sub last { 15 } -- 2.7.4