mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Replace a bunch of from_ffi with as_wstr calls
from_ffi copies a CxxWString into a new Rust WString, but as_wstr simply gets the slice of chars directly. Too many string types!
This commit is contained in:
parent
971d257e67
commit
ead329db60
7 changed files with 26 additions and 35 deletions
|
@ -4,11 +4,8 @@ use std::{
|
|||
sync::{Arc, Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
use crate::wchar::{wstr, WString};
|
||||
use crate::{
|
||||
wchar::L,
|
||||
wchar_ffi::{WCharFromFFI, WCharToFFI},
|
||||
};
|
||||
use crate::wchar::{wstr, WString, L};
|
||||
use crate::wchar_ffi::{AsWstr, WCharFromFFI, WCharToFFI};
|
||||
use cxx::CxxWString;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
@ -353,14 +350,14 @@ impl AbbreviationSet {
|
|||
/// \return the list of replacers for an input token, in priority order, using the global set.
|
||||
/// The \p position is given to describe where the token was found.
|
||||
fn abbrs_match_ffi(token: &CxxWString, position: abbrs_position_t) -> Vec<abbrs_replacer_t> {
|
||||
with_abbrs(|set| set.r#match(&token.from_ffi(), position.into()))
|
||||
with_abbrs(|set| set.r#match(token.as_wstr(), position.into()))
|
||||
.into_iter()
|
||||
.map(|r| r.into())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn abbrs_has_match_ffi(token: &CxxWString, position: abbrs_position_t) -> bool {
|
||||
with_abbrs(|set| set.has_match(&token.from_ffi(), position.into()))
|
||||
with_abbrs(|set| set.has_match(token.as_wstr(), position.into()))
|
||||
}
|
||||
|
||||
fn abbrs_list_ffi() -> Vec<abbreviation_t> {
|
||||
|
@ -429,7 +426,7 @@ impl<'a> GlobalAbbrs<'a> {
|
|||
}
|
||||
|
||||
fn erase(&mut self, name: &CxxWString) {
|
||||
self.g.erase(&name.from_ffi());
|
||||
self.g.erase(name.as_wstr());
|
||||
}
|
||||
}
|
||||
use crate::ffi_tests::add_test;
|
||||
|
|
|
@ -25,7 +25,7 @@ use crate::tokenizer::{
|
|||
};
|
||||
use crate::wchar::{wstr, WString, L};
|
||||
use crate::wchar_ext::WExt;
|
||||
use crate::wchar_ffi::{wcharz, wcharz_t, WCharFromFFI, WCharToFFI};
|
||||
use crate::wchar_ffi::{wcharz, wcharz_t, AsWstr, WCharToFFI};
|
||||
use crate::wutil::printf::sprintf;
|
||||
use crate::wutil::wgettext_fmt;
|
||||
use cxx::{type_id, ExternType};
|
||||
|
@ -4387,7 +4387,7 @@ impl Ast {
|
|||
Box::new(NodeFfi::new(self.top.as_node()))
|
||||
}
|
||||
fn dump_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.dump(&orig.from_ffi()).to_ffi()
|
||||
self.dump(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4398,7 +4398,7 @@ fn ast_parse_ffi(src: &CxxWString, flags: u8, errors: *mut ParseErrorList) -> Bo
|
|||
Some(unsafe { &*errors }.clone())
|
||||
};
|
||||
let ast = Box::new(Ast::parse(
|
||||
&src.from_ffi(),
|
||||
&src.as_wstr(),
|
||||
ParseTreeFlags(flags),
|
||||
&mut out_errors,
|
||||
));
|
||||
|
@ -4419,7 +4419,7 @@ fn ast_parse_argument_list_ffi(
|
|||
Some(unsafe { &*errors }.clone())
|
||||
};
|
||||
let ast = Box::new(Ast::parse_argument_list(
|
||||
&src.from_ffi(),
|
||||
&src.as_wstr(),
|
||||
ParseTreeFlags(flags),
|
||||
&mut out_errors,
|
||||
));
|
||||
|
@ -4518,28 +4518,28 @@ impl<'a> NodeFfi<'a> {
|
|||
self.as_node().source_range()
|
||||
}
|
||||
fn source_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.as_node().source(&orig.from_ffi()).to_ffi()
|
||||
self.as_node().source(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
|
||||
impl Argument {
|
||||
fn source_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.source(&orig.from_ffi()).to_ffi()
|
||||
self.source(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
impl VariableAssignment {
|
||||
fn source_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.source(&orig.from_ffi()).to_ffi()
|
||||
self.source(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
impl String_ {
|
||||
fn source_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.source(&orig.from_ffi()).to_ffi()
|
||||
self.source(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
impl TokenRedirection {
|
||||
fn source_ffi(&self, orig: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.source(&orig.from_ffi()).to_ffi()
|
||||
self.source(orig.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ use crate::builtins::shared::{
|
|||
use crate::ffi::parser_t;
|
||||
use crate::ffi::path_get_paths_ffi;
|
||||
use crate::wchar::{wstr, WString, L};
|
||||
use crate::wchar_ffi::WCharFromFFI;
|
||||
use crate::wchar_ffi::WCharToFFI;
|
||||
use crate::wchar_ffi::{WCharFromFFI, WCharToFFI};
|
||||
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
|
||||
use crate::wutil::sprintf;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
ffi::parser_t,
|
||||
path::path_apply_working_directory,
|
||||
wchar::{wstr, WExt, L},
|
||||
wchar_ffi::WCharFromFFI,
|
||||
wchar_ffi::AsWstr,
|
||||
wgetopt::{wgetopter_t, wopt, woption, woption_argument_t::no_argument},
|
||||
wutil::{normalize_path, wgettext_fmt, wrealpath},
|
||||
};
|
||||
|
@ -118,7 +118,7 @@ pub fn realpath(
|
|||
}
|
||||
} else {
|
||||
// We need to get the *physical* pwd here.
|
||||
let realpwd = wrealpath(&parser.vars1().get_pwd_slash().from_ffi());
|
||||
let realpwd = wrealpath(parser.vars1().get_pwd_slash().as_wstr());
|
||||
|
||||
if let Some(realpwd) = realpwd {
|
||||
let absolute_arg = if arg.starts_with(L!("/")) {
|
||||
|
|
|
@ -908,7 +908,7 @@ pub fn print(streams: &mut io_streams_t, type_filter: &wstr) {
|
|||
|
||||
fn event_print_ffi(streams: Pin<&mut ffi::io_streams_t>, type_filter: &CxxWString) {
|
||||
let mut streams = io_streams_t::new(streams);
|
||||
print(&mut streams, &type_filter.from_ffi());
|
||||
print(&mut streams, type_filter.as_wstr());
|
||||
}
|
||||
|
||||
/// Fire a generic event with the specified name.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::ffi::{fish_wcswidth, fish_wcwidth, wcharz_t};
|
||||
use crate::tokenizer::variable_assignment_equals_pos;
|
||||
use crate::wchar::{wstr, WString, L};
|
||||
use crate::wchar_ffi::{wcharz, WCharFromFFI, WCharToFFI};
|
||||
use crate::wchar_ffi::{wcharz, AsWstr, WCharFromFFI, WCharToFFI};
|
||||
use crate::wutil::{sprintf, wgettext_fmt};
|
||||
use cxx::{type_id, ExternType};
|
||||
use cxx::{CxxWString, UniquePtr};
|
||||
|
@ -565,7 +565,7 @@ impl ParseError {
|
|||
src: &CxxWString,
|
||||
is_interactive: bool,
|
||||
) -> UniquePtr<CxxWString> {
|
||||
self.describe(&src.from_ffi(), is_interactive).to_ffi()
|
||||
self.describe(src.as_wstr(), is_interactive).to_ffi()
|
||||
}
|
||||
|
||||
fn describe_with_prefix_ffi(
|
||||
|
@ -575,13 +575,8 @@ impl ParseError {
|
|||
is_interactive: bool,
|
||||
skip_caret: bool,
|
||||
) -> UniquePtr<CxxWString> {
|
||||
self.describe_with_prefix(
|
||||
&src.from_ffi(),
|
||||
&prefix.from_ffi(),
|
||||
is_interactive,
|
||||
skip_caret,
|
||||
)
|
||||
.to_ffi()
|
||||
self.describe_with_prefix(src.as_wstr(), prefix.as_wstr(), is_interactive, skip_caret)
|
||||
.to_ffi()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::future_feature_flags::{feature_test, FeatureFlag};
|
|||
use crate::parse_constants::SOURCE_OFFSET_INVALID;
|
||||
use crate::redirection::RedirectionMode;
|
||||
use crate::wchar::{wstr, WExt, WString, L};
|
||||
use crate::wchar_ffi::{wchar_t, WCharFromFFI, WCharToFFI};
|
||||
use crate::wchar_ffi::{wchar_t, AsWstr, WCharToFFI};
|
||||
use crate::wutil::wgettext;
|
||||
use cxx::{CxxWString, SharedPtr, UniquePtr};
|
||||
use libc::{c_int, STDIN_FILENO, STDOUT_FILENO};
|
||||
|
@ -283,7 +283,7 @@ impl Tok {
|
|||
&str[self.offset as usize..(self.offset + self.length) as usize]
|
||||
}
|
||||
fn get_source_ffi(self: &Tok, str: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
self.get_source(&str.from_ffi()).to_ffi()
|
||||
self.get_source(str.as_wstr()).to_ffi()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -941,7 +941,7 @@ pub fn tok_command(str: &wstr) -> WString {
|
|||
WString::new()
|
||||
}
|
||||
fn tok_command_ffi(str: &CxxWString) -> UniquePtr<CxxWString> {
|
||||
tok_command(&str.from_ffi()).to_ffi()
|
||||
tok_command(str.as_wstr()).to_ffi()
|
||||
}
|
||||
|
||||
impl TryFrom<&wstr> for PipeOrRedir {
|
||||
|
@ -1381,7 +1381,7 @@ pub fn variable_assignment_equals_pos(txt: &wstr) -> Option<usize> {
|
|||
}
|
||||
|
||||
fn variable_assignment_equals_pos_ffi(txt: &CxxWString) -> SharedPtr<usize> {
|
||||
match variable_assignment_equals_pos(&txt.from_ffi()) {
|
||||
match variable_assignment_equals_pos(txt.as_wstr()) {
|
||||
Some(p) => SharedPtr::new(p),
|
||||
None => SharedPtr::null(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue