diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2013-01-04 02:03:41 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-01-04 02:05:30 -0800 |
commit | 77f1b1f0fe27778750bb9b9aa53f6bc42d5e5843 (patch) | |
tree | df52ec2bdf258a54677eef48d717335f59f2f478 /io.h | |
parent | a79d3c680c9548566309121630dadc94e48934c4 (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.h')
-rw-r--r-- | io.h | 37 |
1 files changed, 25 insertions, 12 deletions
@@ -20,10 +20,9 @@ private: /** buffer to save output in for IO_BUFFER. Note that in the original fish, the buffer was a pointer to a buffer_t stored in the param2 union down below, and when an io_data_t was duplicated the pointer was copied so that two io_data_ts referenced the same buffer. It's not clear to me how this was ever cleaned up correctly. But it's important that they share the same buffer for reasons I don't yet understand either. We can get correct sharing and cleanup with shared_ptr. */ shared_ptr<std::vector<char> > out_buffer; - /* No assignment or copying allowed */ - io_data_t(const io_data_t &rhs); + /* No assignment allowed */ void operator=(const io_data_t &rhs); - + public: /** Type of redirect */ int io_mode; @@ -108,32 +107,46 @@ public: { } + io_data_t(const io_data_t &rhs) : + out_buffer(rhs.out_buffer), + io_mode(rhs.io_mode), + fd(rhs.fd), + param1(rhs.param1), + param2(rhs.param2), + filename_cstr(rhs.filename_cstr ? strdup(rhs.filename_cstr) : NULL), + is_input(rhs.is_input) + { + } + ~io_data_t() { free((void *)filename_cstr); } }; -class io_chain_t : public std::vector<shared_ptr<io_data_t> > +class io_chain_t : public std::vector<io_data_t *> { public: io_chain_t(); - io_chain_t(const shared_ptr<io_data_t> &); + io_chain_t(io_data_t *); - void remove(const shared_ptr<const io_data_t> &element); + void remove(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<io_data_t> get_io_for_fd(int fd); + const io_data_t *get_io_for_fd(int fd) const; + io_data_t *get_io_for_fd(int fd); }; /** Remove the specified io redirection from the chain */ -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); + +/** Make a copy of the specified chain of redirections. Uses operator new. */ +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); @@ -147,14 +160,14 @@ void io_chain_destroy(io_chain_t &chain); /** Return the last io redirection in the chain for the specified file descriptor. */ -shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd); -shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd); +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); /** Free all resources used by a IO_BUFFER type io redirection. */ -void io_buffer_destroy(const shared_ptr<io_data_t> &io_buffer); +void io_buffer_destroy(io_data_t *io_buffer); /** Create a IO_BUFFER type io redirection, complete with a pipe and a |