mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 05:41:16 -03:00
Retire our "use-LC_NUMERIC-internally" workaround
Commit 8dc3982408 (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().
This commit is contained in:
@@ -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!(
|
||||
|
||||
@@ -108,18 +108,8 @@ unsafe fn read_locale() -> Option<Locale> {
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user