diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 5ccae2ca1..07c9b3e44 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -223,11 +223,6 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st int retval = STATUS_CMD_OK; te_error_t error; - // Switch locale while computing stuff. - // This means that the "." is always the radix character, - // so numbers work the same across locales. - char *saved_locale = strdup(setlocale(LC_NUMERIC, nullptr)); - setlocale(LC_NUMERIC, "C"); double v = te_interp(expression.c_str(), &error); if (error.position == 0) { @@ -257,8 +252,6 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ", L"^"); retval = STATUS_CMD_ERROR; } - setlocale(LC_NUMERIC, saved_locale); - free(saved_locale); return retval; } diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index ffe9f0efe..8413d8530 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -24,6 +24,7 @@ // This version has been altered and ported to C++ for inclusion in fish. #include "tinyexpr.h" +#include "wutil.h" #include #include @@ -250,7 +251,7 @@ static void next_token(state *s) { /* Try reading a number. */ if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') { - s->value = wcstod(s->next, const_cast(&s->next)); + s->value = wcstod_l(s->next, const_cast(&s->next), fish_c_locale()); s->type = TOK_NUMBER; } else { /* Look for a function call. */