]>
Commit | Line | Data |
---|---|---|
13d88034 | 1 | /* |
b3962a83 | 2 | * Copyright (c) 1999-2007 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 | /* | |
24 | * objc.h | |
25 | * Copyright 1988-1996, NeXT Software, Inc. | |
26 | */ | |
27 | ||
28 | #ifndef _OBJC_OBJC_H_ | |
29 | #define _OBJC_OBJC_H_ | |
30 | ||
7af964d1 | 31 | #include <sys/types.h> // for __DARWIN_NULL |
8972963c | 32 | #include <Availability.h> |
7af964d1 | 33 | #include <objc/objc-api.h> |
8070259c | 34 | #include <stdbool.h> |
13d88034 | 35 | |
7257e56c A |
36 | #if !OBJC_TYPES_DEFINED |
37 | /// An opaque type that represents an Objective-C class. | |
b3962a83 | 38 | typedef struct objc_class *Class; |
13d88034 | 39 | |
7257e56c A |
40 | /// Represents an instance of a class. |
41 | struct objc_object { | |
4a109af3 | 42 | Class _Nonnull isa OBJC_ISA_AVAILABILITY; |
7257e56c A |
43 | }; |
44 | ||
45 | /// A pointer to an instance of a class. | |
46 | typedef struct objc_object *id; | |
47 | #endif | |
b3962a83 | 48 | |
7257e56c A |
49 | /// An opaque type that represents a method selector. |
50 | typedef struct objc_selector *SEL; | |
cd5f04f5 | 51 | |
7257e56c | 52 | /// A pointer to the function of a method implementation. |
cd5f04f5 A |
53 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
54 | typedef void (*IMP)(void /* id, SEL, ... */ ); | |
55 | #else | |
4a109af3 | 56 | typedef id _Nullable (*IMP)(id _Nonnull, SEL _Nonnull, ...); |
cd5f04f5 A |
57 | #endif |
58 | ||
7257e56c | 59 | /// Type to represent a boolean value. |
bd8dfcfc A |
60 | |
61 | #if defined(__OBJC_BOOL_IS_BOOL) | |
62 | // Honor __OBJC_BOOL_IS_BOOL when available. | |
63 | # if __OBJC_BOOL_IS_BOOL | |
64 | # define OBJC_BOOL_IS_BOOL 1 | |
65 | # else | |
66 | # define OBJC_BOOL_IS_BOOL 0 | |
67 | # endif | |
8070259c | 68 | #else |
bd8dfcfc | 69 | // __OBJC_BOOL_IS_BOOL not set. |
34d5b5e8 | 70 | # if TARGET_OS_OSX || TARGET_OS_MACCATALYST || ((TARGET_OS_IOS || TARGET_OS_BRIDGE) && !__LP64__ && !__ARM_ARCH_7K) |
bd8dfcfc A |
71 | # define OBJC_BOOL_IS_BOOL 0 |
72 | # else | |
73 | # define OBJC_BOOL_IS_BOOL 1 | |
74 | # endif | |
8070259c | 75 | #endif |
390d5862 | 76 | |
bd8dfcfc A |
77 | #if OBJC_BOOL_IS_BOOL |
78 | typedef bool BOOL; | |
79 | #else | |
80 | # define OBJC_BOOL_IS_CHAR 1 | |
81 | typedef signed char BOOL; | |
82 | // BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C" | |
83 | // even if -funsigned-char is used. | |
84 | #endif | |
85 | ||
86 | #define OBJC_BOOL_DEFINED | |
87 | ||
cd5f04f5 | 88 | #if __has_feature(objc_bool) |
8070259c A |
89 | #define YES __objc_yes |
90 | #define NO __objc_no | |
cd5f04f5 | 91 | #else |
8070259c A |
92 | #define YES ((BOOL)1) |
93 | #define NO ((BOOL)0) | |
cd5f04f5 | 94 | #endif |
13d88034 A |
95 | |
96 | #ifndef Nil | |
cd5f04f5 A |
97 | # if __has_feature(cxx_nullptr) |
98 | # define Nil nullptr | |
99 | # else | |
100 | # define Nil __DARWIN_NULL | |
101 | # endif | |
13d88034 A |
102 | #endif |
103 | ||
104 | #ifndef nil | |
cd5f04f5 A |
105 | # if __has_feature(cxx_nullptr) |
106 | # define nil nullptr | |
107 | # else | |
108 | # define nil __DARWIN_NULL | |
109 | # endif | |
13d88034 A |
110 | #endif |
111 | ||
c1e772c4 A |
112 | #ifndef __strong |
113 | # if !__has_feature(objc_arc) | |
114 | # define __strong /* empty */ | |
115 | # endif | |
2bfd4448 | 116 | #endif |
13d88034 | 117 | |
c1e772c4 A |
118 | #ifndef __unsafe_unretained |
119 | # if !__has_feature(objc_arc) | |
120 | # define __unsafe_unretained /* empty */ | |
121 | # endif | |
122 | #endif | |
123 | ||
124 | #ifndef __autoreleasing | |
125 | # if !__has_feature(objc_arc) | |
126 | # define __autoreleasing /* empty */ | |
127 | # endif | |
8972963c A |
128 | #endif |
129 | ||
cd5f04f5 | 130 | |
7257e56c A |
131 | /** |
132 | * Returns the name of the method specified by a given selector. | |
133 | * | |
134 | * @param sel A pointer of type \c SEL. Pass the selector whose name you wish to determine. | |
135 | * | |
136 | * @return A C string indicating the name of the selector. | |
137 | */ | |
4a109af3 A |
138 | OBJC_EXPORT const char * _Nonnull sel_getName(SEL _Nonnull sel) |
139 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); | |
7257e56c A |
140 | |
141 | /** | |
142 | * Registers a method with the Objective-C runtime system, maps the method | |
143 | * name to a selector, and returns the selector value. | |
144 | * | |
145 | * @param str A pointer to a C string. Pass the name of the method you wish to register. | |
146 | * | |
147 | * @return A pointer of type SEL specifying the selector for the named method. | |
148 | * | |
149 | * @note You must register a method name with the Objective-C runtime system to obtain the | |
150 | * method’s selector before you can add the method to a class definition. If the method name | |
151 | * has already been registered, this function simply returns the selector. | |
152 | */ | |
4a109af3 A |
153 | OBJC_EXPORT SEL _Nonnull sel_registerName(const char * _Nonnull str) |
154 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); | |
7257e56c A |
155 | |
156 | /** | |
157 | * Returns the class name of a given object. | |
158 | * | |
159 | * @param obj An Objective-C object. | |
160 | * | |
161 | * @return The name of the class of which \e obj is an instance. | |
162 | */ | |
4a109af3 A |
163 | OBJC_EXPORT const char * _Nonnull object_getClassName(id _Nullable obj) |
164 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); | |
7257e56c A |
165 | |
166 | /** | |
167 | * Returns a pointer to any extra bytes allocated with an instance given object. | |
168 | * | |
169 | * @param obj An Objective-C object. | |
170 | * | |
171 | * @return A pointer to any extra bytes allocated with \e obj. If \e obj was | |
172 | * not allocated with any extra bytes, then dereferencing the returned pointer is undefined. | |
173 | * | |
174 | * @note This function returns a pointer to any extra bytes allocated with the instance | |
175 | * (as specified by \c class_createInstance with extraBytes>0). This memory follows the | |
176 | * object's ordinary ivars, but may not be adjacent to the last ivar. | |
177 | * @note The returned pointer is guaranteed to be pointer-size aligned, even if the area following | |
178 | * the object's last ivar is less aligned than that. Alignment greater than pointer-size is never | |
179 | * guaranteed, even if the area following the object's last ivar is more aligned than that. | |
180 | * @note In a garbage-collected environment, the memory is scanned conservatively. | |
181 | */ | |
4a109af3 | 182 | OBJC_EXPORT void * _Nullable object_getIndexedIvars(id _Nullable obj) |
bc4fafce | 183 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
7257e56c A |
184 | |
185 | /** | |
186 | * Identifies a selector as being valid or invalid. | |
187 | * | |
188 | * @param sel The selector you want to identify. | |
189 | * | |
190 | * @return YES if selector is valid and has a function implementation, NO otherwise. | |
191 | * | |
192 | * @warning On some platforms, an invalid reference (to invalid memory addresses) can cause | |
193 | * a crash. | |
194 | */ | |
4a109af3 A |
195 | OBJC_EXPORT BOOL sel_isMapped(SEL _Nonnull sel) |
196 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); | |
7257e56c A |
197 | |
198 | /** | |
199 | * Registers a method name with the Objective-C runtime system. | |
200 | * | |
201 | * @param str A pointer to a C string. Pass the name of the method you wish to register. | |
202 | * | |
203 | * @return A pointer of type SEL specifying the selector for the named method. | |
204 | * | |
205 | * @note The implementation of this method is identical to the implementation of \c sel_registerName. | |
206 | * @note Prior to OS X version 10.0, this method tried to find the selector mapped to the given name | |
207 | * and returned \c NULL if the selector was not found. This was changed for safety, because it was | |
208 | * observed that many of the callers of this function did not check the return value for \c NULL. | |
209 | */ | |
4a109af3 A |
210 | OBJC_EXPORT SEL _Nonnull sel_getUid(const char * _Nonnull str) |
211 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); | |
8972963c | 212 | |
c1e772c4 | 213 | typedef const void* objc_objectptr_t; |
8972963c | 214 | |
8972963c | 215 | |
c1e772c4 | 216 | // Obsolete ARC conversions. |
8972963c | 217 | |
4a109af3 | 218 | OBJC_EXPORT id _Nullable objc_retainedObject(objc_objectptr_t _Nullable obj) |
66799735 A |
219 | #if !OBJC_DECLARE_SYMBOLS |
220 | OBJC_UNAVAILABLE("use CFBridgingRelease() or a (__bridge_transfer id) cast instead") | |
221 | #endif | |
222 | ; | |
4a109af3 | 223 | OBJC_EXPORT id _Nullable objc_unretainedObject(objc_objectptr_t _Nullable obj) |
66799735 A |
224 | #if !OBJC_DECLARE_SYMBOLS |
225 | OBJC_UNAVAILABLE("use a (__bridge id) cast instead") | |
226 | #endif | |
227 | ; | |
4a109af3 | 228 | OBJC_EXPORT objc_objectptr_t _Nullable objc_unretainedPointer(id _Nullable obj) |
66799735 A |
229 | #if !OBJC_DECLARE_SYMBOLS |
230 | OBJC_UNAVAILABLE("use a __bridge cast instead") | |
231 | #endif | |
232 | ; | |
8972963c | 233 | |
13d88034 | 234 | |
b3962a83 A |
235 | #if !__OBJC2__ |
236 | ||
237 | // The following declarations are provided here for source compatibility. | |
238 | ||
239 | #if defined(__LP64__) | |
13d88034 A |
240 | typedef long arith_t; |
241 | typedef unsigned long uarith_t; | |
390d5862 | 242 | # define ARITH_SHIFT 32 |
13d88034 A |
243 | #else |
244 | typedef int arith_t; | |
245 | typedef unsigned uarith_t; | |
390d5862 | 246 | # define ARITH_SHIFT 16 |
13d88034 A |
247 | #endif |
248 | ||
b3962a83 A |
249 | typedef char *STR; |
250 | ||
251 | #define ISSELECTOR(sel) sel_isMapped(sel) | |
252 | #define SELNAME(sel) sel_getName(sel) | |
253 | #define SELUID(str) sel_getUid(str) | |
254 | #define NAMEOF(obj) object_getClassName(obj) | |
255 | #define IV(obj) object_getIndexedIvars(obj) | |
256 | ||
257 | #endif | |
13d88034 | 258 | |
b3962a83 | 259 | #endif /* _OBJC_OBJC_H_ */ |