From 5eebeff5a95a75c2d7a647883fd12ad15a910cb7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 24 Oct 2025 22:41:39 +0200 Subject: [PATCH] Retire our "use-LC_NUMERIC-internally" workaround Commit 8dc3982408d (Always use LC_NUMERIC=C internally (#8204), 2021-10-13) made us use LC_NUMERIC=C internally, to make C library functions behave in a predictable way. We no longer use library functions affected by LC_NUMERIC[*].. Since the effective value of LC_NUMERIC no longer matters, let's simplify things by using the user locale again, like we do for the other locale variables. The printf crate still uses libc::snprintf() which respects LC_NUMERIC, but it looks like "cargo test" creates a separate process per crate, and the printf crate does not call setlocale(). --- src/env_dispatch.rs | 5 ----- src/locale.rs | 12 +----------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index ff1812ddc..fd8bcc881 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -534,11 +534,6 @@ fn init_locale(vars: &EnvStack) { loc }; - // We *always* use a C-locale for numbers because we want '.' (except for in printf). - let loc_ptr = unsafe { libc::setlocale(libc::LC_NUMERIC, c"C".as_ptr()) }; - // should never fail, the C locale should always be defined - assert_ne!(loc_ptr, ptr::null_mut()); - // Update cached locale information. crate::common::fish_setlocale(); FLOG!( diff --git a/src/locale.rs b/src/locale.rs index 300b0d1d7..2fd1fa555 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -108,18 +108,8 @@ unsafe fn read_locale() -> Option { // Bleh, we have to go through localeconv, which races with setlocale. // TODO: There has to be a better way to do this. let _guard = LOCALE_LOCK.lock().unwrap(); - - unsafe { - libc::setlocale(libc::LC_NUMERIC, c"".as_ptr()); - } - let lconv = unsafe { libc::localeconv() }; - let result = (!lconv.is_null()).then(|| unsafe { lconv_to_locale(&*lconv) }); - // Note we *always* use a C-locale for numbers, because we always want "." except for in printf. - unsafe { - libc::setlocale(libc::LC_NUMERIC, c"C".as_ptr()); - } - result + (!lconv.is_null()).then(|| unsafe { lconv_to_locale(&*lconv) }) } // Current numeric locale.