]> git.saurik.com Git - apple/objc4.git/blame - runtime/objc-api.h
objc4-818.2.tar.gz
[apple/objc4.git] / runtime / objc-api.h
CommitLineData
13d88034 1/*
b3962a83 2 * Copyright (c) 1999-2006 Apple Inc. All Rights Reserved.
13d88034 3 *
b3962a83 4 * @APPLE_LICENSE_HEADER_START@
390d5862
A
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.
13d88034
A
12 *
13 * The Original Code and all software distributed under the License are
390d5862 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
13d88034
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
390d5862
A
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.
13d88034
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23// Copyright 1988-1996 NeXT Software, Inc.
24
b3962a83
A
25#ifndef _OBJC_OBJC_API_H_
26#define _OBJC_OBJC_API_H_
13d88034 27
cd5f04f5 28#include <Availability.h>
b3962a83 29#include <AvailabilityMacros.h>
7af964d1 30#include <TargetConditionals.h>
4a109af3 31#include <sys/types.h>
b3962a83 32
8972963c
A
33#ifndef __has_feature
34# define __has_feature(x) 0
35#endif
36
cd5f04f5
A
37#ifndef __has_extension
38# define __has_extension __has_feature
39#endif
40
7257e56c
A
41#ifndef __has_attribute
42# define __has_attribute(x) 0
43#endif
44
4a109af3
A
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
66799735
A
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
4a109af3 79#endif
cd5f04f5 80
b3962a83
A
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)
cd5f04f5 86# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_5
b3962a83
A
87# define OBJC_API_VERSION 0
88# else
89# define OBJC_API_VERSION 2
90# endif
13d88034 91#endif
b3962a83 92
cd5f04f5 93
31875a97
A
94/*
95 * OBJC_NO_GC 1: GC is not supported
c1e772c4 96 * OBJC_NO_GC undef: GC is supported. This SDK no longer supports this mode.
31875a97
A
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 */
c1e772c4
A
102#if defined(__OBJC_GC__)
103# error Objective-C garbage collection is not supported.
104#elif TARGET_OS_OSX
31875a97
A
105 /* GC is unsupported. GC API symbols are exported. */
106# define OBJC_NO_GC 1
107# undef OBJC_NO_GC_API
108#else
c1e772c4
A
109 /* GC is unsupported. GC API symbols are not exported. */
110# define OBJC_NO_GC 1
111# define OBJC_NO_GC_API 1
31875a97
A
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
34d5b5e8
A
121/* The arm64 ABI requires proper casting to ensure arguments are passed
122 * * correctly. */
123#if defined(__arm64__) && !__swift__
124# undef OBJC_OLD_DISPATCH_PROTOTYPES
125# define OBJC_OLD_DISPATCH_PROTOTYPES 0
126#endif
31875a97 127
cd5f04f5
A
128/* OBJC_OLD_DISPATCH_PROTOTYPES == 0 enforces the rule that the dispatch
129 * functions must be cast to an appropriate function pointer type. */
130#if !defined(OBJC_OLD_DISPATCH_PROTOTYPES)
66799735
A
131# if __swift__
132 // Existing Swift code expects IMP to be Comparable.
133 // Variadic IMP is comparable via OpaquePointer; non-variadic IMP isn't.
134# define OBJC_OLD_DISPATCH_PROTOTYPES 1
135# else
1807f628 136# define OBJC_OLD_DISPATCH_PROTOTYPES 0
66799735 137# endif
cd5f04f5
A
138#endif
139
140
c1e772c4 141/* OBJC_AVAILABLE: shorthand for all-OS availability */
1807f628
A
142#ifndef __APPLE_BLEACH_SDK__
143# if !defined(OBJC_AVAILABLE)
144# define OBJC_AVAILABLE(x, i, t, w, b) \
145 __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
146 __WATCHOS_AVAILABLE(w) __BRIDGEOS_AVAILABLE(b)
147# endif
148#else
149# if !defined(OBJC_AVAILABLE)
150# define OBJC_AVAILABLE(x, i, t, w, b) \
151 __OSX_AVAILABLE(x) __IOS_AVAILABLE(i) __TVOS_AVAILABLE(t) \
152 __WATCHOS_AVAILABLE(w)
153# endif
154#endif
155
156
157/* OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE: Deprecated on OS X,
158 * unavailable everywhere else. */
159#ifndef __APPLE_BLEACH_SDK__
160# if !defined(OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE)
161# define OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(_start, _dep, _msg) \
162 __OSX_DEPRECATED(_start, _dep, _msg) \
163 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
164 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
165# endif
166#else
167# if !defined(OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE)
168# define OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(_start, _dep, _msg) \
169 __OSX_DEPRECATED(_start, _dep, _msg) \
170 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
171 __WATCHOS_UNAVAILABLE
172# endif
173#endif
174
175
176/* OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE: Available on OS X,
177 * unavailable everywhere else. */
178#ifndef __APPLE_BLEACH_SDK__
179# if !defined(OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE)
180# define OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(vers) \
181 __OSX_AVAILABLE(vers) \
182 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
183 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
184# endif
185#else
186# if !defined(OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE)
187# define OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(vers) \
188 __OSX_AVAILABLE(vers) \
189 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE \
190 __WATCHOS_UNAVAILABLE
191# endif
c1e772c4
A
192#endif
193
194
7257e56c
A
195/* OBJC_ISA_AVAILABILITY: `isa` will be deprecated or unavailable
196 * in the future */
197#if !defined(OBJC_ISA_AVAILABILITY)
8070259c
A
198# if __OBJC2__
199# define OBJC_ISA_AVAILABILITY __attribute__((deprecated))
200# else
201# define OBJC_ISA_AVAILABILITY /* still available */
202# endif
7257e56c
A
203#endif
204
205
b3962a83
A
206/* OBJC2_UNAVAILABLE: unavailable in objc 2.0, deprecated in Leopard */
207#if !defined(OBJC2_UNAVAILABLE)
208# if __OBJC2__
209# define OBJC2_UNAVAILABLE UNAVAILABLE_ATTRIBUTE
210# else
7257e56c 211 /* plain C code also falls here, but this is close enough */
c1e772c4
A
212# define OBJC2_UNAVAILABLE \
213 __OSX_DEPRECATED(10.5, 10.5, "not available in __OBJC2__") \
214 __IOS_DEPRECATED(2.0, 2.0, "not available in __OBJC2__") \
4a109af3 215 __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
c1e772c4
A
216# endif
217#endif
218
219/* OBJC_UNAVAILABLE: unavailable, with a message where supported */
220#if !defined(OBJC_UNAVAILABLE)
221# if __has_extension(attribute_unavailable_with_message)
222# define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable(_msg)))
223# else
224# define OBJC_UNAVAILABLE(_msg) __attribute__((unavailable))
225# endif
226#endif
227
228/* OBJC_DEPRECATED: deprecated, with a message where supported */
229#if !defined(OBJC_DEPRECATED)
230# if __has_extension(attribute_deprecated_with_message)
231# define OBJC_DEPRECATED(_msg) __attribute__((deprecated(_msg)))
232# else
233# define OBJC_DEPRECATED(_msg) __attribute__((deprecated))
b3962a83
A
234# endif
235#endif
236
8972963c
A
237/* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */
238#if !defined(OBJC_ARC_UNAVAILABLE)
7257e56c 239# if __has_feature(objc_arc)
c1e772c4 240# define OBJC_ARC_UNAVAILABLE OBJC_UNAVAILABLE("not available in automatic reference counting mode")
8972963c
A
241# else
242# define OBJC_ARC_UNAVAILABLE
243# endif
244#endif
245
31875a97
A
246/* OBJC_SWIFT_UNAVAILABLE: unavailable in Swift */
247#if !defined(OBJC_SWIFT_UNAVAILABLE)
248# if __has_feature(attribute_availability_swift)
249# define OBJC_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg)))
250# else
251# define OBJC_SWIFT_UNAVAILABLE(_msg)
252# endif
253#endif
254
8070259c
A
255/* OBJC_ARM64_UNAVAILABLE: unavailable on arm64 (i.e. stret dispatch) */
256#if !defined(OBJC_ARM64_UNAVAILABLE)
257# if defined(__arm64__)
c1e772c4 258# define OBJC_ARM64_UNAVAILABLE OBJC_UNAVAILABLE("not available in arm64")
8070259c
A
259# else
260# define OBJC_ARM64_UNAVAILABLE
261# endif
262#endif
8070259c 263
cd5f04f5
A
264/* OBJC_GC_UNAVAILABLE: unavailable with -fobjc-gc or -fobjc-gc-only */
265#if !defined(OBJC_GC_UNAVAILABLE)
c1e772c4 266# define OBJC_GC_UNAVAILABLE
cd5f04f5
A
267#endif
268
7af964d1 269#if !defined(OBJC_EXTERN)
b3962a83 270# if defined(__cplusplus)
7af964d1
A
271# define OBJC_EXTERN extern "C"
272# else
273# define OBJC_EXTERN extern
274# endif
275#endif
276
8972963c 277#if !defined(OBJC_VISIBLE)
7af964d1
A
278# if TARGET_OS_WIN32
279# if defined(BUILDING_OBJC)
8972963c 280# define OBJC_VISIBLE __declspec(dllexport)
7af964d1 281# else
8972963c 282# define OBJC_VISIBLE __declspec(dllimport)
7af964d1 283# endif
b3962a83 284# else
8972963c 285# define OBJC_VISIBLE __attribute__((visibility("default")))
b3962a83 286# endif
1f20c7a7 287#endif
13d88034 288
8972963c
A
289#if !defined(OBJC_EXPORT)
290# define OBJC_EXPORT OBJC_EXTERN OBJC_VISIBLE
291#endif
292
13d88034 293#if !defined(OBJC_IMPORT)
390d5862 294# define OBJC_IMPORT extern
13d88034
A
295#endif
296
7257e56c
A
297#if !defined(OBJC_ROOT_CLASS)
298# if __has_attribute(objc_root_class)
299# define OBJC_ROOT_CLASS __attribute__((objc_root_class))
300# else
301# define OBJC_ROOT_CLASS
302# endif
303#endif
304
7af964d1
A
305#ifndef __DARWIN_NULL
306#define __DARWIN_NULL NULL
307#endif
308
309#if !defined(OBJC_INLINE)
310# define OBJC_INLINE __inline
311#endif
312
31875a97
A
313// Declares an enum type or option bits type as appropriate for each language.
314#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
315#define OBJC_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
316#if (__cplusplus)
317#define OBJC_OPTIONS(_type, _name) _type _name; enum : _type
318#else
319#define OBJC_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
320#endif
321#else
322#define OBJC_ENUM(_type, _name) _type _name; enum
323#define OBJC_OPTIONS(_type, _name) _type _name; enum
324#endif
325
4a109af3
A
326#if !defined(OBJC_RETURNS_RETAINED)
327# if __OBJC__ && __has_attribute(ns_returns_retained)
328# define OBJC_RETURNS_RETAINED __attribute__((ns_returns_retained))
329# else
330# define OBJC_RETURNS_RETAINED
331# endif
332#endif
333
b3962a83 334#endif