| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 WTF_Allocator_h | 5 #ifndef WTF_Allocator_h |
| 6 #define WTF_Allocator_h | 6 #define WTF_Allocator_h |
| 7 | 7 |
| 8 #include "wtf/StdLibExtras.h" |
| 9 |
| 8 namespace WTF { | 10 namespace WTF { |
| 9 | 11 |
| 10 // Classes that contain references to garbage-collected objects but aren't | 12 // Classes that contain references to garbage-collected objects but aren't |
| 11 // themselves garbaged allocated, have some extra macros available which | 13 // themselves garbaged allocated, have some extra macros available which |
| 12 // allows their use to be restricted to cases where the garbage collector | 14 // allows their use to be restricted to cases where the garbage collector |
| 13 // is able to discover their references. These macros will be useful for | 15 // is able to discover their references. These macros will be useful for |
| 14 // non-garbage-collected objects to avoid unintended allocations. | 16 // non-garbage-collected objects to avoid unintended allocations. |
| 15 // | 17 // |
| 16 // STACK_ALLOCATED(): Use if the object is only stack allocated. | 18 // STACK_ALLOCATED(): Use if the object is only stack allocated. |
| 17 // Garbage-collected objects should be in Members but you do not need the | 19 // Garbage-collected objects should be in Members but you do not need the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 38 #define ALLOW_ONLY_INLINE_ALLOCATION()
\ | 40 #define ALLOW_ONLY_INLINE_ALLOCATION()
\ |
| 39 public:
\ | 41 public:
\ |
| 40 using IsAllowOnlyInlineAllocation = int;
\ | 42 using IsAllowOnlyInlineAllocation = int;
\ |
| 41 void* operator new(size_t, NotNullTag, void* location) { return location
; } \ | 43 void* operator new(size_t, NotNullTag, void* location) { return location
; } \ |
| 42 void* operator new(size_t, void* location) { return location; }
\ | 44 void* operator new(size_t, void* location) { return location; }
\ |
| 43 private:
\ | 45 private:
\ |
| 44 void* operator new(size_t) = delete; | 46 void* operator new(size_t) = delete; |
| 45 | 47 |
| 46 #define STATIC_ONLY(Type) \ | 48 #define STATIC_ONLY(Type) \ |
| 47 private: \ | 49 private: \ |
| 48 Type() = delete; | 50 Type() = delete; \ |
| 51 Type(const Type&) = delete; \ |
| 52 Type& operator=(const Type&) = delete; \ |
| 53 void* operator new(size_t) = delete; \ |
| 54 void* operator new(size_t, NotNullTag, void*) = delete; \ |
| 55 void* operator new(size_t, void*) = delete; |
| 49 | 56 |
| 50 #if COMPILER(CLANG) | 57 #if COMPILER(CLANG) |
| 51 #define STACK_ALLOCATED() \ | 58 #define STACK_ALLOCATED() \ |
| 52 private: \ | 59 private: \ |
| 53 __attribute__((annotate("blink_stack_allocated"))) \ | 60 __attribute__((annotate("blink_stack_allocated"))) \ |
| 54 void* operator new(size_t) = delete; \ | 61 void* operator new(size_t) = delete; \ |
| 55 void* operator new(size_t, NotNullTag, void*) = delete; \ | 62 void* operator new(size_t, NotNullTag, void*) = delete; \ |
| 56 void* operator new(size_t, void*) = delete; | 63 void* operator new(size_t, void*) = delete; |
| 57 #else | 64 #else |
| 58 #define STACK_ALLOCATED() DISALLOW_ALLOCATION() | 65 #define STACK_ALLOCATED() DISALLOW_ALLOCATION() |
| 59 #endif | 66 #endif |
| 60 | 67 |
| 61 } // namespace WTF | 68 } // namespace WTF |
| 62 | 69 |
| 63 #endif /* WTF_Allocator_h */ | 70 #endif /* WTF_Allocator_h */ |
| OLD | NEW |