OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 static T& unwrap(T* singleton) { return *singleton; } | 74 static T& unwrap(T* singleton) { return *singleton; } |
75 }; | 75 }; |
76 | 76 |
77 template <typename T> | 77 template <typename T> |
78 class StaticLocalWrapper<T, true> { | 78 class StaticLocalWrapper<T, true> { |
79 public: | 79 public: |
80 using WrapType = blink::Persistent<T>; | 80 using WrapType = blink::Persistent<T>; |
81 | 81 |
82 static T& unwrap(blink::Persistent<T>* singleton) { | 82 static T& unwrap(blink::Persistent<T>* singleton) { |
83 ASSERT(singleton); | 83 ASSERT(singleton); |
84 // If this assert triggers, you're supplying an empty ("()") 'Arguments' arg
ument | 84 // If this assert triggers, you're supplying an empty ("()") 'Arguments' |
85 // to DEFINE_STATIC_LOCAL() - it must be the heap object you wish to create | 85 // argument to DEFINE_STATIC_LOCAL() - it must be the heap object you wish |
86 // as a static singleton and wrapped up with a Persistent reference. | 86 // to create as a static singleton and wrapped up with a Persistent |
| 87 // reference. |
87 ASSERT(*singleton); | 88 ASSERT(*singleton); |
88 return **singleton; | 89 return **singleton; |
89 } | 90 } |
90 }; | 91 }; |
91 | 92 |
92 #if ENABLE(ASSERT) | 93 #if ENABLE(ASSERT) |
93 #define DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name) \ | 94 #define DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name) \ |
94 static StaticLocalVerifier Name##StaticLocalVerifier; \ | 95 static StaticLocalVerifier Name##StaticLocalVerifier; \ |
95 ASSERT(Name##StaticLocalVerifier.isNotRacy()) | 96 ASSERT(Name##StaticLocalVerifier.isNotRacy()) |
96 #else | 97 #else |
(...skipping 14 matching lines...) Expand all Loading... |
111 // details. | 112 // details. |
112 // | 113 // |
113 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ | 114 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ |
114 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ | 115 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ |
115 using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \ | 116 using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \ |
116 static WrappedTypeFor##Name* WrappedInstanceFor##Name = \ | 117 static WrappedTypeFor##Name* WrappedInstanceFor##Name = \ |
117 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ | 118 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ |
118 WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \ | 119 WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \ |
119 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name); | 120 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name); |
120 | 121 |
121 // Use this to declare and define a static local pointer to a ref-counted object
so that | 122 // Use this to declare and define a static local pointer to a ref-counted object |
122 // it is leaked so that the object's destructors are not called at exit. | 123 // so that it is leaked so that the object's destructors are not called at |
123 // This macro should be used with ref-counted objects rather than DEFINE_STATIC_
LOCAL macro, | 124 // exit. This macro should be used with ref-counted objects rather than |
124 // as this macro does not lead to an extra memory allocation. | 125 // DEFINE_STATIC_LOCAL macro, as this macro does not lead to an extra memory |
| 126 // allocation. |
125 #define DEFINE_STATIC_REF(type, name, arguments) \ | 127 #define DEFINE_STATIC_REF(type, name, arguments) \ |
126 static type* name = PassRefPtr<type>(arguments).leakRef(); | 128 static type* name = PassRefPtr<type>(arguments).leakRef(); |
127 | 129 |
128 /* | 130 /* |
129 * The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where | 131 * The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where |
130 * sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC: | 132 * sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC: |
131 * increases required alignment of target type. | 133 * increases required alignment of target type. |
132 * | 134 * |
133 * An implicit or an extra static_cast<void*> bypasses the warning. | 135 * An implicit or an extra static_cast<void*> bypasses the warning. |
134 * For more info see the following bugzilla entries: | 136 * For more info see the following bugzilla entries: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 "Truncating conversions not allowed."); \ | 214 "Truncating conversions not allowed."); \ |
213 static_assert(!std::numeric_limits<ActualArgType>::is_signed || \ | 215 static_assert(!std::numeric_limits<ActualArgType>::is_signed || \ |
214 std::numeric_limits<ExpectedArgType>::is_signed, \ | 216 std::numeric_limits<ExpectedArgType>::is_signed, \ |
215 "Signed to unsigned conversion not allowed."); \ | 217 "Signed to unsigned conversion not allowed."); \ |
216 static_assert((sizeof(ExpectedArgType) != sizeof(ActualArgType)) || \ | 218 static_assert((sizeof(ExpectedArgType) != sizeof(ActualArgType)) || \ |
217 (std::numeric_limits<ActualArgType>::is_signed == \ | 219 (std::numeric_limits<ActualArgType>::is_signed == \ |
218 std::numeric_limits<ExpectedArgType>::is_signed), \ | 220 std::numeric_limits<ExpectedArgType>::is_signed), \ |
219 "Unsigned to signed conversion not allowed for types with " \ | 221 "Unsigned to signed conversion not allowed for types with " \ |
220 "identical size (could overflow)."); | 222 "identical size (could overflow)."); |
221 | 223 |
222 // Macro that returns a compile time constant with the length of an array, but g
ives an error if passed a non-array. | 224 // Macro that returns a compile time constant with the length of an array, but |
| 225 // gives an error if passed a non-array. |
223 template <typename T, size_t Size> | 226 template <typename T, size_t Size> |
224 char (&ArrayLengthHelperFunction(T (&)[Size]))[Size]; | 227 char (&ArrayLengthHelperFunction(T (&)[Size]))[Size]; |
225 // GCC needs some help to deduce a 0 length array. | 228 // GCC needs some help to deduce a 0 length array. |
226 #if COMPILER(GCC) | 229 #if COMPILER(GCC) |
227 template <typename T> | 230 template <typename T> |
228 char (&ArrayLengthHelperFunction(T (&)[0]))[0]; | 231 char (&ArrayLengthHelperFunction(T (&)[0]))[0]; |
229 #endif | 232 #endif |
230 #define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array)) | 233 #define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array)) |
231 | 234 |
232 } // namespace WTF | 235 } // namespace WTF |
233 | 236 |
234 // This version of placement new omits a 0 check. | 237 // This version of placement new omits a 0 check. |
235 enum NotNullTag { NotNull }; | 238 enum NotNullTag { NotNull }; |
236 inline void* operator new(size_t, NotNullTag, void* location) { | 239 inline void* operator new(size_t, NotNullTag, void* location) { |
237 ASSERT(location); | 240 ASSERT(location); |
238 return location; | 241 return location; |
239 } | 242 } |
240 | 243 |
241 using WTF::bitwiseCast; | 244 using WTF::bitwiseCast; |
242 using WTF::safeCast; | 245 using WTF::safeCast; |
243 | 246 |
244 #endif // WTF_StdLibExtras_h | 247 #endif // WTF_StdLibExtras_h |
OLD | NEW |