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