summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-12-11 23:15:25 -0700
committerKarl Williamson <public@khwilliamson.com>2014-01-04 13:33:06 -0700
commitf6dde82eadcc6685581969cf33932bba37fed9d1 (patch)
tree63a7aed7570e54c21f23a8e7d02fadd8bc44d3f7 /toke.c
parent90d6b40e1850c1b0849446bc02c3ffe9a376aaee (diff)
downloadperl-f6dde82eadcc6685581969cf33932bba37fed9d1.tar.gz
toke.c: Set locale for all scan_num() calls; restore instead of reset
One call of Perl_scan_num changes the locale around it. However, this function is called in several places, including from outside the file. It is better to set the locale within scan_num() at the point where it matters. And, instead of setting the locale unconditionally, it is better to change it only if it needs to be changed, and restore it to the original. Otherwise the locale can be changed to something unexpected.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/toke.c b/toke.c
index 8ac0f31fb4..f8ebf5304a 100644
--- a/toke.c
+++ b/toke.c
@@ -2407,15 +2407,7 @@ S_force_version(pTHX_ char *s, int guessing)
#endif
if (*d == ';' || isSPACE(*d) || *d == '{' || *d == '}' || !*d) {
SV *ver;
-#ifdef USE_LOCALE_NUMERIC
- char *loc = savepv(setlocale(LC_NUMERIC, NULL));
- setlocale(LC_NUMERIC, "C");
-#endif
s = scan_num(s, &pl_yylval);
-#ifdef USE_LOCALE_NUMERIC
- setlocale(LC_NUMERIC, loc);
- Safefree(loc);
-#endif
version = pl_yylval.opval;
ver = cSVOPx(version)->op_sv;
if (SvPOK(ver) && !SvNIOK(ver)) {
@@ -11330,9 +11322,11 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
floatit = TRUE;
}
if (floatit) {
+ STORE_NUMERIC_LOCAL_SET_STANDARD();
/* terminate the string */
*d = '\0';
nv = Atof(PL_tokenbuf);
+ RESTORE_NUMERIC_LOCAL();
sv = newSVnv(nv);
}