mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
redirection.rs: don't leak FFI type into Rust code
This commit is contained in:
parent
807d1578c3
commit
16ea4380c5
2 changed files with 17 additions and 16 deletions
|
@ -40,12 +40,12 @@ mod redirection_ffi {
|
||||||
target: wcharz_t,
|
target: wcharz_t,
|
||||||
) -> Box<RedirectionSpec>;
|
) -> Box<RedirectionSpec>;
|
||||||
|
|
||||||
type RedirectionSpecList;
|
type RedirectionSpecListFfi;
|
||||||
fn new_redirection_spec_list() -> Box<RedirectionSpecList>;
|
fn new_redirection_spec_list() -> Box<RedirectionSpecListFfi>;
|
||||||
fn size(self: &RedirectionSpecList) -> usize;
|
fn size(self: &RedirectionSpecListFfi) -> usize;
|
||||||
fn at(self: &RedirectionSpecList, offset: usize) -> *const RedirectionSpec;
|
fn at(self: &RedirectionSpecListFfi, offset: usize) -> *const RedirectionSpec;
|
||||||
fn push_back(self: &mut RedirectionSpecList, spec: Box<RedirectionSpec>);
|
fn push_back(self: &mut RedirectionSpecListFfi, spec: Box<RedirectionSpec>);
|
||||||
fn clone(self: &RedirectionSpecList) -> Box<RedirectionSpecList>;
|
fn clone(self: &RedirectionSpecListFfi) -> Box<RedirectionSpecListFfi>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type that represents the action dup2(src, target).
|
/// A type that represents the action dup2(src, target).
|
||||||
|
@ -150,14 +150,15 @@ fn new_redirection_spec(fd: i32, mode: RedirectionMode, target: wcharz_t) -> Box
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO This should be type alias once we drop the FFI.
|
pub type RedirectionSpecList = Vec<RedirectionSpec>;
|
||||||
pub struct RedirectionSpecList(Vec<RedirectionSpec>);
|
|
||||||
|
|
||||||
fn new_redirection_spec_list() -> Box<RedirectionSpecList> {
|
struct RedirectionSpecListFfi(RedirectionSpecList);
|
||||||
Box::new(RedirectionSpecList(Vec::new()))
|
|
||||||
|
fn new_redirection_spec_list() -> Box<RedirectionSpecListFfi> {
|
||||||
|
Box::new(RedirectionSpecListFfi(Vec::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedirectionSpecList {
|
impl RedirectionSpecListFfi {
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.0.len()
|
self.0.len()
|
||||||
}
|
}
|
||||||
|
@ -165,11 +166,11 @@ impl RedirectionSpecList {
|
||||||
&self.0[offset]
|
&self.0[offset]
|
||||||
}
|
}
|
||||||
#[allow(clippy::boxed_local)]
|
#[allow(clippy::boxed_local)]
|
||||||
fn push_back(self: &mut RedirectionSpecList, spec: Box<RedirectionSpec>) {
|
fn push_back(&mut self, spec: Box<RedirectionSpec>) {
|
||||||
self.0.push(*spec)
|
self.0.push(*spec)
|
||||||
}
|
}
|
||||||
fn clone(self: &RedirectionSpecList) -> Box<RedirectionSpecList> {
|
fn clone(&self) -> Box<RedirectionSpecListFfi> {
|
||||||
Box::new(RedirectionSpecList(self.0.clone()))
|
Box::new(RedirectionSpecListFfi(self.0.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ enum class RedirectionMode {
|
||||||
struct Dup2Action;
|
struct Dup2Action;
|
||||||
class Dup2List;
|
class Dup2List;
|
||||||
struct RedirectionSpec;
|
struct RedirectionSpec;
|
||||||
struct RedirectionSpecList;
|
struct RedirectionSpecListFfi;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using redirection_mode_t = RedirectionMode;
|
using redirection_mode_t = RedirectionMode;
|
||||||
using redirection_spec_t = RedirectionSpec;
|
using redirection_spec_t = RedirectionSpec;
|
||||||
using redirection_spec_list_t = RedirectionSpecList;
|
using redirection_spec_list_t = RedirectionSpecListFfi;
|
||||||
using dup2_action_t = Dup2Action;
|
using dup2_action_t = Dup2Action;
|
||||||
using dup2_list_t = Dup2List;
|
using dup2_list_t = Dup2List;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue