]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-api.h
objc4-750.tar.gz
[apple/objc4.git] / runtime / objc-api.h
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 <sys/types.h>
32
33 #ifndef __has_feature
34 # define __has_feature(x) 0
35 #endif
36
37 #ifndef __has_extension
38 # define __has_extension __has_feature
39 #endif
40
41 #ifndef __has_attribute
42 # define __has_attribute(x) 0
43 #endif
44
45 #if !__has_feature(nullability)
46 # ifndef _Nullable
47 # define _Nullable
48 # endif
49 # ifndef _Nonnull
50 # define _Nonnull
51 # endif
52 # ifndef _Null_unspecified
53 # define _Null_unspecified
54 # endif
55 #endif
56
57 #ifndef __APPLE_BLEACH_SDK__
58 # if __has_feature(attribute_availability_bridgeos)
59 # ifndef __BRIDGEOS_AVAILABLE
60 # define __BRIDGEOS_AVAILABLE(_vers) __OS_AVAILABILITY(bridgeos,introduced=_vers)
61 # endif
62 # ifndef __BRIDGEOS_DEPRECATED
63 # define __BRIDGEOS_DEPRECATED(_start, _dep, _msg) __BRIDGEOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(bridgeos,deprecated=_dep,_msg)
64 # endif
65 # ifndef __BRIDGEOS_UNAVAILABLE
66 # define __BRIDGEOS_UNAVAILABLE __OS_AVAILABILITY(bridgeos,unavailable)
67 # endif
68 # else
69 # ifndef __BRIDGEOS_AVAILABLE
70 # define __BRIDGEOS_AVAILABLE(_vers)
71 # endif
72 # ifndef __BRIDGEOS_DEPRECATED
73 # define __BRIDGEOS_DEPRECATED(_start, _dep, _msg)
74 # endif
75 # ifndef __BRIDGEOS_UNAVAILABLE
76 # define __BRIDGEOS_UNAVAILABLE
77 # endif
78 # endif
79 #endif
80
81 /*
82 * OBJC_API_VERSION 0 or undef: Tiger and earlier API only
83 * OBJC_API_VERSION 2: Leopard and later API available
84 */
85 #if !defined(OBJC_API_VERSION)
86 # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5
87 # define OBJC_API_VERSION 0
88 # else
89 # define OBJC_API_VERSION 2
90 # endif
91 #endif
92
93
94 /*
95 * OBJC_NO_GC 1: GC is not supported
96 * OBJC_NO_GC undef: GC is supported. This SDK no longer supports this mode.
97 *
98 * OBJC_NO_GC_API undef: Libraries must export any symbols that
99 * dual-mode code may links to.
100 * OBJC_NO_GC_API 1: Libraries need not export GC-related symbols.
101 */
102 #if defined(__OBJC_GC__)
103 # error Objective-C garbage collection is not supported.
104 #elif TARGET_OS_OSX
105 /* GC is unsupported. GC API symbols are exported. */
106 # define OBJC_NO_GC 1
107 # undef OBJC_NO_GC_API
108 #else
109 /* GC is unsupported. GC API symbols are not exported. */
110 # define OBJC_NO_GC 1
111 # define OBJC_NO_GC_API 1
112 #endif
113
114
115 /* NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER == 1
116 * marks -[NSObject init] as a designated initializer. */
117 #if !defined(NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER)
118 # define NS_ENFORCE_NSOBJECT_DESIGNATED_INITIALIZER 1
119 #endif
120
121
122 /* OBJC_OLD_DISPATCH_PROTOTYPES == 0 enforces the rule that the dispatch
123 * functions must be cast to an appropriate function pointer type. */
124 #if !defined(OBJC_OLD_DISPATCH_PROTOTYPES)
125 # if __swift__
126 // Existing Swift code expects IMP to be Comparable.
127 // Variadic IMP is comparable via OpaquePointer; non-variadic IMP isn't.
128 # define OBJC_OLD_DISPATCH_PROTOTYPES 1
129 # else
130 # define OBJC_OLD_DISPATCH_PROTOTYPES 1
131 # endif
132 #endif
133
134
135 /* OBJC_AVAILABLE: shorthand for all-OS availability */
136 #if !defined(OBJC_AVAILABLE)
137 # define OBJC_AVAILABLE(x, i, t, w, b) \
138 __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
139 __WATCHOS_AVAILABLE(w) __BRIDGEOS_AVAILABLE(b)
140 #endif
141
142
143 /* OBJC_ISA_AVAILABILITY: `isa` will be deprecated or unavailable
144 * in the future */
145 #if !defined(OBJC_ISA_AVAILABILITY)
146 # if __OBJC2__
147 # define OBJC_ISA_AVAILABILITY __attribute__((deprecated))
148 # else
149 # define OBJC_ISA_AVAILABILITY /* still available */
150 # endif
151 #endif
152
153
154 /* OBJC2_UNAVAILABLE: unavailable in objc 2.0, deprecated in Leopard */
155 #if !defined(OBJC2_UNAVAILABLE)
156 # if __OBJC2__
157 # define OBJC2_UNAVAILABLE UNAVAILABLE_ATTRIBUTE
158 # else
159 /* plain C code also falls here, but this is close enough */
160 # define OBJC2_UNAVAILABLE \
161 __OSX_DEPRECATED(10.5, 10.5, "not available in __OBJC2__") \
162 __IOS_DEPRECATED(2.0, 2.0, "not available in __OBJC2__") \
163 __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
164 # endif
165 #endif
166
167 /* OBJC_UNAVAILABLE: unavailable, with a message where supported */
168 #if !defined(OBJC_UNAVAILABLE)
169 # if __has_extension(attribute_unavailable_with_message)
170 # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable(_msg)))
171 # else
172 # define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable))
173 # endif
174 #endif
175
176 /* OBJC_DEPRECATED: deprecated, with a message where supported */
177 #if !defined(OBJC_DEPRECATED)
178 # if __has_extension(attribute_deprecated_with_message)
179 # define OBJC_DEPRECATED(_msg) __attribute__((deprecated(_msg)))
180 # else
181 # define OBJC_DEPRECATED(_msg) __attribute__((deprecated))
182 # endif
183 #endif
184
185 /* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */
186 #if !defined(OBJC_ARC_UNAVAILABLE)
187 # if __has_feature(objc_arc)
188 # define OBJC_ARC_UNAVAILABLE OBJC_UNAVAILABLE("not available in automatic reference counting mode")
189 # else
190 # define OBJC_ARC_UNAVAILABLE
191 # endif
192 #endif
193
194 /* OBJC_SWIFT_UNAVAILABLE: unavailable in Swift */
195 #if !defined(OBJC_SWIFT_UNAVAILABLE)
196 # if __has_feature(attribute_availability_swift)
197 # define OBJC_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg)))
198 # else
199 # define OBJC_SWIFT_UNAVAILABLE(_msg)
200 # endif
201 #endif
202
203 /* OBJC_ARM64_UNAVAILABLE: unavailable on arm64 (i.e. stret dispatch) */
204 #if !defined(OBJC_ARM64_UNAVAILABLE)
205 # if defined(__arm64__)
206 # define OBJC_ARM64_UNAVAILABLE OBJC_UNAVAILABLE("not available in arm64")
207 # else
208 # define OBJC_ARM64_UNAVAILABLE
209 # endif
210 #endif
211
212 /* OBJC_GC_UNAVAILABLE: unavailable with -fobjc-gc or -fobjc-gc-only */
213 #if !defined(OBJC_GC_UNAVAILABLE)
214 # define OBJC_GC_UNAVAILABLE
215 #endif
216
217 #if !defined(OBJC_EXTERN)
218 # if defined(__cplusplus)
219 # define OBJC_EXTERN extern "C"
220 # else
221 # define OBJC_EXTERN extern
222 # endif
223 #endif
224
225 #if !defined(OBJC_VISIBLE)
226 # if TARGET_OS_WIN32
227 # if defined(BUILDING_OBJC)
228 # define OBJC_VISIBLE __declspec(dllexport)
229 # else
230 # define OBJC_VISIBLE __declspec(dllimport)
231 # endif
232 # else
233 # define OBJC_VISIBLE __attribute__((visibility("default")))
234 # endif
235 #endif
236
237 #if !defined(OBJC_EXPORT)
238 # define OBJC_EXPORT OBJC_EXTERN OBJC_VISIBLE
239 #endif
240
241 #if !defined(OBJC_IMPORT)
242 # define OBJC_IMPORT extern
243 #endif
244
245 #if !defined(OBJC_ROOT_CLASS)
246 # if __has_attribute(objc_root_class)
247 # define OBJC_ROOT_CLASS __attribute__((objc_root_class))
248 # else
249 # define OBJC_ROOT_CLASS
250 # endif
251 #endif
252
253 #ifndef __DARWIN_NULL
254 #define __DARWIN_NULL NULL
255 #endif
256
257 #if !defined(OBJC_INLINE)
258 # define OBJC_INLINE __inline
259 #endif
260
261 // Declares an enum type or option bits type as appropriate for each language.
262 #if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
263 #define OBJC_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
264 #if (__cplusplus)
265 #define OBJC_OPTIONS(_type, _name) _type _name; enum : _type
266 #else
267 #define OBJC_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
268 #endif
269 #else
270 #define OBJC_ENUM(_type, _name) _type _name; enum
271 #define OBJC_OPTIONS(_type, _name) _type _name; enum
272 #endif
273
274 #if !defined(OBJC_RETURNS_RETAINED)
275 # if __OBJC__ && __has_attribute(ns_returns_retained)
276 # define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained))
277 # else
278 # define OBJC_RETURNS_RETAINED
279 # endif
280 #endif
281
282 #endif