Blame view

Pods/Realm/include/core/realm/util/features.h 9.02 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
  /*************************************************************************
   *
   * Copyright 2016 Realm Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   **************************************************************************/
  
  #ifndef REALM_UTIL_FEATURES_H
  #define REALM_UTIL_FEATURES_H
  
  #ifdef _MSC_VER
  #pragma warning(disable : 4800) // Visual Studio int->bool performance warnings
  #endif
  
  #if defined(_WIN32) && !defined(NOMINMAX)
  #define NOMINMAX
  #endif
  
  #ifndef REALM_NO_CONFIG
  #include <realm/util/config.h>
  #endif
  
  /* The maximum number of elements in a B+-tree node. Applies to inner nodes and
   * to leaves. The minimum allowable value is 2.
   */
  #ifndef REALM_MAX_BPNODE_SIZE
  #define REALM_MAX_BPNODE_SIZE 1000
  #endif
  
  
  #define REALM_QUOTE_2(x) #x
  #define REALM_QUOTE(x) REALM_QUOTE_2(x)
  
  /* See these links for information about feature check macroes in GCC,
   * Clang, and MSVC:
   *
   * http://gcc.gnu.org/projects/cxx0x.html
   * http://clang.llvm.org/cxx_status.html
   * http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-standard-language-features
   * http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
   * http://sourceforge.net/p/predef/wiki/Compilers
   */
  
  
  /* Compiler is GCC and version is greater than or equal to the specified version */
  #define REALM_HAVE_AT_LEAST_GCC(maj, min) \
      (__GNUC__ > (maj) || __GNUC__ == (maj) && __GNUC_MINOR__ >= (min))
  
  #if defined(__clang__)
  #define REALM_HAVE_CLANG_FEATURE(feature) __has_feature(feature)
  #define REALM_HAVE_CLANG_WARNING(warning) __has_warning(warning)
  #else
  #define REALM_HAVE_CLANG_FEATURE(feature) 0
  #define REALM_HAVE_CLANG_WARNING(warning) 0
  #endif
  
  #ifdef __has_cpp_attribute
  #define REALM_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr)
  #else
  #define REALM_HAS_CPP_ATTRIBUTE(attr) 0
  #endif
  
  #if REALM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
  #define REALM_FALLTHROUGH [[clang::fallthrough]]
  #elif REALM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
  #define REALM_FALLTHROUGH [[gnu::fallthrough]]
  #elif REALM_HAS_CPP_ATTRIBUTE(fallthrough)
  #define REALM_FALLTHROUGH [[fallthrough]]
  #else
  #define REALM_FALLTHROUGH
  #endif
  
  // This should be renamed to REALM_UNREACHABLE as soon as REALM_UNREACHABLE is renamed to
  // REALM_ASSERT_NOT_REACHED which will better reflect its nature
  #if defined(__GNUC__) || defined(__clang__)
  #define REALM_COMPILER_HINT_UNREACHABLE __builtin_unreachable
  #else
  #define REALM_COMPILER_HINT_UNREACHABLE abort
  #endif
  
  #if defined(__GNUC__) // clang or GCC
  #define REALM_PRAGMA(v) _Pragma(REALM_QUOTE_2(v))
  #elif defined(_MSC_VER) // VS
  #define REALM_PRAGMA(v) __pragma(v)
  #else
  #define REALM_PRAGMA(v)
  #endif
  
  #if defined(__clang__)
  #define REALM_DIAG(v) REALM_PRAGMA(clang diagnostic v)
  #elif defined(__GNUC__)
  #define REALM_DIAG(v) REALM_PRAGMA(GCC diagnostic v)
  #else
  #define REALM_DIAG(v)
  #endif
  
  #define REALM_DIAG_PUSH() REALM_DIAG(push)
  #define REALM_DIAG_POP() REALM_DIAG(pop)
  
  #ifdef _MSC_VER
  #define REALM_VS_WARNING_DISABLE #pragma warning (default: 4297)
  #endif
  
  #if REALM_HAVE_CLANG_WARNING("-Wtautological-compare") || REALM_HAVE_AT_LEAST_GCC(6, 0)
  #define REALM_DIAG_IGNORE_TAUTOLOGICAL_COMPARE() REALM_DIAG(ignored "-Wtautological-compare")
  #else
  #define REALM_DIAG_IGNORE_TAUTOLOGICAL_COMPARE()
  #endif
  
  #ifdef _MSC_VER
  #  define REALM_DIAG_IGNORE_UNSIGNED_MINUS() REALM_PRAGMA(warning(disable:4146))
  #else
  #define REALM_DIAG_IGNORE_UNSIGNED_MINUS()
  #endif
  
  /* Compiler is MSVC (Microsoft Visual C++) */
  #if defined(_MSC_VER) && _MSC_VER >= 1600
  #define REALM_HAVE_AT_LEAST_MSVC_10_2010 1
  #endif
  #if defined(_MSC_VER) && _MSC_VER >= 1700
  #define REALM_HAVE_AT_LEAST_MSVC_11_2012 1
  #endif
  #if defined(_MSC_VER) && _MSC_VER >= 1800
  #define REALM_HAVE_AT_LEAST_MSVC_12_2013 1
  #endif
  
  
  /* The way to specify that a function never returns. */
  #if REALM_HAVE_AT_LEAST_GCC(4, 8) || REALM_HAVE_CLANG_FEATURE(cxx_attributes)
  #define REALM_NORETURN [[noreturn]]
  #elif __GNUC__
  #define REALM_NORETURN __attribute__((noreturn))
  #elif defined(_MSC_VER)
  #define REALM_NORETURN __declspec(noreturn)
  #else
  #define REALM_NORETURN
  #endif
  
  
  /* The way to specify that a variable or type is intended to possibly
   * not be used. Use it to suppress a warning from the compiler. */
  #if __GNUC__
  #define REALM_UNUSED __attribute__((unused))
  #else
  #define REALM_UNUSED
  #endif
  
  /* The way to specify that a function is deprecated
   * not be used. Use it to suppress a warning from the compiler. */
  #if __GNUC__
  #define REALM_DEPRECATED(x) [[deprecated(x)]]
  #else
  #define REALM_DEPRECATED(x) __declspec(deprecated(x))
  #endif
  
  
  #if __GNUC__ || defined __INTEL_COMPILER
  #define REALM_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
  #define REALM_LIKELY(expr) __builtin_expect(!!(expr), 1)
  #else
  #define REALM_UNLIKELY(expr) (expr)
  #define REALM_LIKELY(expr) (expr)
  #endif
  
  
  #if defined(__GNUC__) || defined(__HP_aCC)
  #define REALM_FORCEINLINE inline __attribute__((always_inline))
  #elif defined(_MSC_VER)
  #define REALM_FORCEINLINE __forceinline
  #else
  #define REALM_FORCEINLINE inline
  #endif
  
  
  #if REALM_HAS_CPP_ATTRIBUTE(gnu::cold)
  #define REALM_COLD [[gnu::cold]]
  #else
  #define REALM_COLD
  #endif
  
  
  #if REALM_HAS_CPP_ATTRIBUTE(gnu::noinline)
  #define REALM_NOINLINE [[gnu::noinline]]
  #elif defined(__GNUC__) || defined(__HP_aCC)
  #define REALM_NOINLINE __attribute__((noinline))
  #elif defined(_MSC_VER)
  #define REALM_NOINLINE __declspec(noinline)
  #else
  #define REALM_NOINLINE
  #endif
  
  
  #if REALM_HAS_CPP_ATTRIBUTE(nodiscard)
  #define REALM_NODISCARD [[nodiscard]]
  #else
  #if defined(__GNUC__) || defined(__HP_aCC)
  #define REALM_NODISCARD __attribute__((warn_unused_result))
  #elif defined(_MSC_VER)
  #define REALM_NODISCARD _Check_return_
  #else
  #define REALM_NODISCARD
  #endif
  #endif
  
  /* Thread specific data (only for POD types) */
  #if defined __clang__
  #define REALM_THREAD_LOCAL __thread
  #else
  #define REALM_THREAD_LOCAL thread_local
  #endif
  
  
  #if defined ANDROID || defined __ANDROID_API__
  #define REALM_ANDROID 1
  #else
  #define REALM_ANDROID 0
  #endif
  
  #if defined _WIN32
  #include <winapifamily.h>
  #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
  #define REALM_WINDOWS 1
  #define REALM_UWP 0
  #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
  #define REALM_WINDOWS 0
  #define REALM_UWP 1
  #endif
  #else
  #define REALM_WINDOWS 0
  #define REALM_UWP 0
  #endif
  
  // Some documentation of the defines provided by Apple:
  // http://developer.apple.com/library/mac/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html#//apple_ref/doc/uid/TP40002850-SW13
  #if defined __APPLE__ && defined __MACH__
  #define REALM_PLATFORM_APPLE 1
  /* Apple OSX and iOS (Darwin). */
  #include <Availability.h>
  #include <TargetConditionals.h>
  #if TARGET_OS_IPHONE == 1 && TARGET_OS_IOS == 1
  /* Device (iPhone or iPad) or simulator. */
  #define REALM_IOS 1
  #define REALM_APPLE_DEVICE !TARGET_OS_SIMULATOR
  #else
  #define REALM_IOS 0
  #endif
  #if TARGET_OS_WATCH == 1
  /* Device (Apple Watch) or simulator. */
  #define REALM_WATCHOS 1
  #define REALM_APPLE_DEVICE !TARGET_OS_SIMULATOR
  #else
  #define REALM_WATCHOS 0
  #endif
  #if TARGET_OS_TV
  /* Device (Apple TV) or simulator. */
  #define REALM_TVOS 1
  #define REALM_APPLE_DEVICE !TARGET_OS_SIMULATOR
  #else
  #define REALM_TVOS 0
  #endif
  #else
  #define REALM_PLATFORM_APPLE 0
  #define REALM_IOS 0
  #define REALM_WATCHOS 0
  #define REALM_TVOS 0
  #endif
  #ifndef REALM_APPLE_DEVICE
  #define REALM_APPLE_DEVICE 0
  #endif
  
  #if REALM_ANDROID || REALM_IOS || REALM_WATCHOS || REALM_TVOS || REALM_UWP
  #define REALM_MOBILE 1
  #else
  #define REALM_MOBILE 0
  #endif
  
  
  #if defined(REALM_DEBUG) && !defined(REALM_COOKIE_CHECK)
  #define REALM_COOKIE_CHECK
  #endif
  
  // We're in i686 mode
  #if defined(__i386) || defined(__i386__) || defined(__i686__) || defined(_M_I86) || defined(_M_IX86)
  #define REALM_ARCHITECTURE_X86_32 1
  #else
  #define REALM_ARCHITECTURE_X86_32 0
  #endif
  
  // We're in amd64 mode
  #if defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
      defined(_M_AMD64)
  #define REALM_ARCHITECTURE_X86_64 1
  #else
  #define REALM_ARCHITECTURE_X86_64 0
  #endif
  
  // Address Sanitizer
  #if defined(__has_feature) // Clang
  #  if __has_feature(address_sanitizer)
  #    define REALM_SANITIZE_ADDRESS 1
  #  else
  #    define REALM_SANITIZE_ADDRESS 0
  #  endif
  #elif defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ // GCC
  #  define REALM_SANITIZE_ADDRESS 1
  #else
  #  define REALM_SANITIZE_ADDRESS 0
  #endif
  
  // Thread Sanitizer
  #if defined(__has_feature) // Clang
  #  if __has_feature(thread_sanitizer)
  #    define REALM_SANITIZE_THREAD 1
  #  else
  #    define REALM_SANITIZE_THREAD 0
  #  endif
  #elif defined(__SANITIZE_THREAD__) && __SANITIZE_THREAD__ // GCC
  #  define REALM_SANITIZE_THREAD 1
  #else
  #  define REALM_SANITIZE_THREAD 0
  #endif
  
  #endif /* REALM_UTIL_FEATURES_H */