Revert rename of wcwidth() to system_wcwidth()

It's not clear whether or not `system_wcwidth()` was picked solely because of
the namespace conflict (which is easily remedied) but using the most obvious
name for this function should be the way to go.

We already have our own overload of `wcwidth()` (`fish_wcwidth()`) so it should
be more obvious which is the bare system call and which isn't.

(I do want to move this w/ some of the other standalone extern C wrappers to the
unix module later.)
This commit is contained in:
Mahmoud Al-Qudsi 2023-05-16 18:54:10 -05:00
parent 1a88c55b71
commit 3ee71772f1

View file

@ -26,16 +26,18 @@ pub static FISH_AMBIGUOUS_WIDTH: AtomicI32 = AtomicI32::new(1);
// For some reason, this is declared here and exposed here, but is set in `env_dispatch`. // For some reason, this is declared here and exposed here, but is set in `env_dispatch`.
pub static FISH_EMOJI_WIDTH: AtomicI32 = AtomicI32::new(1); pub static FISH_EMOJI_WIDTH: AtomicI32 = AtomicI32::new(1);
extern "C" { static WC_LOOKUP_TABLE: Lazy<WcLookupTable> = Lazy::new(WcLookupTable::new);
/// A safe wrapper around the system `wcwidth()` function
pub fn wcwidth(c: char) -> i32 {
extern "C" {
pub fn wcwidth(c: libc::wchar_t) -> libc::c_int; pub fn wcwidth(c: libc::wchar_t) -> libc::c_int;
} }
fn system_wcwidth(c: char) -> i32 {
const _: () = assert!(mem::size_of::<libc::wchar_t>() >= mem::size_of::<char>()); const _: () = assert!(mem::size_of::<libc::wchar_t>() >= mem::size_of::<char>());
unsafe { wcwidth(c as libc::wchar_t) } unsafe { wcwidth(c as libc::wchar_t) }
} }
static WC_LOOKUP_TABLE: Lazy<WcLookupTable> = Lazy::new(WcLookupTable::new);
// Big hack to use our versions of wcswidth where we know them to be broken, which is // Big hack to use our versions of wcswidth where we know them to be broken, which is
// EVERYWHERE (https://github.com/fish-shell/fish-shell/issues/2199) // EVERYWHERE (https://github.com/fish-shell/fish-shell/issues/2199)
pub fn fish_wcwidth(c: char) -> i32 { pub fn fish_wcwidth(c: char) -> i32 {
@ -43,7 +45,7 @@ pub fn fish_wcwidth(c: char) -> i32 {
// in the console session, but knows nothing about the capabilities of other terminal emulators // in the console session, but knows nothing about the capabilities of other terminal emulators
// or ttys. Use it from the start only if we are logged in to the physical console. // or ttys. Use it from the start only if we are logged in to the physical console.
if is_console_session() { if is_console_session() {
return system_wcwidth(c); return wcwidth(c);
} }
// Check for VS16 which selects emoji presentation. This "promotes" a character like U+2764 // Check for VS16 which selects emoji presentation. This "promotes" a character like U+2764
@ -68,7 +70,7 @@ pub fn fish_wcwidth(c: char) -> i32 {
match width { match width {
WcWidth::NonCharacter | WcWidth::NonPrint | WcWidth::Combining | WcWidth::Unassigned => { WcWidth::NonCharacter | WcWidth::NonPrint | WcWidth::Combining | WcWidth::Unassigned => {
// Fall back to system wcwidth in this case. // Fall back to system wcwidth in this case.
system_wcwidth(c) wcwidth(c)
} }
WcWidth::Ambiguous | WcWidth::PrivateUse => { WcWidth::Ambiguous | WcWidth::PrivateUse => {
// TR11: "All private-use characters are by default classified as Ambiguous". // TR11: "All private-use characters are by default classified as Ambiguous".