objc-api.h (9229B) - Raw
1 /* 2 * Copyright (c) 1999-2006 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 // Copyright 1988-1996 NeXT Software, Inc. 24 25 #ifndef _OBJC_OBJC_API_H_ 26 #define _OBJC_OBJC_API_H_ 27 28 #include <Availability.h> 29 #include <AvailabilityMacros.h> 30 #include <TargetConditionals.h> 31 #include <stddef.h> 32 #include <sys/types.h> 33 34 #ifndef __has_feature 35 # define __has_feature(x) 0 36 #endif 37 38 #ifndef __has_extension 39 # define __has_extension __has_feature 40 #endif 41 42 #ifndef __has_attribute 43 # define __has_attribute(x) 0 44 #endif 45 46 #if !__has_feature(nullability) 47 # ifndef _Nullable 48 # define _Nullable 49 # endif 50 # ifndef _Nonnull 51 # define _Nonnull 52 # endif 53 # ifndef _Null_unspecified 54 # define _Null_unspecified 55 # endif 56 #endif 57 58 59 60 /* 61 * OBJC_API_VERSION 0 or undef: Tiger and earlier API only 62 * OBJC_API_VERSION 2: Leopard and later API available 63 */ 64 #if !defined(OBJC_API_VERSION) 65 # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5 66 # define OBJC_API_VERSION 0 67 # else 68 # define OBJC_API_VERSION 2 69 # endif 70 #endif 71 72 73 /* 74 * OBJC_NO_GC 1: GC is not supported 75 * OBJC_NO_GC undef: GC is supported. This SDK no longer supports this mode. 76 * 77 * OBJC_NO_GC_API undef: Libraries must export any symbols that 78 * dual-mode code may links to. 79 * OBJC_NO_GC_API 1: Libraries need not export GC-related symbols. 80 */ 81 #if defined(__OBJC_GC__) 82 # error Objective-C garbage collection is not supported. 83 #elif TARGET_OS_OSX 84 /* GC is unsupported. GC API symbols are exported. */ 85 # define OBJC_NO_GC 1 86 # undef OBJC_NO_GC_API 87 #else 88 /* GC is unsupported. GC API symbols are not exported. */ 89 # define OBJC_NO_GC 1 90 # define OBJC_NO_GC_API 1 91 #endif 92 93 94 /* NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER == 1 95 * marks -[NSObject init] as a designated initializer. */ 96 #if !defined(NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER) 97 # define NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER 1 98 #endif 99 100 /* The arm64 ABI requires proper casting to ensure arguments are passed 101 * * correctly. */ 102 #if defined(__arm64__) && !__swift__ 103 # undef OBJC_OLD_DISPATCH_PROTOTYPES 104 # define OBJC_OLD_DISPATCH_PROTOTYPES 0 105 #endif 106 107 /* OBJC_OLD_DISPATCH_PROTOTYPES == 0 enforces the rule that the dispatch 108 * functions must be cast to an appropriate function pointer type. */ 109 #if !defined(OBJC_OLD_DISPATCH_PROTOTYPES) 110 # if __swift__ 111 // Existing Swift code expects IMP to be Comparable. 112 // Variadic IMP is comparable via OpaquePointer; non-variadic IMP isn't. 113 # define OBJC_OLD_DISPATCH_PROTOTYPES 1 114 # else 115 # define OBJC_OLD_DISPATCH_PROTOTYPES 0 116 # endif 117 #endif 118 119 120 /* OBJC_AVAILABLE: shorthand for all-OS availability */ 121 122 # if !defined(OBJC_AVAILABLE) 123 # define OBJC_AVAILABLE(x, i, t, w, b) \ 124 __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \ 125 __WATCHOS_AVAILABLE(w) 126 # endif 127 128 129 130 /* OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE: Deprecated on OS X, 131 * unavailable everywhere else. */ 132 133 # if !defined(OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE) 134 # define OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(_start, _dep, _msg) \ 135 __OSX_DEPRECATED(_start, _dep, _msg) \ 136 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \ 137 __WATCHOS_UNAVAILABLE 138 # endif 139 140 141 142 /* OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE: Available on OS X, 143 * unavailable everywhere else. */ 144 145 # if !defined(OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE) 146 # define OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(vers) \ 147 __OSX_AVAILABLE(vers) \ 148 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \ 149 __WATCHOS_UNAVAILABLE 150 # endif 151 152 153 154 /* OBJC_ISA_AVAILABILITY: `isa` will be deprecated or unavailable 155 * in the future */ 156 #if !defined(OBJC_ISA_AVAILABILITY) 157 # define OBJC_ISA_AVAILABILITY __attribute__((deprecated)) 158 #endif 159 160 /* OBJC_UNAVAILABLE: unavailable, with a message where supported */ 161 #if !defined(OBJC_UNAVAILABLE) 162 # if __has_extension(attribute_unavailable_with_message) 163 # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable(_msg))) 164 # else 165 # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable)) 166 # endif 167 #endif 168 169 /* OBJC_DEPRECATED: deprecated, with a message where supported */ 170 #if !defined(OBJC_DEPRECATED) 171 # if __has_extension(attribute_deprecated_with_message) 172 # define OBJC_DEPRECATED(_msg) __attribute__((deprecated(_msg))) 173 # else 174 # define OBJC_DEPRECATED(_msg) __attribute__((deprecated)) 175 # endif 176 #endif 177 178 /* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */ 179 #if !defined(OBJC_ARC_UNAVAILABLE) 180 # if __has_feature(objc_arc) 181 # define OBJC_ARC_UNAVAILABLE OBJC_UNAVAILABLE("not available in automatic reference counting mode") 182 # else 183 # define OBJC_ARC_UNAVAILABLE 184 # endif 185 #endif 186 187 /* OBJC_SWIFT_UNAVAILABLE: unavailable in Swift */ 188 #if !defined(OBJC_SWIFT_UNAVAILABLE) 189 # if __has_feature(attribute_availability_swift) 190 # define OBJC_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg))) 191 # else 192 # define OBJC_SWIFT_UNAVAILABLE(_msg) 193 # endif 194 #endif 195 196 /* OBJC_ARM64_UNAVAILABLE: unavailable on arm64 (i.e. stret dispatch) */ 197 #if !defined(OBJC_ARM64_UNAVAILABLE) 198 # if defined(__arm64__) 199 # define OBJC_ARM64_UNAVAILABLE OBJC_UNAVAILABLE("not available in arm64") 200 # else 201 # define OBJC_ARM64_UNAVAILABLE 202 # endif 203 #endif 204 205 /* OBJC_GC_UNAVAILABLE: unavailable with -fobjc-gc or -fobjc-gc-only */ 206 #if !defined(OBJC_GC_UNAVAILABLE) 207 # define OBJC_GC_UNAVAILABLE 208 #endif 209 210 #if !defined(OBJC_EXTERN) 211 # if defined(__cplusplus) 212 # define OBJC_EXTERN extern "C" 213 # else 214 # define OBJC_EXTERN extern 215 # endif 216 #endif 217 218 #if !defined(OBJC_VISIBLE) 219 # define OBJC_VISIBLE __attribute__((visibility("default"))) 220 #endif 221 222 #if !defined(OBJC_EXPORT) 223 # define OBJC_EXPORT OBJC_EXTERN OBJC_VISIBLE 224 #endif 225 226 #if !defined(OBJC_IMPORT) 227 # define OBJC_IMPORT extern 228 #endif 229 230 #if !defined(OBJC_ROOT_CLASS) 231 # if __has_attribute(objc_root_class) 232 # define OBJC_ROOT_CLASS __attribute__((objc_root_class)) 233 # else 234 # define OBJC_ROOT_CLASS 235 # endif 236 #endif 237 238 #ifndef __DARWIN_NULL 239 #define __DARWIN_NULL NULL 240 #endif 241 242 #if !defined(OBJC_INLINE) 243 # define OBJC_INLINE __inline 244 #endif 245 246 // Declares an enum type or option bits type as appropriate for each language. 247 #if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum)) 248 #define OBJC_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 249 #if (__cplusplus) 250 #define OBJC_OPTIONS(_type, _name) _type _name; enum : _type 251 #else 252 #define OBJC_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type 253 #endif 254 #else 255 #define OBJC_ENUM(_type, _name) _type _name; enum 256 #define OBJC_OPTIONS(_type, _name) _type _name; enum 257 #endif 258 259 #if !defined(OBJC_RETURNS_RETAINED) 260 # if __OBJC__ && __has_attribute(ns_returns_retained) 261 # define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained)) 262 # else 263 # define OBJC_RETURNS_RETAINED 264 # endif 265 #endif 266 267 /* OBJC_COLD: very rarely called, e.g. on error path */ 268 #if !defined(OBJC_COLD) 269 # if __OBJC__ && __has_attribute(cold) 270 # define OBJC_COLD __attribute__((cold)) 271 # else 272 # define OBJC_COLD 273 # endif 274 #endif 275 276 /* OBJC_NORETURN: does not return normally, but may throw */ 277 #if !defined(OBJC_NORETURN) 278 # if __OBJC__ && __has_attribute(noreturn) 279 # define OBJC_NORETURN __attribute__((noreturn)) 280 # else 281 # define OBJC_NORETURN 282 # endif 283 #endif 284 285 /* OBJC_NOESCAPE: marks a block as nonescaping */ 286 #if !defined(OBJC_NOESCAPE) 287 # if __has_attribute(noescape) 288 # define OBJC_NOESCAPE __attribute__((noescape)) 289 # else 290 # define OBJC_NOESCAPE 291 # endif 292 #endif 293 294 /* OBJC_REFINED_FOR_SWIFT: hide the definition from Swift as we have a 295 better one in the overlay */ 296 #if !defined(OBJC_REFINED_FOR_SWIFT) 297 # if __has_attribute(swift_private) 298 # define OBJC_REFINED_FOR_SWIFT __attribute__((swift_private)) 299 # else 300 # define OBJC_REFINED_FOR_SWIFT 301 # endif 302 #endif 303 304 #if __has_attribute(not_tail_called) 305 # define OBJC_NOT_TAIL_CALLED __attribute__((not_tail_called)) 306 #else 307 # define OBJC_NOT_TAIL_CALLED 308 #endif 309 310 #endif