fix read buffer bug

This commit is contained in:
Marcin Junczys-Dowmunt 2018-12-12 17:22:30 -08:00
parent 8115bcc172
commit 0faa7a4b91

View File

@ -178,11 +178,9 @@ public:
bool empty() { return istream_->peek() == std::ifstream::traits_type::eof(); }
void setbufsize(size_t size) const {
#ifdef 0 // this is buggy, do nothing
istream_->rdbuf()->pubsetbuf(0, 0);
readBuf_.reset(new char[size]);
istream_->rdbuf()->pubsetbuf(readBuf_.get(), 0);
#endif
readBuf_.resize(size);
istream_->rdbuf()->pubsetbuf(readBuf_.data(), readBuf_.size());
}
template <typename T>
@ -206,9 +204,10 @@ private:
std::unique_ptr<std::istream> istream_;
boost::iostreams::file_descriptor_source fds_;
mutable std::vector<char> readBuf_; // for setbuf()
std::unique_ptr<boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source>> fdsBuffer_;
mutable UPtr<char[]> readBuf_; // for setbuf()
};
// wrapper around std::getline() that handles Windows input files with extra CR
@ -301,6 +300,7 @@ private:
marian::filesystem::Path file_;
std::unique_ptr<std::ostream> ostream_;
boost::iostreams::file_descriptor_sink fds_;
std::unique_ptr<boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink>> fdsBuffer_;
};