zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

base.h (7546B) - Raw


      1 // Copyright (c) 2009-2011 Apple Inc. All rights reserved.
      2 
      3 #ifndef __XPC_BASE_H__
      4 #define __XPC_BASE_H__
      5 
      6 #include <sys/cdefs.h>
      7 
      8 #if !defined(__has_include)
      9 #define __has_include(x) 0
     10 #endif // !defined(__has_include)
     11 
     12 #if !defined(__has_attribute)
     13 #define __has_attribute(x) 0
     14 #endif // !defined(__has_attribute)
     15 
     16 #if !defined(__has_feature)
     17 #define __has_feature(x) 0
     18 #endif // !defined(__has_feature)
     19 
     20 #if !defined(__has_extension)
     21 #define __has_extension(x) 0
     22 #endif // !defined(__has_extension)
     23 
     24 #if __has_include(<xpc/availability.h>)
     25 #include <xpc/availability.h>
     26 #else // __has_include(<xpc/availability.h>)
     27 #include <Availability.h>
     28 #endif // __has_include(<xpc/availability.h>)
     29 
     30 #include <os/availability.h>
     31 
     32 #ifndef __XPC_INDIRECT__
     33 #error "Please #include <xpc/xpc.h> instead of this file directly."
     34 #endif // __XPC_INDIRECT__ 
     35 
     36 __BEGIN_DECLS
     37 
     38 #pragma mark Attribute Shims
     39 #ifdef __GNUC__
     40 #define XPC_CONSTRUCTOR __attribute__((constructor))
     41 #define XPC_NORETURN __attribute__((__noreturn__))
     42 #define XPC_NOTHROW __attribute__((__nothrow__))
     43 #define XPC_NONNULL1 __attribute__((__nonnull__(1)))
     44 #define XPC_NONNULL2 __attribute__((__nonnull__(2)))
     45 #define XPC_NONNULL3 __attribute__((__nonnull__(3)))
     46 #define XPC_NONNULL4 __attribute__((__nonnull__(4)))
     47 #define XPC_NONNULL5 __attribute__((__nonnull__(5)))
     48 #define XPC_NONNULL6 __attribute__((__nonnull__(6)))
     49 #define XPC_NONNULL7 __attribute__((__nonnull__(7)))
     50 #define XPC_NONNULL8 __attribute__((__nonnull__(8)))
     51 #define XPC_NONNULL9 __attribute__((__nonnull__(9)))
     52 #define XPC_NONNULL10 __attribute__((__nonnull__(10)))
     53 #define XPC_NONNULL11 __attribute__((__nonnull__(11)))
     54 #define XPC_NONNULL_ALL __attribute__((__nonnull__))
     55 #define XPC_SENTINEL __attribute__((__sentinel__))
     56 #define XPC_PURE __attribute__((__pure__))
     57 #define XPC_WARN_RESULT __attribute__((__warn_unused_result__))
     58 #define XPC_MALLOC __attribute__((__malloc__))
     59 #define XPC_UNUSED __attribute__((__unused__))
     60 #define XPC_USED __attribute__((__used__))
     61 #define XPC_PACKED __attribute__((__packed__))
     62 #define XPC_PRINTF(m, n) __attribute__((format(printf, m, n)))
     63 #define XPC_INLINE static __inline__ __attribute__((__always_inline__))
     64 #define XPC_NOINLINE __attribute__((noinline))
     65 #define XPC_NOIMPL __attribute__((unavailable))
     66 
     67 #if __has_attribute(noescape)
     68 #define XPC_NOESCAPE __attribute__((__noescape__))
     69 #else
     70 #define XPC_NOESCAPE
     71 #endif
     72 
     73 #if __has_extension(attribute_unavailable_with_message)
     74 #define XPC_UNAVAILABLE(m) __attribute__((unavailable(m)))
     75 #else // __has_extension(attribute_unavailable_with_message)
     76 #define XPC_UNAVAILABLE(m) XPC_NOIMPL
     77 #endif // __has_extension(attribute_unavailable_with_message)
     78 
     79 #define XPC_EXPORT extern __attribute__((visibility("default")))
     80 #define XPC_NOEXPORT __attribute__((visibility("hidden")))
     81 #define XPC_WEAKIMPORT extern __attribute__((weak_import))
     82 #define XPC_DEBUGGER_EXCL XPC_NOEXPORT XPC_USED
     83 #define XPC_TRANSPARENT_UNION __attribute__((transparent_union))
     84 #if __clang__
     85 #define XPC_DEPRECATED(m) __attribute__((deprecated(m)))
     86 #else // __clang__
     87 #define XPC_DEPRECATED(m) __attribute__((deprecated))
     88 #endif // __clang
     89 #ifndef XPC_TESTEXPORT
     90 #define XPC_TESTEXPORT XPC_NOEXPORT
     91 #endif // XPC_TESTEXPORT
     92 
     93 #if defined(__XPC_TEST__) && __XPC_TEST__
     94 #define XPC_TESTSTATIC
     95 #define XPC_TESTEXTERN extern
     96 #else // defined(__XPC_TEST__) && __XPC_TEST__
     97 #define XPC_TESTSTATIC static
     98 #endif // defined(__XPC_TEST__) && __XPC_TEST__
     99 
    100 #if __has_feature(objc_arc)
    101 #define XPC_GIVES_REFERENCE __strong
    102 #define XPC_UNRETAINED __unsafe_unretained
    103 #define XPC_BRIDGE(xo) ((__bridge void *)(xo))
    104 #define XPC_BRIDGEREF_BEGIN(xo) ((__bridge_retained void *)(xo))
    105 #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) ((__bridge void *)(xo))
    106 #define XPC_BRIDGEREF_MIDDLE(xo) ((__bridge id)(xo))
    107 #define XPC_BRIDGEREF_END(xo) ((__bridge_transfer id)(xo))
    108 #else // __has_feature(objc_arc)
    109 #define XPC_GIVES_REFERENCE
    110 #define XPC_UNRETAINED
    111 #define XPC_BRIDGE(xo) (xo)
    112 #define XPC_BRIDGEREF_BEGIN(xo) (xo)
    113 #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) (xo)
    114 #define XPC_BRIDGEREF_MIDDLE(xo) (xo)
    115 #define XPC_BRIDGEREF_END(xo) (xo)
    116 #endif // __has_feature(objc_arc)
    117 
    118 #define _xpc_unreachable() __builtin_unreachable()
    119 #else // __GNUC__ 
    120 /*! @parseOnly */
    121 #define XPC_CONSTRUCTOR
    122 /*! @parseOnly */
    123 #define XPC_NORETURN
    124 /*! @parseOnly */
    125 #define XPC_NOTHROW
    126 /*! @parseOnly */
    127 #define XPC_NONNULL1
    128 /*! @parseOnly */
    129 #define XPC_NONNULL2
    130 /*! @parseOnly */
    131 #define XPC_NONNULL3
    132 /*! @parseOnly */
    133 #define XPC_NONNULL4
    134 /*! @parseOnly */
    135 #define XPC_NONNULL5
    136 /*! @parseOnly */
    137 #define XPC_NONNULL6
    138 /*! @parseOnly */
    139 #define XPC_NONNULL7
    140 /*! @parseOnly */
    141 #define XPC_NONNULL8
    142 /*! @parseOnly */
    143 #define XPC_NONNULL9
    144 /*! @parseOnly */
    145 #define XPC_NONNULL10
    146 /*! @parseOnly */
    147 #define XPC_NONNULL11
    148 /*! @parseOnly */
    149 #define XPC_NONNULL(n)
    150 /*! @parseOnly */
    151 #define XPC_NONNULL_ALL
    152 /*! @parseOnly */
    153 #define XPC_SENTINEL
    154 /*! @parseOnly */
    155 #define XPC_PURE
    156 /*! @parseOnly */
    157 #define XPC_WARN_RESULT
    158 /*! @parseOnly */
    159 #define XPC_MALLOC
    160 /*! @parseOnly */
    161 #define XPC_UNUSED
    162 /*! @parseOnly */
    163 #define XPC_PACKED
    164 /*! @parseOnly */
    165 #define XPC_PRINTF(m, n)
    166 /*! @parseOnly */
    167 #define XPC_INLINE static inline
    168 /*! @parseOnly */
    169 #define XPC_NOINLINE
    170 /*! @parseOnly */
    171 #define XPC_NOIMPL
    172 /*! @parseOnly */
    173 #define XPC_EXPORT extern
    174 /*! @parseOnly */
    175 #define XPC_WEAKIMPORT
    176 /*! @parseOnly */
    177 #define XPC_DEPRECATED
    178 /*! @parseOnly */
    179 #define XPC_UNAVAILABLE(m)
    180 /*! @parseOnly */
    181 #define XPC_NOESCAPE
    182 #endif // __GNUC__
    183 
    184 #if __has_feature(assume_nonnull)
    185 #define XPC_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
    186 #define XPC_ASSUME_NONNULL_END   _Pragma("clang assume_nonnull end")
    187 #else
    188 #define XPC_ASSUME_NONNULL_BEGIN
    189 #define XPC_ASSUME_NONNULL_END
    190 #endif
    191 
    192 #if __has_feature(nullability_on_arrays)
    193 #define XPC_NONNULL_ARRAY _Nonnull
    194 #else
    195 #define XPC_NONNULL_ARRAY
    196 #endif
    197 
    198 #if defined(__has_ptrcheck) && __has_ptrcheck
    199 #define XPC_PTR_ASSUMES_SINGLE __ptrcheck_abi_assume_single()
    200 #define XPC_SINGLE __single
    201 #define XPC_UNSAFE_INDEXABLE __unsafe_indexable
    202 #define XPC_CSTRING XPC_UNSAFE_INDEXABLE
    203 #define XPC_SIZEDBY(N) __sized_by(N)
    204 #define XPC_COUNTEDBY(N) __counted_by(N)
    205 #define XPC_UNSAFE_FORGE_SIZED_BY(_type, _ptr, _size) \
    206 		__unsafe_forge_bidi_indexable(_type, _ptr, _size)
    207 #define XPC_UNSAFE_FORGE_SINGLE(_type, _ptr) \
    208 		__unsafe_forge_single(_type, _ptr)
    209 #else // defined(__has_ptrcheck) ** __has_ptrcheck
    210 #define XPC_PTR_ASSUMES_SINGLE
    211 #define XPC_SINGLE
    212 #define XPC_UNSAFE_INDEXABLE
    213 #define XPC_CSTRING
    214 #define XPC_SIZEDBY(N)
    215 #define XPC_COUNTEDBY(N)
    216 #define XPC_UNSAFE_FORGE_SIZED_BY(_type, _ptr, _size) ((_type)(_ptr))
    217 #define XPC_UNSAFE_FORGE_SINGLE(_type, _ptr) ((_type)(_ptr))
    218 #endif // defined(__has_ptrcheck) ** __has_ptrcheck
    219 
    220 #ifdef OS_CLOSED_OPTIONS
    221 #define XPC_FLAGS_ENUM(_name, _type, ...) \
    222 		OS_CLOSED_OPTIONS(_name, _type, __VA_ARGS__)
    223 #else // OS_CLOSED_ENUM
    224 #define XPC_FLAGS_ENUM(_name, _type, ...) \
    225 		OS_ENUM(_name, _type, __VA_ARGS__)
    226 #endif // OS_CLOSED_ENUM
    227 
    228 #ifdef OS_CLOSED_ENUM
    229 #define XPC_ENUM(_name, _type, ...) \
    230 		OS_CLOSED_ENUM(_name, _type, __VA_ARGS__)
    231 #else // OS_CLOSED_ENUM
    232 #define XPC_ENUM(_name, _type, ...) \
    233 		OS_ENUM(_name, _type, __VA_ARGS__)
    234 #endif // OS_CLOSED_ENUM
    235 
    236 #if __has_attribute(swift_name)
    237 # define XPC_SWIFT_NAME(_name) __attribute__((swift_name(_name)))
    238 #else
    239 # define XPC_SWIFT_NAME(_name) // __has_attribute(swift_name)
    240 #endif
    241 
    242 #define XPC_SWIFT_UNAVAILABLE(msg) __swift_unavailable(msg)
    243 #define XPC_SWIFT_NOEXPORT XPC_SWIFT_UNAVAILABLE("Unavailable in Swift from the XPC C Module")
    244 
    245 __END_DECLS
    246 
    247 #endif // __XPC_BASE_H__