OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef WTF_RawPtr_h | 31 #ifndef WTF_RawPtr_h |
32 #define WTF_RawPtr_h | 32 #define WTF_RawPtr_h |
33 | 33 |
34 #include <algorithm> | 34 #include <algorithm> |
| 35 #include <stdint.h> |
| 36 |
35 #include "wtf/HashTableDeletedValueType.h" | 37 #include "wtf/HashTableDeletedValueType.h" |
36 | 38 |
37 // RawPtr is a simple wrapper for a raw pointer that provides the | 39 // RawPtr is a simple wrapper for a raw pointer that provides the |
38 // interface (get, clear) of other pointer types such as RefPtr, | 40 // interface (get, clear) of other pointer types such as RefPtr, |
39 // Persistent and Member. This is used for the Blink garbage | 41 // Persistent and Member. This is used for the Blink garbage |
40 // collection work in order to be able to write shared code that will | 42 // collection work in order to be able to write shared code that will |
41 // use reference counting or garbage collection based on a | 43 // use reference counting or garbage collection based on a |
42 // compile-time flag. | 44 // compile-time flag. |
43 | 45 |
44 namespace WTF { | 46 namespace WTF { |
45 | 47 |
46 template<typename T> | 48 template<typename T> |
47 class RawPtr { | 49 class RawPtr { |
48 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RawPtr); | 50 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RawPtr); |
49 WTF_DISALLOW_ZERO_ASSIGNMENT(RawPtr); | 51 WTF_DISALLOW_ZERO_ASSIGNMENT(RawPtr); |
50 public: | 52 public: |
51 RawPtr() : m_ptr(0) { } | 53 RawPtr() |
| 54 { |
| 55 #ifndef NDEBUG |
| 56 m_ptr = reinterpret_cast<T*>(rawPtrZapValue); |
| 57 #endif |
| 58 } |
52 RawPtr(std::nullptr_t) : m_ptr(0) { } | 59 RawPtr(std::nullptr_t) : m_ptr(0) { } |
53 RawPtr(T* ptr) : m_ptr(ptr) { } | 60 RawPtr(T* ptr) : m_ptr(ptr) { } |
54 explicit RawPtr(T& reference) : m_ptr(&reference) { } | 61 explicit RawPtr(T& reference) : m_ptr(&reference) { } |
55 RawPtr(const RawPtr& other) | 62 RawPtr(const RawPtr& other) |
56 : m_ptr(other.get()) | 63 : m_ptr(other.get()) |
57 { | 64 { |
58 } | 65 } |
59 | 66 |
60 template<typename U> | 67 template<typename U> |
61 RawPtr(const RawPtr<U>& other) | 68 RawPtr(const RawPtr<U>& other) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 bool operator!() const { return !m_ptr; } | 116 bool operator!() const { return !m_ptr; } |
110 | 117 |
111 void swap(RawPtr& o) | 118 void swap(RawPtr& o) |
112 { | 119 { |
113 std::swap(m_ptr, o.m_ptr); | 120 std::swap(m_ptr, o.m_ptr); |
114 } | 121 } |
115 | 122 |
116 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 123 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
117 | 124 |
118 private: | 125 private: |
| 126 static const uintptr_t rawPtrZapValue = 0x3a3a3a3a; |
119 T* m_ptr; | 127 T* m_ptr; |
120 }; | 128 }; |
121 | 129 |
122 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP
tr<U>& p) | 130 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP
tr<U>& p) |
123 { | 131 { |
124 return RawPtr<T>(static_cast<T*>(p.get())); | 132 return RawPtr<T>(static_cast<T*>(p.get())); |
125 } | 133 } |
126 | 134 |
127 template<typename T> inline T* getPtr(const RawPtr<T>& p) | 135 template<typename T> inline T* getPtr(const RawPtr<T>& p) |
128 { | 136 { |
129 return p.get(); | 137 return p.get(); |
130 } | 138 } |
131 | 139 |
132 } // namespace WTF | 140 } // namespace WTF |
133 | 141 |
134 using WTF::RawPtr; | 142 using WTF::RawPtr; |
135 | 143 |
136 #endif | 144 #endif |
OLD | NEW |