simplify, and fix, setting the current locale

Fix test setup bogosities. Specifically, they weren't hermetic with respect to
locale env vars.

Rewrite the handling of locale vars to simplify the code and make it more like
the pattern most programs employ.

Fixes #3110
This commit is contained in:
Kurtis Rader
2016-06-03 19:05:13 -07:00
parent 32a585a52b
commit 0b385f145c
8 changed files with 77 additions and 87 deletions

View File

@@ -197,24 +197,6 @@ static int octal_to_bin(wchar_t c) {
}
}
double C_STRTOD(wchar_t const *nptr, wchar_t **endptr) {
double r;
const wcstring saved_locale = wsetlocale(LC_NUMERIC, NULL);
if (!saved_locale.empty()) {
wsetlocale(LC_NUMERIC, L"C");
}
r = wcstod(nptr, endptr);
if (!saved_locale.empty()) {
wsetlocale(LC_NUMERIC, saved_locale.c_str());
}
return r;
}
void builtin_printf_state_t::fatal_error(const wchar_t *fmt, ...) {
// Don't error twice.
if (early_exit) return;
@@ -283,7 +265,12 @@ uintmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
template <>
long double raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
return C_STRTOD(s, end);
// Forcing the locale to C is questionable but it's what the old C_STRTOD() that I inlined here
// as part of changing how locale management is done by fish.
char * old_locale = setlocale(LC_NUMERIC, "C");
double val = wcstod(s, end);
setlocale(LC_NUMERIC, old_locale);
return val;
}
template <typename T>