Reviewers: Benedikt Meurer,
Description:
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
Please review this at https://codereview.chromium.org/859773002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+16, -10 lines):
M src/ostreams.h
M src/ostreams.cc
Index: src/ostreams.cc
diff --git a/src/ostreams.cc b/src/ostreams.cc
index
ee0474d2c0882db2ffe81e9e293401fa3c45fed3..07d60115869d104dfc185e0cb1baa38f9b8ce044
100644
--- a/src/ostreams.cc
+++ b/src/ostreams.cc
@@ -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,14 @@ 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 std::fwrite(s, 1, n, f_);
+}
+
+
+OFStream::OFStream(FILE* f) : std::ostream(nullptr), buf_(f) {
DCHECK_NOT_NULL(f);
+ rdbuf(&buf_);
}
Index: src/ostreams.h
diff --git a/src/ostreams.h b/src/ostreams.h
index
56787f7c126a2d1ff0be295652b247354816170c..840f341551632a4d21e5e747be1a524f0f1cc752
100644
--- a/src/ostreams.h
+++ b/src/ostreams.h
@@ -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_;
};
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.