diff options
author | Cheer Xiao <xiaqqaix@gmail.com> | 2013-01-07 23:04:55 +0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-01-11 14:18:10 -0800 |
commit | b66233de786ec1b136c84fb2ec0afcce0e107e00 (patch) | |
tree | 3efdb0181d69d6d429e0ffca737b527e19cc5cbd /io.h | |
parent | ff49792f44196f41156547efdf615bb2b52fcaaa (diff) |
Revert "Revert shared_ptr<io_data_t> changes until kinks are ironed out"
This reverts commit 77f1b1f0fe27778750bb9b9aa53f6bc42d5e5843.
Diffstat (limited to 'io.h')
-rw-r--r-- | io.h | 35 |
1 files changed, 11 insertions, 24 deletions
@@ -20,7 +20,8 @@ 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 allowed */ + /* No assignment or copying allowed */ + io_data_t(const io_data_t &rhs); void operator=(const io_data_t &rhs); public: @@ -107,46 +108,32 @@ 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<io_data_t *> +class io_chain_t : public std::vector<shared_ptr<io_data_t> > { public: io_chain_t(); - io_chain_t(io_data_t *); + io_chain_t(const shared_ptr<io_data_t> &); - void remove(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(); - const io_data_t *get_io_for_fd(int fd) const; - io_data_t *get_io_for_fd(int fd); + shared_ptr<const io_data_t> get_io_for_fd(int fd) const; + shared_ptr<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 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); +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); @@ -160,14 +147,14 @@ void io_chain_destroy(io_chain_t &chain); /** 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); -io_data_t *io_chain_get(io_chain_t &src, int fd); +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); /** Free all resources used by a IO_BUFFER type io redirection. */ -void io_buffer_destroy(io_data_t *io_buffer); +void io_buffer_destroy(const shared_ptr<io_data_t> &io_buffer); /** Create a IO_BUFFER type io redirection, complete with a pipe and a |