Remove some functions which were rendered trivial by xiaq's changes. Make io_file_t take its path directly. Make io_buffer_t no longer use a shared_ptr for its data.

This commit is contained in:
ridiculousfish 2013-01-19 10:59:43 -08:00
parent f850c021b7
commit 98a17f4046
5 changed files with 18 additions and 75 deletions

View file

@ -332,20 +332,11 @@ static int has_fd(const io_chain_t &d, int fd)
} }
/** /**
Free a transmogrified io chain. Only the chain itself and resources Close a list of fds.
used by a transmogrified IO_FILE redirection are freed, since the
original chain may still be needed.
*/ */
static void io_cleanup_chains(io_chain_t &chains, const std::vector<int> &opened_fds) static void io_cleanup_fds(const std::vector<int> &opened_fds)
{ {
/* Close all the fds */ std::for_each(opened_fds.begin(), opened_fds.end(), close);
for (size_t idx = 0; idx < opened_fds.size(); idx++)
{
close(opened_fds.at(idx));
}
/* Then delete all of the redirections we made */
chains.destroy();
} }
/** /**
@ -446,7 +437,8 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t &out_chain, s
else else
{ {
/* No dice - clean up */ /* No dice - clean up */
io_cleanup_chains(result_chain, opened_fds); result_chain.clear();
io_cleanup_fds(opened_fds);
} }
return success; return success;
} }
@ -488,7 +480,8 @@ static void internal_exec_helper(parser_t &parser,
signal_block(); signal_block();
io_cleanup_chains(morphed_chain, opened_fds); morphed_chain.clear();
io_cleanup_fds(opened_fds);
job_reap(0); job_reap(0);
is_block=is_block_old; is_block=is_block_old;
} }
@ -563,7 +556,7 @@ void exec(parser_t &parser, job_t *j)
if (! parser.block_io.empty()) if (! parser.block_io.empty())
{ {
io_duplicate_prepend(parser.block_io, j->io); j->io.insert(j->io.begin(), parser.block_io.begin(), parser.block_io.end());
} }
const io_buffer_t *input_redirect = 0; const io_buffer_t *input_redirect = 0;

22
io.cpp
View file

@ -135,7 +135,6 @@ io_buffer_t *io_buffer_t::create(bool is_input)
{ {
bool success = true; bool success = true;
io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1, is_input); io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1, is_input);
buffer_redirect->out_buffer_create();
if (exec_pipe(buffer_redirect->pipe_fd) == -1) if (exec_pipe(buffer_redirect->pipe_fd) == -1)
{ {
@ -194,17 +193,6 @@ void io_chain_t::remove(const shared_ptr<const io_data_t> &element)
} }
} }
void io_chain_t::duplicate_prepend(const io_chain_t &src)
{
/* Prepend a duplicate of src before this. */
this->insert(this->begin(), src.begin(), src.end());
}
void io_chain_t::destroy()
{
this->clear();
}
void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element) void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element)
{ {
list.remove(element); list.remove(element);
@ -227,16 +215,6 @@ void io_print(const io_chain_t &chain)
} }
} }
void io_duplicate_prepend(const io_chain_t &src, io_chain_t &dst)
{
return dst.duplicate_prepend(src);
}
void io_chain_destroy(io_chain_t &chain)
{
chain.destroy();
}
/* Return the last IO for the given fd */ /* Return the last IO for the given fd */
shared_ptr<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
{ {

44
io.h
View file

@ -71,22 +71,15 @@ class io_file_t : public io_data_t
{ {
public: public:
/** Filename, malloc'd. This needs to be used after fork, so don't use wcstring here. */ /** Filename, malloc'd. This needs to be used after fork, so don't use wcstring here. */
const char *filename_cstr; const char * const filename_cstr;
/** file creation flags to send to open */ /** file creation flags to send to open */
int flags; int flags;
/** Convenience to set filename_cstr via wcstring */
void set_filename(const wcstring &str)
{
free((void *)filename_cstr);
filename_cstr = wcs2str(str.c_str());
}
virtual void print() const; virtual void print() const;
io_file_t(int f, const char *fname = NULL, int fl = 0) : io_file_t(int f, const wcstring &fname, int fl = 0) :
io_data_t(IO_FILE, f), io_data_t(IO_FILE, f),
filename_cstr(fname ? strdup(fname) : NULL), filename_cstr(wcs2str(fname)),
flags(fl) flags(fl)
{ {
} }
@ -125,7 +118,7 @@ class io_buffer_t : public io_pipe_t
{ {
private: private:
/** buffer to save output in */ /** buffer to save output in */
shared_ptr<std::vector<char> > out_buffer; std::vector<char> out_buffer;
io_buffer_t(int f, bool i): io_buffer_t(int f, bool i):
io_pipe_t(IO_BUFFER, f, i), io_pipe_t(IO_BUFFER, f, i),
@ -138,37 +131,27 @@ public:
virtual ~io_buffer_t(); virtual ~io_buffer_t();
/** Function to create the output buffer */
void out_buffer_create()
{
out_buffer.reset(new std::vector<char>);
}
/** Function to append to the buffer */ /** Function to append to the buffer */
void out_buffer_append(const char *ptr, size_t count) void out_buffer_append(const char *ptr, size_t count)
{ {
assert(out_buffer.get() != NULL); out_buffer.insert(out_buffer.end(), ptr, ptr + count);
out_buffer->insert(out_buffer->end(), ptr, ptr + count);
} }
/** Function to get a pointer to the buffer */ /** Function to get a pointer to the buffer */
char *out_buffer_ptr(void) char *out_buffer_ptr(void)
{ {
assert(out_buffer.get() != NULL); return out_buffer.empty() ? NULL : &out_buffer.at(0);
return out_buffer->empty() ? NULL : &out_buffer->at(0);
} }
const char *out_buffer_ptr(void) const const char *out_buffer_ptr(void) const
{ {
assert(out_buffer.get() != NULL); return out_buffer.empty() ? NULL : &out_buffer.at(0);
return out_buffer->empty() ? NULL : &out_buffer->at(0);
} }
/** Function to get the size of the buffer */ /** Function to get the size of the buffer */
size_t out_buffer_size(void) const size_t out_buffer_size(void) const
{ {
assert(out_buffer.get() != NULL); return out_buffer.size();
return out_buffer->size();
} }
/** /**
@ -195,9 +178,6 @@ public:
io_chain_t(const shared_ptr<io_data_t> &); io_chain_t(const shared_ptr<io_data_t> &);
void remove(const shared_ptr<const io_data_t> &element); void remove(const shared_ptr<const io_data_t> &element);
io_chain_t duplicate() const;
void duplicate_prepend(const io_chain_t &src);
void destroy();
shared_ptr<const io_data_t> get_io_for_fd(int fd) const; shared_ptr<const io_data_t> get_io_for_fd(int fd) const;
shared_ptr<io_data_t> get_io_for_fd(int fd); shared_ptr<io_data_t> get_io_for_fd(int fd);
@ -209,12 +189,6 @@ public:
*/ */
void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element); void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element);
/** Return a shallow copy of the specified chain of redirections that contains only the applicable redirections. That is, if there's multiple redirections for the same fd, only the second one is included. */
io_chain_t io_unique(const io_chain_t &chain);
/** Prepends a copy of the specified 'src' chain of redirections to 'dst.' Uses operator new. */
void io_duplicate_prepend(const io_chain_t &src, io_chain_t &dst);
/** Destroys an io_chain */ /** Destroys an io_chain */
void io_chain_destroy(io_chain_t &chain); void io_chain_destroy(io_chain_t &chain);

View file

@ -1619,8 +1619,7 @@ void parser_t::parse_job_argument_list(process_t *p,
break; break;
} }
io_file_t *new_io_file = new io_file_t(fd, NULL, flags); io_file_t *new_io_file = new io_file_t(fd, target, flags);
new_io_file->set_filename(target);
new_io.reset(new_io_file); new_io.reset(new_io_file);
} }
} }

View file

@ -544,7 +544,6 @@ job_t::~job_t()
{ {
if (first_process != NULL) if (first_process != NULL)
delete first_process; delete first_process;
io_chain_destroy(this->io);
release_job_id(job_id); release_job_id(job_id);
} }