]> git.saurik.com Git - apple/libdispatch.git/blob - os/linux_base.h
libdispatch-913.1.6.tar.gz
[apple/libdispatch.git] / os / linux_base.h
1 /*
2 * This source file is part of the Swift.org open source project
3 *
4 * Copyright (c) 2015 Apple Inc. and the Swift project authors
5 *
6 * Licensed under Apache License v2.0 with Runtime Library Exception
7 *
8 * See http://swift.org/LICENSE.txt for license information
9 * See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 *
11 */
12
13 #ifndef __OS_LINUX_BASE__
14 #define __OS_LINUX_BASE__
15
16 #include <sys/param.h>
17
18 #if HAVE_SYS_CDEFS_H
19 #include <sys/cdefs.h>
20 #endif
21
22 #ifndef API_AVAILABLE
23 #define API_AVAILABLE(...)
24 #endif
25 #ifndef API_DEPRECATED
26 #define API_DEPRECATED(...)
27 #endif
28 #ifndef API_UNAVAILABLE
29 #define API_UNAVAILABLE(...)
30 #endif
31 #ifndef API_DEPRECATED_WITH_REPLACEMENT
32 #define API_DEPRECATED_WITH_REPLACEMENT(...)
33 #endif
34
35 #if __GNUC__
36 #define OS_EXPECT(x, v) __builtin_expect((x), (v))
37 #define OS_UNUSED __attribute__((__unused__))
38 #else
39 #define OS_EXPECT(x, v) (x)
40 #define OS_UNUSED
41 #endif
42
43 #ifndef os_likely
44 #define os_likely(x) OS_EXPECT(!!(x), 1)
45 #endif
46 #ifndef os_unlikely
47 #define os_unlikely(x) OS_EXPECT(!!(x), 0)
48 #endif
49
50 #if __has_feature(assume_nonnull)
51 #define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
52 #define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
53 #else
54 #define OS_ASSUME_NONNULL_BEGIN
55 #define OS_ASSUME_NONNULL_END
56 #endif
57
58 #if __has_builtin(__builtin_assume)
59 #define OS_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr)
60 #else
61 #define OS_COMPILER_CAN_ASSUME(expr) ((void)(expr))
62 #endif
63
64 #if __has_feature(attribute_availability_swift)
65 // equivalent to __SWIFT_UNAVAILABLE from Availability.h
66 #define OS_SWIFT_UNAVAILABLE(_msg) \
67 __attribute__((__availability__(swift, unavailable, message=_msg)))
68 #else
69 #define OS_SWIFT_UNAVAILABLE(_msg)
70 #endif
71
72 #if __has_attribute(swift_private)
73 # define OS_REFINED_FOR_SWIFT __attribute__((__swift_private__))
74 #else
75 # define OS_REFINED_FOR_SWIFT
76 #endif
77
78 #if __has_attribute(swift_name)
79 # define OS_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name)))
80 #else
81 # define OS_SWIFT_NAME(_name)
82 #endif
83
84 #define __OS_STRINGIFY(s) #s
85 #define OS_STRINGIFY(s) __OS_STRINGIFY(s)
86 #define __OS_CONCAT(x, y) x ## y
87 #define OS_CONCAT(x, y) __OS_CONCAT(x, y)
88
89 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
90 #define OS_ENUM(_name, _type, ...) \
91 typedef enum : _type { __VA_ARGS__ } _name##_t
92 #else
93 #define OS_ENUM(_name, _type, ...) \
94 enum { __VA_ARGS__ }; typedef _type _name##_t
95 #endif
96
97 /*
98 * Stub out misc linking and compilation attributes
99 */
100
101 #ifdef OS_EXPORT
102 #undef OS_EXPORT
103 #endif
104 #define OS_EXPORT
105
106 #ifdef OS_WARN_RESULT_NEEDS_RELEASE
107 #undef OS_WARN_RESULT_NEEDS_RELEASE
108 #endif
109
110 #ifdef OS_WARN_RESULT
111 #undef OS_WARN_RESULT
112 #endif
113 #define OS_WARN_RESULT
114
115 #ifdef OS_NOTHROW
116 #undef OS_NOTHROW
117 #endif
118 #define OS_NOTHROW
119
120 #endif /* __OS_LINUX_BASE__ */