Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: courgette/memory_allocator.h

Issue 6716006: Identifying call sites that need to handle out of memory situations in Courgette. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « courgette/ensemble_apply.cc ('k') | courgette/streams.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_ 5 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_
6 #define COURGETTE_MEMORY_ALLOCATOR_H_ 6 #define COURGETTE_MEMORY_ALLOCATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 14
15 #ifndef NDEBUG
16
17 // A helper class to track down call sites that are not handling error cases.
18 template<class T>
19 class CheckReturnValue {
20 public:
21 // Not marked explicit on purpose.
22 CheckReturnValue(T value) : value_(value), checked_(false) { // NOLINT
23 }
24 CheckReturnValue(const CheckReturnValue& other)
25 : value_(other.value_), checked_(other.checked_) {
26 other.checked_ = true;
27 }
28
29 CheckReturnValue& operator=(const CheckReturnValue& other) {
30 if (this != &other) {
31 DCHECK(checked_);
32 value_ = other.value_;
33 checked_ = other.checked_;
34 other.checked_ = true;
35 }
36 }
37
38 ~CheckReturnValue() {
39 DCHECK(checked_);
40 }
41
42 operator const T&() const {
43 checked_ = true;
44 return value_;
45 }
46
47 private:
48 T value_;
49 mutable bool checked_;
50 };
51 typedef CheckReturnValue<bool> CheckBool;
52 #else
53 typedef bool CheckBool;
54 #endif
55
15 namespace courgette { 56 namespace courgette {
16 57
17 #ifdef OS_WIN 58 #ifdef OS_WIN
18 59
19 // Manages a temporary file. The file is created in the %TEMP% folder and 60 // Manages a temporary file. The file is created in the %TEMP% folder and
20 // is deleted when the file handle is closed. 61 // is deleted when the file handle is closed.
21 // NOTE: Since the file will be used as backing for a memory allocation, 62 // NOTE: Since the file will be used as backing for a memory allocation,
22 // it will never be so big that size_t cannot represent its size. 63 // it will never be so big that size_t cannot represent its size.
23 class TempFile { 64 class TempFile {
24 public: 65 public:
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 template<class T> 256 template<class T>
216 class MemoryAllocator : public std::allocator<T> { 257 class MemoryAllocator : public std::allocator<T> {
217 public: 258 public:
218 }; 259 };
219 260
220 #endif // OS_WIN 261 #endif // OS_WIN
221 262
222 } // namespace courgette 263 } // namespace courgette
223 264
224 #endif // COURGETTE_MEMORY_ALLOCATOR_H_ 265 #endif // COURGETTE_MEMORY_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « courgette/ensemble_apply.cc ('k') | courgette/streams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698