Eliminate to_rust_string_vec

This can just use wcstring_list_ffi_t now.
This commit is contained in:
ridiculousfish 2023-04-15 18:15:37 -07:00
parent dee969bf3a
commit 15c8f08458
3 changed files with 7 additions and 17 deletions

View File

@ -28,8 +28,6 @@ mod builtins_ffi {
status_code: &mut i32, status_code: &mut i32,
) -> bool; ) -> bool;
} }
impl Vec<wcharz_t> {}
} }
/// Error message when too many arguments are supplied to a builtin. /// Error message when too many arguments are supplied to a builtin.

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
common::{escape_string, EscapeStringStyle}, common::{escape_string, EscapeStringStyle},
ffi::{self, parser_t, wcharz_t}, ffi::{self, parser_t, wcharz_t, wcstring_list_ffi_t},
global_safety::RelaxedAtomicBool, global_safety::RelaxedAtomicBool,
wchar::{self, wstr, L}, wchar::{self, wstr, L},
wchar_ffi::WCharToFFI, wchar_ffi::{WCharFromFFI, WCharToFFI},
}; };
#[cxx::bridge] #[cxx::bridge]
@ -11,6 +11,7 @@ mod trace_ffi {
extern "C++" { extern "C++" {
include!("wutil.h"); include!("wutil.h");
include!("parser.h"); include!("parser.h");
type wcstring_list_ffi_t = super::wcstring_list_ffi_t;
type wcharz_t = super::wcharz_t; type wcharz_t = super::wcharz_t;
type parser_t = super::parser_t; type parser_t = super::parser_t;
} }
@ -19,7 +20,7 @@ mod trace_ffi {
fn trace_set_enabled(do_enable: bool); fn trace_set_enabled(do_enable: bool);
fn trace_enabled(parser: &parser_t) -> bool; fn trace_enabled(parser: &parser_t) -> bool;
#[cxx_name = "trace_argv"] #[cxx_name = "trace_argv"]
fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &Vec<wcharz_t>); fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &wcstring_list_ffi_t);
} }
} }
@ -41,9 +42,9 @@ pub fn trace_enabled(parser: &parser_t) -> bool {
/// Trace an "argv": a list of arguments where the first is the command. /// Trace an "argv": a list of arguments where the first is the command.
// Allow the `&Vec` parameter as this function only exists temporarily for the FFI // Allow the `&Vec` parameter as this function only exists temporarily for the FFI
#[allow(clippy::ptr_arg)] #[allow(clippy::ptr_arg)]
fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &Vec<wcharz_t>) { fn trace_argv_ffi(parser: &parser_t, command: wcharz_t, args: &wcstring_list_ffi_t) {
let command: wchar::WString = command.into(); let command: wchar::WString = command.into();
let args: Vec<wchar::WString> = args.iter().map(Into::into).collect(); let args: Vec<wchar::WString> = args.from_ffi();
let args_ref: Vec<&wstr> = args.iter().map(wchar::WString::as_utfstr).collect(); let args_ref: Vec<&wstr> = args.iter().map(wchar::WString::as_utfstr).collect();
trace_argv(parser, command.as_utfstr(), &args_ref); trace_argv(parser, command.as_utfstr(), &args_ref);
} }

View File

@ -15,18 +15,9 @@ inline std::shared_ptr<T> box_to_shared_ptr(rust::Box<T> &&value) {
return shared; return shared;
} }
inline static rust::Vec<wcharz_t> to_rust_string_vec(const wcstring_list_t &strings) {
rust::Vec<wcharz_t> rust_strings;
rust_strings.reserve(strings.size());
for (const wcstring &string : strings) {
rust_strings.emplace_back(string.c_str());
}
return rust_strings;
}
inline static void trace_if_enabled(const parser_t &parser, wcharz_t command, inline static void trace_if_enabled(const parser_t &parser, wcharz_t command,
const wcstring_list_t &args = {}) { const wcstring_list_t &args = {}) {
if (trace_enabled(parser)) { if (trace_enabled(parser)) {
trace_argv(parser, command, to_rust_string_vec(args)); trace_argv(parser, command, args);
} }
} }