mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Use shared_ptr to manage io_data_t*.
This commit is contained in:
parent
1ae0e5d7cb
commit
a9ada13a23
7 changed files with 80 additions and 82 deletions
80
exec.cpp
80
exec.cpp
|
@ -160,7 +160,7 @@ static bool use_fd_in_pipe(int fd, const io_chain_t &io_chain)
|
||||||
{
|
{
|
||||||
for (size_t idx = 0; idx < io_chain.size(); idx++)
|
for (size_t idx = 0; idx < io_chain.size(); idx++)
|
||||||
{
|
{
|
||||||
const io_data_t *io = io_chain.at(idx);
|
shared_ptr<const io_data_t> io = io_chain.at(idx);
|
||||||
if ((io->io_mode == IO_BUFFER) ||
|
if ((io->io_mode == IO_BUFFER) ||
|
||||||
(io->io_mode == IO_PIPE))
|
(io->io_mode == IO_PIPE))
|
||||||
{
|
{
|
||||||
|
@ -378,8 +378,8 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t &out_chain, s
|
||||||
|
|
||||||
for (size_t idx = 0; idx < in_chain.size(); idx++)
|
for (size_t idx = 0; idx < in_chain.size(); idx++)
|
||||||
{
|
{
|
||||||
io_data_t *in = in_chain.at(idx);
|
shared_ptr<io_data_t> in = in_chain.at(idx);
|
||||||
io_data_t *out = NULL; //gets allocated via new
|
shared_ptr<io_data_t> out; //gets allocated via new
|
||||||
|
|
||||||
switch (in->io_mode)
|
switch (in->io_mode)
|
||||||
{
|
{
|
||||||
|
@ -397,7 +397,7 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t &out_chain, s
|
||||||
case IO_BUFFER:
|
case IO_BUFFER:
|
||||||
case IO_CLOSE:
|
case IO_CLOSE:
|
||||||
{
|
{
|
||||||
out = new io_data_t(*in);
|
out.reset(new io_data_t(*in));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t &out_chain, s
|
||||||
*/
|
*/
|
||||||
case IO_FILE:
|
case IO_FILE:
|
||||||
{
|
{
|
||||||
out = new io_data_t();
|
out.reset(new io_data_t());
|
||||||
out->fd = in->fd;
|
out->fd = in->fd;
|
||||||
out->io_mode = IO_FD;
|
out->io_mode = IO_FD;
|
||||||
out->param2.close_old = 1;
|
out->param2.close_old = 1;
|
||||||
|
@ -544,7 +544,7 @@ static bool can_use_posix_spawn_for_job(const job_t *job, const process_t *proce
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for (size_t idx = 0; idx < job->io.size(); idx++)
|
for (size_t idx = 0; idx < job->io.size(); idx++)
|
||||||
{
|
{
|
||||||
const io_data_t *io = job->io.at(idx);
|
shared_ptr<const io_data_t> io = job->io.at(idx);
|
||||||
if (io->io_mode == IO_FILE)
|
if (io->io_mode == IO_FILE)
|
||||||
{
|
{
|
||||||
const char *path = io->filename_cstr;
|
const char *path = io->filename_cstr;
|
||||||
|
@ -567,9 +567,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
int mypipe[2];
|
int mypipe[2];
|
||||||
sigset_t chldset;
|
sigset_t chldset;
|
||||||
|
|
||||||
io_data_t pipe_read, pipe_write;
|
shared_ptr<io_data_t> io_buffer;
|
||||||
|
|
||||||
io_data_t *io_buffer =0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set to true if something goes wrong while exec:ing the job, in
|
Set to true if something goes wrong while exec:ing the job, in
|
||||||
|
@ -597,7 +595,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
io_duplicate_prepend(parser.block_io, j->io);
|
io_duplicate_prepend(parser.block_io, j->io);
|
||||||
}
|
}
|
||||||
|
|
||||||
const io_data_t *input_redirect = NULL;
|
shared_ptr<const io_data_t> input_redirect;
|
||||||
for (size_t idx = 0; idx < j->io.size(); idx++)
|
for (size_t idx = 0; idx < j->io.size(); idx++)
|
||||||
{
|
{
|
||||||
input_redirect = j->io.at(idx);
|
input_redirect = j->io.at(idx);
|
||||||
|
@ -646,17 +644,19 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe_read.fd = 0;
|
shared_ptr<io_data_t> pipe_read(new io_data_t);
|
||||||
pipe_read.io_mode = IO_PIPE;
|
pipe_read->fd = 0;
|
||||||
pipe_read.is_input = 1;
|
pipe_read->io_mode = IO_PIPE;
|
||||||
pipe_read.param1.pipe_fd[0] = pipe_read.param1.pipe_fd[1] = -1;
|
pipe_read->is_input = 1;
|
||||||
|
pipe_read->param1.pipe_fd[0] = pipe_read->param1.pipe_fd[1] = -1;
|
||||||
|
|
||||||
pipe_write.fd = 1;
|
shared_ptr<io_data_t> pipe_write(new io_data_t);
|
||||||
pipe_write.io_mode = IO_PIPE;
|
pipe_write->fd = 1;
|
||||||
pipe_write.is_input = 0;
|
pipe_write->io_mode = IO_PIPE;
|
||||||
pipe_write.param1.pipe_fd[0] = pipe_write.param1.pipe_fd[1] = -1;
|
pipe_write->is_input = 0;
|
||||||
|
pipe_write->param1.pipe_fd[0] = pipe_write->param1.pipe_fd[1] = -1;
|
||||||
|
|
||||||
j->io.push_back(&pipe_write);
|
j->io.push_back(pipe_write);
|
||||||
|
|
||||||
signal_block();
|
signal_block();
|
||||||
|
|
||||||
|
@ -728,9 +728,9 @@ void exec(parser_t &parser, job_t *j)
|
||||||
const bool p_wants_pipe = (p->next != NULL);
|
const bool p_wants_pipe = (p->next != NULL);
|
||||||
mypipe[1]=-1;
|
mypipe[1]=-1;
|
||||||
|
|
||||||
pipe_write.fd = p->pipe_write_fd;
|
pipe_write->fd = p->pipe_write_fd;
|
||||||
pipe_read.fd = p->pipe_read_fd;
|
pipe_read->fd = p->pipe_read_fd;
|
||||||
// debug( 0, L"Pipe created from fd %d to fd %d", pipe_write.fd, pipe_read.fd );
|
// debug( 0, L"Pipe created from fd %d to fd %d", pipe_write->fd, pipe_read->fd );
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -752,7 +752,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
if (p == j->first_process->next)
|
if (p == j->first_process->next)
|
||||||
{
|
{
|
||||||
j->io.push_back(&pipe_read);
|
j->io.push_back(pipe_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_wants_pipe)
|
if (p_wants_pipe)
|
||||||
|
@ -767,7 +767,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pipe_write.param1.pipe_fd, mypipe, sizeof(int)*2);
|
memcpy(pipe_write->param1.pipe_fd, mypipe, sizeof(int)*2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -775,7 +775,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
This is the last element of the pipeline.
|
This is the last element of the pipeline.
|
||||||
Remove the io redirection for pipe output.
|
Remove the io redirection for pipe output.
|
||||||
*/
|
*/
|
||||||
io_chain_t::iterator where = std::find(j->io.begin(), j->io.end(), &pipe_write);
|
io_chain_t::iterator where = std::find(j->io.begin(), j->io.end(), pipe_write);
|
||||||
if (where != j->io.end())
|
if (where != j->io.end())
|
||||||
j->io.erase(where);
|
j->io.erase(where);
|
||||||
}
|
}
|
||||||
|
@ -830,7 +830,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
if (p->next)
|
if (p->next)
|
||||||
{
|
{
|
||||||
io_buffer = io_buffer_create(0);
|
io_buffer.reset(io_buffer_create(0));
|
||||||
j->io.push_back(io_buffer);
|
j->io.push_back(io_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
{
|
{
|
||||||
if (p->next)
|
if (p->next)
|
||||||
{
|
{
|
||||||
io_buffer = io_buffer_create(0);
|
io_buffer.reset(io_buffer_create(0));
|
||||||
j->io.push_back(io_buffer);
|
j->io.push_back(io_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -869,7 +869,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
*/
|
*/
|
||||||
if (p == j->first_process)
|
if (p == j->first_process)
|
||||||
{
|
{
|
||||||
const io_data_t *in = io_chain_get(j->io, 0);
|
shared_ptr<const io_data_t> in = io_chain_get(j->io, 0);
|
||||||
|
|
||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
|
@ -935,7 +935,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builtin_stdin = pipe_read.param1.pipe_fd[0];
|
builtin_stdin = pipe_read->param1.pipe_fd[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builtin_stdin == -1)
|
if (builtin_stdin == -1)
|
||||||
|
@ -1035,7 +1035,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
io_remove(j->io, io_buffer);
|
io_remove(j->io, io_buffer);
|
||||||
|
|
||||||
io_buffer_read(io_buffer);
|
io_buffer_read(io_buffer.get());
|
||||||
|
|
||||||
const char *buffer = io_buffer->out_buffer_ptr();
|
const char *buffer = io_buffer->out_buffer_ptr();
|
||||||
size_t count = io_buffer->out_buffer_size();
|
size_t count = io_buffer->out_buffer_size();
|
||||||
|
@ -1083,7 +1083,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
io_buffer_destroy(io_buffer);
|
io_buffer_destroy(io_buffer);
|
||||||
|
|
||||||
io_buffer=0;
|
io_buffer.reset();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1154,7 +1154,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
performance quite a bit in complex completion code.
|
performance quite a bit in complex completion code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
io_data_t *io = io_chain_get(j->io, 1);
|
shared_ptr<io_data_t> io = io_chain_get(j->io, 1);
|
||||||
bool buffer_stdout = io && io->io_mode == IO_BUFFER;
|
bool buffer_stdout = io && io->io_mode == IO_BUFFER;
|
||||||
|
|
||||||
if ((get_stderr_buffer().empty()) &&
|
if ((get_stderr_buffer().empty()) &&
|
||||||
|
@ -1183,7 +1183,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
for (io_chain_t::iterator iter = j->io.begin(); iter != j->io.end(); iter++)
|
for (io_chain_t::iterator iter = j->io.begin(); iter != j->io.end(); iter++)
|
||||||
{
|
{
|
||||||
io_data_t *tmp_io = *iter;
|
shared_ptr<io_data_t> tmp_io = *iter;
|
||||||
if (tmp_io->io_mode == IO_FILE && strcmp(tmp_io->filename_cstr, "/dev/null") != 0)
|
if (tmp_io->io_mode == IO_FILE && strcmp(tmp_io->filename_cstr, "/dev/null") != 0)
|
||||||
{
|
{
|
||||||
skip_fork = false;
|
skip_fork = false;
|
||||||
|
@ -1357,14 +1357,14 @@ void exec(parser_t &parser, job_t *j)
|
||||||
Close the pipe the current process uses to read from the
|
Close the pipe the current process uses to read from the
|
||||||
previous process_t
|
previous process_t
|
||||||
*/
|
*/
|
||||||
if (pipe_read.param1.pipe_fd[0] >= 0)
|
if (pipe_read->param1.pipe_fd[0] >= 0)
|
||||||
exec_close(pipe_read.param1.pipe_fd[0]);
|
exec_close(pipe_read->param1.pipe_fd[0]);
|
||||||
/*
|
/*
|
||||||
Set up the pipe the next process uses to read from the
|
Set up the pipe the next process uses to read from the
|
||||||
current process_t
|
current process_t
|
||||||
*/
|
*/
|
||||||
if (p_wants_pipe)
|
if (p_wants_pipe)
|
||||||
pipe_read.param1.pipe_fd[0] = mypipe[0];
|
pipe_read->param1.pipe_fd[0] = mypipe[0];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If there is a next process in the pipeline, close the
|
If there is a next process in the pipeline, close the
|
||||||
|
@ -1392,7 +1392,7 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
debug(3, L"Job is constructed");
|
debug(3, L"Job is constructed");
|
||||||
|
|
||||||
io_remove(j->io, &pipe_read);
|
io_remove(j->io, pipe_read);
|
||||||
|
|
||||||
for (io_chain_t::const_iterator iter = parser.block_io.begin(); iter != parser.block_io.end(); iter++)
|
for (io_chain_t::const_iterator iter = parser.block_io.begin(); iter != parser.block_io.end(); iter++)
|
||||||
{
|
{
|
||||||
|
@ -1419,7 +1419,6 @@ static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst)
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
int prev_subshell = is_subshell;
|
int prev_subshell = is_subshell;
|
||||||
int status, prev_status;
|
int status, prev_status;
|
||||||
io_data_t *io_buffer;
|
|
||||||
char sep=0;
|
char sep=0;
|
||||||
|
|
||||||
const env_var_t ifs = env_get_string(L"IFS");
|
const env_var_t ifs = env_get_string(L"IFS");
|
||||||
|
@ -1439,7 +1438,8 @@ static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst)
|
||||||
}
|
}
|
||||||
|
|
||||||
is_subshell=1;
|
is_subshell=1;
|
||||||
io_buffer= io_buffer_create(0);
|
|
||||||
|
shared_ptr<io_data_t> io_buffer(io_buffer_create(0));
|
||||||
|
|
||||||
prev_status = proc_get_last_status();
|
prev_status = proc_get_last_status();
|
||||||
|
|
||||||
|
@ -1453,7 +1453,7 @@ static int exec_subshell_internal(const wcstring &cmd, wcstring_list_t *lst)
|
||||||
status = proc_get_last_status();
|
status = proc_get_last_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
io_buffer_read(io_buffer);
|
io_buffer_read(io_buffer.get());
|
||||||
|
|
||||||
proc_set_last_status(prev_status);
|
proc_set_last_status(prev_status);
|
||||||
|
|
||||||
|
|
42
io.cpp
42
io.cpp
|
@ -133,7 +133,7 @@ io_data_t *io_buffer_create(bool is_input)
|
||||||
return buffer_redirect;
|
return buffer_redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_buffer_destroy(io_data_t *io_buffer)
|
void io_buffer_destroy(shared_ptr<io_data_t> io_buffer)
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,10 +151,9 @@ void io_buffer_destroy(io_data_t *io_buffer)
|
||||||
Dont free fd for writing. This should already be free'd before
|
Dont free fd for writing. This should already be free'd before
|
||||||
calling exec_read_io_buffer on the buffer
|
calling exec_read_io_buffer on the buffer
|
||||||
*/
|
*/
|
||||||
delete io_buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_chain_t::remove(const io_data_t *element)
|
void io_chain_t::remove(shared_ptr<const io_data_t> element)
|
||||||
{
|
{
|
||||||
// See if you can guess why std::find doesn't work here
|
// See if you can guess why std::find doesn't work here
|
||||||
for (io_chain_t::iterator iter = this->begin(); iter != this->end(); ++iter)
|
for (io_chain_t::iterator iter = this->begin(); iter != this->end(); ++iter)
|
||||||
|
@ -173,20 +172,18 @@ io_chain_t io_chain_t::duplicate() const
|
||||||
result.reserve(this->size());
|
result.reserve(this->size());
|
||||||
for (io_chain_t::const_iterator iter = this->begin(); iter != this->end(); iter++)
|
for (io_chain_t::const_iterator iter = this->begin(); iter != this->end(); iter++)
|
||||||
{
|
{
|
||||||
const io_data_t *io = *iter;
|
result.push_back(shared_ptr<io_data_t>(new io_data_t(**iter)));
|
||||||
result.push_back(new io_data_t(*io));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_chain_t::duplicate_prepend(const io_chain_t &src)
|
void io_chain_t::duplicate_prepend(const io_chain_t &src)
|
||||||
{
|
{
|
||||||
/* Prepend a duplicate of src before this. Start by inserting a bunch of NULLs (so we only have to reallocate once) and then replace them. */
|
/* Prepend a duplicate of src before this. Start by inserting a bunch of empty shared_ptr's (so we only have to reallocate once) and then replace them. */
|
||||||
this->insert(this->begin(), src.size(), NULL);
|
this->insert(this->begin(), src.size(), shared_ptr<io_data_t>());
|
||||||
for (size_t idx = 0; idx < src.size(); idx++)
|
for (size_t idx = 0; idx < src.size(); idx++)
|
||||||
{
|
{
|
||||||
const io_data_t *src_data = src.at(idx);
|
this->at(idx).reset(new io_data_t(*src.at(idx)));
|
||||||
this->at(idx) = new io_data_t(*src_data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,12 +191,12 @@ void io_chain_t::destroy()
|
||||||
{
|
{
|
||||||
for (size_t idx = 0; idx < this->size(); idx++)
|
for (size_t idx = 0; idx < this->size(); idx++)
|
||||||
{
|
{
|
||||||
delete this->at(idx);
|
this->at(idx).reset();
|
||||||
}
|
}
|
||||||
this->clear();
|
this->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_remove(io_chain_t &list, const io_data_t *element)
|
void io_remove(io_chain_t &list, shared_ptr<const io_data_t> element)
|
||||||
{
|
{
|
||||||
list.remove(element);
|
list.remove(element);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +217,7 @@ void io_print(const io_chain_t &chain)
|
||||||
fprintf(stderr, "Chain %p (%ld items):\n", &chain, (long)chain.size());
|
fprintf(stderr, "Chain %p (%ld items):\n", &chain, (long)chain.size());
|
||||||
for (size_t i=0; i < chain.size(); i++)
|
for (size_t i=0; i < chain.size(); i++)
|
||||||
{
|
{
|
||||||
const io_data_t *io = chain.at(i);
|
shared_ptr<const io_data_t> io = chain.at(i);
|
||||||
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
|
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
|
||||||
switch (io->io_mode)
|
switch (io->io_mode)
|
||||||
{
|
{
|
||||||
|
@ -254,50 +251,51 @@ void io_chain_destroy(io_chain_t &chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the last IO for the given fd */
|
/* Return the last IO for the given fd */
|
||||||
const io_data_t *io_chain_t::get_io_for_fd(int fd) const
|
shared_ptr<const io_data_t> io_chain_t::get_io_for_fd(int fd) const
|
||||||
{
|
{
|
||||||
size_t idx = this->size();
|
size_t idx = this->size();
|
||||||
while (idx--)
|
while (idx--)
|
||||||
{
|
{
|
||||||
const io_data_t *data = this->at(idx);
|
shared_ptr<const io_data_t> data = this->at(idx);
|
||||||
if (data->fd == fd)
|
if (data->fd == fd)
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return shared_ptr<const io_data_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
io_data_t *io_chain_t::get_io_for_fd(int fd)
|
shared_ptr<io_data_t> io_chain_t::get_io_for_fd(int fd)
|
||||||
{
|
{
|
||||||
size_t idx = this->size();
|
size_t idx = this->size();
|
||||||
while (idx--)
|
while (idx--)
|
||||||
{
|
{
|
||||||
io_data_t *data = this->at(idx);
|
shared_ptr<io_data_t> data = this->at(idx);
|
||||||
if (data->fd == fd)
|
if (data->fd == fd)
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return shared_ptr<io_data_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The old function returned the last match, so we mimic that. */
|
/* The old function returned the last match, so we mimic that. */
|
||||||
const io_data_t *io_chain_get(const io_chain_t &src, int fd)
|
shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd)
|
||||||
{
|
{
|
||||||
return src.get_io_for_fd(fd);
|
return src.get_io_for_fd(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
io_data_t *io_chain_get(io_chain_t &src, int fd)
|
shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd)
|
||||||
{
|
{
|
||||||
return src.get_io_for_fd(fd);
|
return src.get_io_for_fd(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
io_chain_t::io_chain_t(io_data_t *data) : std::vector<io_data_t *>(1, data)
|
io_chain_t::io_chain_t(shared_ptr<io_data_t> data) :
|
||||||
|
std::vector<shared_ptr<io_data_t> >(1, data)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
io_chain_t::io_chain_t() : std::vector<io_data_t *>()
|
io_chain_t::io_chain_t() : std::vector<shared_ptr<io_data_t> >()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
18
io.h
18
io.h
|
@ -124,26 +124,26 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class io_chain_t : public std::vector<io_data_t *>
|
class io_chain_t : public std::vector<shared_ptr<io_data_t> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
io_chain_t();
|
io_chain_t();
|
||||||
io_chain_t(io_data_t *);
|
io_chain_t(shared_ptr<io_data_t> );
|
||||||
|
|
||||||
void remove(const io_data_t *element);
|
void remove(shared_ptr<const io_data_t> element);
|
||||||
io_chain_t duplicate() const;
|
io_chain_t duplicate() const;
|
||||||
void duplicate_prepend(const io_chain_t &src);
|
void duplicate_prepend(const io_chain_t &src);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
const io_data_t *get_io_for_fd(int fd) const;
|
shared_ptr<const io_data_t> get_io_for_fd(int fd) const;
|
||||||
io_data_t *get_io_for_fd(int fd);
|
shared_ptr<io_data_t> get_io_for_fd(int fd);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove the specified io redirection from the chain
|
Remove the specified io redirection from the chain
|
||||||
*/
|
*/
|
||||||
void io_remove(io_chain_t &list, const io_data_t *element);
|
void io_remove(io_chain_t &list, shared_ptr<const io_data_t> element);
|
||||||
|
|
||||||
/** Make a copy of the specified chain of redirections. Uses operator new. */
|
/** Make a copy of the specified chain of redirections. Uses operator new. */
|
||||||
io_chain_t io_duplicate(const io_chain_t &chain);
|
io_chain_t io_duplicate(const io_chain_t &chain);
|
||||||
|
@ -160,14 +160,14 @@ void io_chain_destroy(io_chain_t &chain);
|
||||||
/**
|
/**
|
||||||
Return the last io redirection in the chain for the specified file descriptor.
|
Return the last io redirection in the chain for the specified file descriptor.
|
||||||
*/
|
*/
|
||||||
const io_data_t *io_chain_get(const io_chain_t &src, int fd);
|
shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd);
|
||||||
io_data_t *io_chain_get(io_chain_t &src, int fd);
|
shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Free all resources used by a IO_BUFFER type io redirection.
|
Free all resources used by a IO_BUFFER type io redirection.
|
||||||
*/
|
*/
|
||||||
void io_buffer_destroy(io_data_t *io_buffer);
|
void io_buffer_destroy(shared_ptr<io_data_t> io_buffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a IO_BUFFER type io redirection, complete with a pipe and a
|
Create a IO_BUFFER type io redirection, complete with a pipe and a
|
||||||
|
|
|
@ -377,7 +377,7 @@ parser_t::parser_t(enum parser_type_t type, bool errors) :
|
||||||
job_start_pos(0),
|
job_start_pos(0),
|
||||||
eval_level(-1),
|
eval_level(-1),
|
||||||
current_block(NULL),
|
current_block(NULL),
|
||||||
block_io(NULL)
|
block_io(shared_ptr<io_data_t>())
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1495,7 +1495,7 @@ void parser_t::parse_job_argument_list(process_t *p,
|
||||||
case TOK_REDIRECT_NOCLOB:
|
case TOK_REDIRECT_NOCLOB:
|
||||||
{
|
{
|
||||||
int type = tok_last_type(tok);
|
int type = tok_last_type(tok);
|
||||||
std::auto_ptr<io_data_t> new_io;
|
shared_ptr<io_data_t> new_io;
|
||||||
wcstring target;
|
wcstring target;
|
||||||
bool has_target = false;
|
bool has_target = false;
|
||||||
wchar_t *end;
|
wchar_t *end;
|
||||||
|
@ -1633,7 +1633,7 @@ void parser_t::parse_job_argument_list(process_t *p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j->io.push_back(new_io.release());
|
j->io.push_back(new_io);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -117,7 +117,7 @@ static void free_redirected_fds_from_pipes(io_chain_t &io_chain)
|
||||||
for (size_t j = 0; j < max; j++)
|
for (size_t j = 0; j < max; j++)
|
||||||
{
|
{
|
||||||
/* We're only interested in pipes */
|
/* We're only interested in pipes */
|
||||||
io_data_t *possible_conflict = io_chain.at(j);
|
shared_ptr<io_data_t> possible_conflict = io_chain.at(j);
|
||||||
if (possible_conflict->io_mode != IO_PIPE && possible_conflict->io_mode != IO_BUFFER)
|
if (possible_conflict->io_mode != IO_PIPE && possible_conflict->io_mode != IO_BUFFER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ static int handle_child_io(io_chain_t &io_chain)
|
||||||
free_redirected_fds_from_pipes(io_chain);
|
free_redirected_fds_from_pipes(io_chain);
|
||||||
for (size_t idx = 0; idx < io_chain.size(); idx++)
|
for (size_t idx = 0; idx < io_chain.size(); idx++)
|
||||||
{
|
{
|
||||||
io_data_t *io = io_chain.at(idx);
|
shared_ptr<io_data_t> io = io_chain.at(idx);
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
if (io->io_mode == IO_FD && io->fd == io->param1.old_fd)
|
if (io->io_mode == IO_FD && io->fd == io->param1.old_fd)
|
||||||
|
@ -441,7 +441,7 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
|
||||||
|
|
||||||
for (size_t idx = 0; idx < j->io.size(); idx++)
|
for (size_t idx = 0; idx < j->io.size(); idx++)
|
||||||
{
|
{
|
||||||
const io_data_t *io = j->io.at(idx);
|
shared_ptr<const io_data_t> io = j->io.at(idx);
|
||||||
|
|
||||||
if (io->io_mode == IO_FD && io->fd == io->param1.old_fd)
|
if (io->io_mode == IO_FD && io->fd == io->param1.old_fd)
|
||||||
{
|
{
|
||||||
|
|
4
proc.cpp
4
proc.cpp
|
@ -869,7 +869,7 @@ static int select_try(job_t *j)
|
||||||
|
|
||||||
for (size_t idx = 0; idx < j->io.size(); idx++)
|
for (size_t idx = 0; idx < j->io.size(); idx++)
|
||||||
{
|
{
|
||||||
const io_data_t *d = j->io.at(idx);
|
const io_data_t *d = j->io.at(idx).get();
|
||||||
if (d->io_mode == IO_BUFFER)
|
if (d->io_mode == IO_BUFFER)
|
||||||
{
|
{
|
||||||
int fd = d->param1.pipe_fd[0];
|
int fd = d->param1.pipe_fd[0];
|
||||||
|
@ -909,7 +909,7 @@ static void read_try(job_t *j)
|
||||||
*/
|
*/
|
||||||
for (size_t idx = 0; idx < j->io.size(); idx++)
|
for (size_t idx = 0; idx < j->io.size(); idx++)
|
||||||
{
|
{
|
||||||
io_data_t *d = j->io.at(idx);
|
io_data_t *d = j->io.at(idx).get();
|
||||||
if (d->io_mode == IO_BUFFER)
|
if (d->io_mode == IO_BUFFER)
|
||||||
{
|
{
|
||||||
buff=d;
|
buff=d;
|
||||||
|
|
|
@ -1014,7 +1014,7 @@ static void run_pager(const wcstring &prefix, int is_quoted, const std::vector<c
|
||||||
is_quoted?L"-q":L"",
|
is_quoted?L"-q":L"",
|
||||||
prefix_esc.c_str());
|
prefix_esc.c_str());
|
||||||
|
|
||||||
io_data_t *in = io_buffer_create(true);
|
shared_ptr<io_data_t> in(io_buffer_create(true));
|
||||||
in->fd = 3;
|
in->fd = 3;
|
||||||
|
|
||||||
escaped_separator = escape(COMPLETE_SEP_STR, 1);
|
escaped_separator = escape(COMPLETE_SEP_STR, 1);
|
||||||
|
@ -1083,7 +1083,7 @@ static void run_pager(const wcstring &prefix, int is_quoted, const std::vector<c
|
||||||
|
|
||||||
term_donate();
|
term_donate();
|
||||||
|
|
||||||
io_data_t *out = io_buffer_create(false);
|
shared_ptr<io_data_t> out(io_buffer_create(false));
|
||||||
out->fd = 4;
|
out->fd = 4;
|
||||||
|
|
||||||
parser_t &parser = parser_t::principal_parser();
|
parser_t &parser = parser_t::principal_parser();
|
||||||
|
@ -1093,7 +1093,7 @@ static void run_pager(const wcstring &prefix, int is_quoted, const std::vector<c
|
||||||
parser.eval(cmd, io_chain, TOP);
|
parser.eval(cmd, io_chain, TOP);
|
||||||
term_steal();
|
term_steal();
|
||||||
|
|
||||||
io_buffer_read(out);
|
io_buffer_read(out.get());
|
||||||
|
|
||||||
int nil=0;
|
int nil=0;
|
||||||
out->out_buffer_append((char *)&nil, 1);
|
out->out_buffer_append((char *)&nil, 1);
|
||||||
|
|
Loading…
Reference in a new issue