summaryrefslogtreecommitdiffstats
path: root/courgette/streams.h
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 20:19:49 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 20:19:49 +0000
commitc8240b1c3519b35de243b0fb91af409d59a5808c (patch)
treed7f20f227779c4c32fdd2851037255f1d660673a /courgette/streams.h
parentd64abe1c12dbe8dab68adee605fa143dc9020f86 (diff)
downloadchromium_src-c8240b1c3519b35de243b0fb91af409d59a5808c.zip
chromium_src-c8240b1c3519b35de243b0fb91af409d59a5808c.tar.gz
chromium_src-c8240b1c3519b35de243b0fb91af409d59a5808c.tar.bz2
Identifying call sites that need to handle out of memory situations in Courgette.
There's no functional change here, only interface changes: * Change methods that are known to fail out in the field to return bool instead of void. * Where those methods are called, check the return value and report errors * In debug builds use a specialized template class that forces callers to check return values (this is possible at compile time in gcc, but unfortunately not in VS). The next step will be to change the implementation to not use STL containers. TEST=Run courgette tests. BUG=74777 Review URL: http://codereview.chromium.org/6716006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/streams.h')
-rw-r--r--courgette/streams.h31
1 files changed, 19 insertions, 12 deletions
diff --git a/courgette/streams.h b/courgette/streams.h
index 7be28a5..a778185 100644
--- a/courgette/streams.h
+++ b/courgette/streams.h
@@ -4,11 +4,11 @@
// Streams classes.
//
-// These memory-resident streams are used for serialzing data into a sequential
+// These memory-resident streams are used for serializing data into a sequential
// region of memory.
// Streams are divided into SourceStreams for reading and SinkStreams for
// writing. Streams are aggregated into Sets which allows several streams to be
-// used at once. Example: we can write A1, B1, A2, B2 but achive the memory
+// used at once. Example: we can write A1, B1, A2, B2 but achieve the memory
// layout A1 A2 B1 B2 by writing 'A's to one stream and 'B's to another.
#ifndef COURGETTE_STREAMS_H_
#define COURGETTE_STREAMS_H_
@@ -17,10 +17,12 @@
#include <string>
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "courgette/memory_allocator.h"
#include "courgette/region.h"
+
namespace courgette {
class SourceStream;
@@ -109,7 +111,7 @@ class SourceStream {
};
// A SinkStream accumulates writes into a buffer that it owns. The stream is
-// initialy in an 'accumulating' state where writes are permitted. Accessing
+// initially in an 'accumulating' state where writes are permitted. Accessing
// the buffer moves the stream into a 'locked' state where no more writes are
// permitted. The stream may also be in a 'retired' state where the buffer
// contents are no longer available.
@@ -119,21 +121,21 @@ class SinkStream {
~SinkStream() {}
// Appends |byte_count| bytes from |data| to the stream.
- void Write(const void* data, size_t byte_count);
+ CheckBool Write(const void* data, size_t byte_count) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- void WriteVarint32(uint32 value);
+ CheckBool WriteVarint32(uint32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- void WriteVarint32Signed(int32 value);
+ CheckBool WriteVarint32Signed(int32 value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
// On platforms where sizeof(size_t) != sizeof(int32), do a safety check.
- void WriteSizeVarint32(size_t value);
+ CheckBool WriteSizeVarint32(size_t value) WARN_UNUSED_RESULT;
// Contents of |other| are appended to |this| stream. The |other| stream
// becomes retired.
- void Append(SinkStream* other);
+ CheckBool Append(SinkStream* other) WARN_UNUSED_RESULT;
// Returns the number of bytes in this SinkStream
size_t Length() const { return buffer_.size(); }
@@ -146,7 +148,12 @@ class SinkStream {
}
// Hints that the stream will grow by an additional |length| bytes.
- void Reserve(size_t length) { buffer_.reserve(length + buffer_.length()); }
+ // Caller must be prepared to handle memory allocation problems.
+ CheckBool Reserve(size_t length) WARN_UNUSED_RESULT {
+ buffer_.reserve(length + buffer_.length());
+ //TODO(tommi): return false when allocation fails.
+ return true;
+ }
// Finished with this stream and any storage it has.
void Retire();
@@ -215,15 +222,15 @@ class SinkStreamSet {
// CopyTo serializes the streams in this SinkStreamSet into a single target
// stream. The serialized format may be re-read by initializing a
// SourceStreamSet with a buffer containing the data.
- bool CopyTo(SinkStream* combined_stream);
+ CheckBool CopyTo(SinkStream* combined_stream);
// Writes the streams of |set| into the corresponding streams of |this|.
// Stream zero first has some metadata written to it. |set| becomes retired.
// Partner to SourceStreamSet::ReadSet.
- bool WriteSet(SinkStreamSet* set);
+ CheckBool WriteSet(SinkStreamSet* set);
private:
- void CopyHeaderTo(SinkStream* stream);
+ CheckBool CopyHeaderTo(SinkStream* stream);
size_t count_;
SinkStream streams_[kMaxStreams];