mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Clean up io_chain in IoStreams
Previously this was a pointer; now it can just be a reference.
This commit is contained in:
parent
7d7c59611f
commit
5bff483fe1
8 changed files with 23 additions and 30 deletions
|
@ -15,7 +15,7 @@ pub fn eval(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Opt
|
|||
let new_cmd = join_strings(&args[1..], ' ');
|
||||
|
||||
// Copy the full io chain; we may append bufferfills.
|
||||
let mut ios = unsafe { &*streams.io_chain }.clone();
|
||||
let mut ios = streams.io_chain.clone();
|
||||
|
||||
// If stdout is piped, then its output must go to the streams, not to the io_chain in our
|
||||
// streams, because the pipe may be intended to be consumed by a process which
|
||||
|
|
|
@ -934,12 +934,7 @@ fn builtin_breakpoint(
|
|||
}
|
||||
|
||||
let bpb = parser.push_block(Block::breakpoint_block());
|
||||
let mut empty_io_chain = IoChain::new();
|
||||
let io_chain = if streams.io_chain.is_null() {
|
||||
&mut empty_io_chain
|
||||
} else {
|
||||
unsafe { &mut *streams.io_chain }
|
||||
};
|
||||
let io_chain = &streams.io_chain;
|
||||
reader_read(parser, STDIN_FILENO, io_chain);
|
||||
parser.pop_block(bpb);
|
||||
Some(parser.get_last_status())
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{
|
||||
common::{escape, scoped_push_replacer, FilenameRef},
|
||||
fds::{wopen_cloexec, AutoCloseFd},
|
||||
io::IoChain,
|
||||
nix::isatty,
|
||||
parser::Block,
|
||||
reader::reader_read,
|
||||
|
@ -102,16 +101,7 @@ pub fn source(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
|
|||
}
|
||||
parser.vars().set_argv(argv_list);
|
||||
|
||||
let empty_io_chain = IoChain::new();
|
||||
let mut retval = reader_read(
|
||||
parser,
|
||||
fd,
|
||||
if !streams.io_chain.is_null() {
|
||||
unsafe { &*streams.io_chain }
|
||||
} else {
|
||||
&empty_io_chain
|
||||
},
|
||||
);
|
||||
let mut retval = reader_read(parser, fd, streams.io_chain);
|
||||
|
||||
parser.pop_block(sb);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::io::IoChain;
|
||||
use crate::tests::prelude::*;
|
||||
use crate::wchar::prelude::*;
|
||||
|
||||
|
@ -27,7 +28,8 @@ fn test_string() {
|
|||
let parser: &Parser = Parser::principal_parser();
|
||||
let mut outs = OutputStream::String(StringOutputStream::new());
|
||||
let mut errs = OutputStream::Null;
|
||||
let mut streams = IoStreams::new(&mut outs, &mut errs);
|
||||
let io_chain = IoChain::new();
|
||||
let mut streams = IoStreams::new(&mut outs, &mut errs, &io_chain);
|
||||
streams.stdin_is_directly_redirected = false; // read from argv instead of stdin
|
||||
|
||||
let rc = string(parser, &mut streams, args.as_mut_slice()).expect("string failed");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::builtins::prelude::*;
|
||||
use crate::builtins::test::test as builtin_test;
|
||||
use crate::io::OutputStream;
|
||||
use crate::io::{IoChain, OutputStream};
|
||||
use crate::tests::prelude::*;
|
||||
|
||||
fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> bool {
|
||||
|
@ -22,7 +22,8 @@ fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> boo
|
|||
let mut argv = argv.iter().map(|s| s.as_ref()).collect::<Vec<_>>();
|
||||
let mut out = OutputStream::Null;
|
||||
let mut err = OutputStream::Null;
|
||||
let mut streams = IoStreams::new(&mut out, &mut err);
|
||||
let io_chain = IoChain::new();
|
||||
let mut streams = IoStreams::new(&mut out, &mut err, &io_chain);
|
||||
|
||||
let result: Option<i32> = builtin_test(parser, &mut streams, &mut argv);
|
||||
|
||||
|
@ -53,7 +54,8 @@ fn test_test_brackets() {
|
|||
|
||||
let mut out = OutputStream::Null;
|
||||
let mut err = OutputStream::Null;
|
||||
let mut streams = IoStreams::new(&mut out, &mut err);
|
||||
let io_chain = IoChain::new();
|
||||
let mut streams = IoStreams::new(&mut out, &mut err, &io_chain);
|
||||
|
||||
let args1 = &mut ["["L, "foo"L];
|
||||
assert_eq!(
|
||||
|
|
|
@ -1110,7 +1110,7 @@ fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box<Pr
|
|||
// returned closure.
|
||||
let argv = p.argv().clone();
|
||||
let job_group = j.group.clone();
|
||||
let mut io_chain = io_chain.clone();
|
||||
let io_chain = io_chain.clone();
|
||||
|
||||
// Be careful to not capture p or j by value, as the intent is that this may be run on another
|
||||
// thread.
|
||||
|
@ -1139,7 +1139,7 @@ fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box<Pr
|
|||
}
|
||||
|
||||
// Populate our IoStreams. This is a bag of information for the builtin.
|
||||
let mut streams = IoStreams::new(output_stream, errput_stream);
|
||||
let mut streams = IoStreams::new(output_stream, errput_stream, &io_chain);
|
||||
streams.job_group = job_group;
|
||||
streams.stdin_fd = local_builtin_stdin;
|
||||
streams.stdin_is_directly_redirected = stdin_is_directly_redirected;
|
||||
|
@ -1151,7 +1151,6 @@ fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box<Pr
|
|||
streams.err_is_piped = err_io
|
||||
.map(|io| io.io_mode() == IoMode::pipe)
|
||||
.unwrap_or(false);
|
||||
streams.io_chain = &mut io_chain;
|
||||
|
||||
// Execute the builtin.
|
||||
let mut shim_argv: Vec<&wstr> =
|
||||
|
|
|
@ -965,8 +965,8 @@ pub struct IoStreams<'a> {
|
|||
pub out_is_redirected: bool,
|
||||
pub err_is_redirected: bool,
|
||||
|
||||
// Actual IO redirections. This is only used by the source builtin. Unowned.
|
||||
pub io_chain: *mut IoChain,
|
||||
// Actual IO redirections. This is only used by the source builtin.
|
||||
pub io_chain: &'a IoChain,
|
||||
|
||||
// The job group of the job, if any. This enables builtins which run more code like eval() to
|
||||
// share pgid.
|
||||
|
@ -975,7 +975,11 @@ pub struct IoStreams<'a> {
|
|||
}
|
||||
|
||||
impl<'a> IoStreams<'a> {
|
||||
pub fn new(out: &'a mut OutputStream, err: &'a mut OutputStream) -> Self {
|
||||
pub fn new(
|
||||
out: &'a mut OutputStream,
|
||||
err: &'a mut OutputStream,
|
||||
io_chain: &'a IoChain,
|
||||
) -> Self {
|
||||
IoStreams {
|
||||
out,
|
||||
err,
|
||||
|
@ -985,7 +989,7 @@ impl<'a> IoStreams<'a> {
|
|||
err_is_piped: false,
|
||||
out_is_redirected: false,
|
||||
err_is_redirected: false,
|
||||
io_chain: std::ptr::null_mut(),
|
||||
io_chain,
|
||||
job_group: None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1317,7 +1317,8 @@ impl<'a> ParseExecutionContext {
|
|||
trace_if_enabled_with_args(ctx.parser(), L!("function"), &arguments);
|
||||
let mut outs = OutputStream::Null;
|
||||
let mut errs = OutputStream::String(StringOutputStream::new());
|
||||
let mut streams = IoStreams::new(&mut outs, &mut errs);
|
||||
let io_chain = IoChain::new();
|
||||
let mut streams = IoStreams::new(&mut outs, &mut errs, &io_chain);
|
||||
let mut shim_arguments: Vec<&wstr> = arguments
|
||||
.iter()
|
||||
.map(|s| truncate_at_nul(s.as_ref()))
|
||||
|
|
Loading…
Reference in a new issue