aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-01-04 02:03:41 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-01-04 02:05:30 -0800
commit77f1b1f0fe27778750bb9b9aa53f6bc42d5e5843 (patch)
treedf52ec2bdf258a54677eef48d717335f59f2f478 /io.cpp
parenta79d3c680c9548566309121630dadc94e48934c4 (diff)
Revert shared_ptr<io_data_t> changes until kinks are ironed out
https://github.com/fish-shell/fish-shell/pull/487 Revert "Merge branch 'oo-io' of git://github.com/xiaq/fish-shell into xiaq-oo-io" This reverts commit f3c8f535a48d5fdd518bd60879ade948bc8be7e6, reversing changes made to b02f6cf3bc4343cf3e068dee3cb46de7139a5a27. Also reverts ac023f7588e562a03fdea7fd2feda487f18827c7 and a79d3c680c9548566309121630dadc94e48934c4
Diffstat (limited to 'io.cpp')
-rw-r--r--io.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/io.cpp b/io.cpp
index 6a304014..ef2a0493 100644
--- a/io.cpp
+++ b/io.cpp
@@ -133,7 +133,7 @@ io_data_t *io_buffer_create(bool is_input)
return buffer_redirect;
}
-void io_buffer_destroy(const shared_ptr<io_data_t> &io_buffer)
+void io_buffer_destroy(io_data_t *io_buffer)
{
/**
@@ -151,9 +151,10 @@ void io_buffer_destroy(const shared_ptr<io_data_t> &io_buffer)
Dont free fd for writing. This should already be free'd before
calling exec_read_io_buffer on the buffer
*/
+ delete io_buffer;
}
-void io_chain_t::remove(const shared_ptr<const io_data_t> &element)
+void io_chain_t::remove(const io_data_t *element)
{
// See if you can guess why std::find doesn't work here
for (io_chain_t::iterator iter = this->begin(); iter != this->end(); ++iter)
@@ -166,22 +167,48 @@ void io_chain_t::remove(const shared_ptr<const io_data_t> &element)
}
}
+io_chain_t io_chain_t::duplicate() const
+{
+ io_chain_t result;
+ result.reserve(this->size());
+ for (io_chain_t::const_iterator iter = this->begin(); iter != this->end(); iter++)
+ {
+ const io_data_t *io = *iter;
+ result.push_back(new io_data_t(*io));
+ }
+ return result;
+}
+
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());
+ /* 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->at(idx) = new io_data_t(*src_data);
+ }
}
void io_chain_t::destroy()
{
+ for (size_t idx = 0; idx < this->size(); idx++)
+ {
+ delete this->at(idx);
+ }
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 io_data_t *element)
{
list.remove(element);
}
+io_chain_t io_duplicate(const io_chain_t &chain)
+{
+ return chain.duplicate();
+}
+
void io_print(const io_chain_t &chain)
{
if (chain.empty())
@@ -193,7 +220,7 @@ void io_print(const io_chain_t &chain)
fprintf(stderr, "Chain %p (%ld items):\n", &chain, (long)chain.size());
for (size_t i=0; i < chain.size(); i++)
{
- const shared_ptr<const io_data_t> &io = chain.at(i);
+ 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");
switch (io->io_mode)
{
@@ -227,51 +254,50 @@ void io_chain_destroy(io_chain_t &chain)
}
/* Return the last IO for the given fd */
-shared_ptr<const io_data_t> io_chain_t::get_io_for_fd(int fd) const
+const io_data_t *io_chain_t::get_io_for_fd(int fd) const
{
size_t idx = this->size();
while (idx--)
{
- const shared_ptr<const io_data_t> &data = this->at(idx);
+ const io_data_t *data = this->at(idx);
if (data->fd == fd)
{
return data;
}
}
- return shared_ptr<const io_data_t>();
+ return NULL;
}
-shared_ptr<io_data_t> io_chain_t::get_io_for_fd(int fd)
+io_data_t *io_chain_t::get_io_for_fd(int fd)
{
size_t idx = this->size();
while (idx--)
{
- const shared_ptr<io_data_t> &data = this->at(idx);
+ io_data_t *data = this->at(idx);
if (data->fd == fd)
{
return data;
}
}
- return shared_ptr<io_data_t>();
+ return NULL;
}
/* The old function returned the last match, so we mimic that. */
-shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd)
+const io_data_t *io_chain_get(const io_chain_t &src, int fd)
{
return src.get_io_for_fd(fd);
}
-shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd)
+io_data_t *io_chain_get(io_chain_t &src, int fd)
{
return src.get_io_for_fd(fd);
}
-io_chain_t::io_chain_t(const shared_ptr<io_data_t> &data) :
- std::vector<shared_ptr<io_data_t> >(1, data)
+io_chain_t::io_chain_t(io_data_t *data) : std::vector<io_data_t *>(1, data)
{
}
-io_chain_t::io_chain_t() : std::vector<shared_ptr<io_data_t> >()
+io_chain_t::io_chain_t() : std::vector<io_data_t *>()
{
}