Commit 327d4a7c authored by svenpanne's avatar svenpanne Committed by Commit bot

Unobscurified OFStream.

Use simple HAS-A relationship instead of obscure multiple inheritance.
In theory, UBSan should be totally happy with this, but it still isn't.
This seems to be a bug in UBSan, see e.g.
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040225.html

BUG=chromium:448102
LOG=y

Review URL: https://codereview.chromium.org/859773002

Cr-Commit-Position: refs/heads/master@{#26139}
parent af8a0c0d
......@@ -17,7 +17,7 @@ OFStreamBase::OFStreamBase(FILE* f) : f_(f) {}
OFStreamBase::~OFStreamBase() {}
OFStreamBase::int_type OFStreamBase::sync() {
int OFStreamBase::sync() {
std::fflush(f_);
return 0;
}
......@@ -28,8 +28,15 @@ OFStreamBase::int_type OFStreamBase::overflow(int_type c) {
}
OFStream::OFStream(FILE* f) : OFStreamBase(f), std::ostream(this) {
std::streamsize OFStreamBase::xsputn(const char* s, std::streamsize n) {
return static_cast<std::streamsize>(
std::fwrite(s, 1, static_cast<size_t>(n), f_));
}
OFStream::OFStream(FILE* f) : std::ostream(nullptr), buf_(f) {
DCHECK_NOT_NULL(f);
rdbuf(&buf_);
}
......
......@@ -17,29 +17,29 @@
namespace v8 {
namespace internal {
class OFStreamBase : public std::streambuf {
protected:
public:
explicit OFStreamBase(FILE* f);
virtual ~OFStreamBase();
int_type sync() FINAL;
int_type overflow(int_type c) FINAL;
private:
protected:
FILE* const f_;
DISALLOW_COPY_AND_ASSIGN(OFStreamBase);
virtual int sync();
virtual int_type overflow(int_type c);
virtual std::streamsize xsputn(const char* s, std::streamsize n);
};
// An output stream writing to a file.
class OFStream FINAL : private virtual OFStreamBase, public std::ostream {
class OFStream : public std::ostream {
public:
explicit OFStream(FILE* f);
~OFStream();
private:
DISALLOW_COPY_AND_ASSIGN(OFStream);
OFStreamBase buf_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment