From 9145d053971e59c3a0413fd3be4f290db5fc8a00 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 19 Aug 2012 14:09:39 -0700 Subject: [PATCH] Restore correct order of IO redirections Fixes https://github.com/fish-shell/fish-shell/issues/281 --- exec.cpp | 2 +- io.cpp | 11 ++++++----- io.h | 7 +++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/exec.cpp b/exec.cpp index 499250923..40000e7c6 100644 --- a/exec.cpp +++ b/exec.cpp @@ -408,7 +408,7 @@ void exec( parser_t &parser, job_t *j ) if( ! parser.block_io.empty() ) { - io_duplicate_append(parser.block_io, j->io); + io_duplicate_prepend(parser.block_io, j->io); } const io_data_t *input_redirect = NULL; diff --git a/io.cpp b/io.cpp index 176fb2a34..a956bbbc0 100644 --- a/io.cpp +++ b/io.cpp @@ -179,13 +179,14 @@ io_chain_t io_chain_t::duplicate() const return result; } -void io_chain_t::duplicate_append(const io_chain_t &src) +void io_chain_t::duplicate_prepend(const io_chain_t &src) { - this->reserve(this->size() + src.size()); + /* 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. */ + this->insert(this->begin(), src.size(), NULL); for (size_t idx = 0; idx < src.size(); idx++) { const io_data_t *src_data = src.at(idx); - this->push_back(new io_data_t(*src_data)); + this->at(idx) = new io_data_t(*src_data); } } @@ -241,9 +242,9 @@ void io_print(const io_chain_t &chain) } } -void io_duplicate_append( const io_chain_t &src, io_chain_t &dst ) +void io_duplicate_prepend( const io_chain_t &src, io_chain_t &dst ) { - return dst.duplicate_append(src); + return dst.duplicate_prepend(src); } void io_chain_destroy(io_chain_t &chain) diff --git a/io.h b/io.h index 109c1a5ab..540c8141c 100644 --- a/io.h +++ b/io.h @@ -124,13 +124,12 @@ public: void remove(const io_data_t *element); io_chain_t duplicate() const; - void duplicate_append(const io_chain_t &src); + void duplicate_prepend(const io_chain_t &src); void destroy(); const io_data_t *get_io_for_fd(int fd) const; io_data_t *get_io_for_fd(int fd); - }; /** @@ -144,8 +143,8 @@ io_chain_t io_duplicate(const io_chain_t &chain); /** 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); -/** Appends a copy of the specified 'src' chain of redirections to 'dst.' Uses operator new. */ -void io_duplicate_append( const io_chain_t &src, io_chain_t &dst ); +/** 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 */ void io_chain_destroy(io_chain_t &chain);