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