2 * Copyright (c) 1999-2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1988-1996, NeXT Software, Inc.
31 #include <sys/types.h> // for __DARWIN_NULL
32 #include <Availability.h>
33 #include <objc/objc-api.h>
36 #if !OBJC_TYPES_DEFINED
37 /// An opaque type that represents an Objective-C class.
38 typedef struct objc_class
*Class
;
40 /// Represents an instance of a class.
42 Class isa OBJC_ISA_AVAILABILITY
;
45 /// A pointer to an instance of a class.
46 typedef struct objc_object
*id
;
49 /// An opaque type that represents a method selector.
50 typedef struct objc_selector
*SEL
;
52 /// A pointer to the function of a method implementation.
53 #if !OBJC_OLD_DISPATCH_PROTOTYPES
54 typedef void (*IMP
)(void /* id, SEL, ... */ );
56 typedef id (*IMP
)(id
, SEL
, ...);
59 #define OBJC_BOOL_DEFINED
61 /// Type to represent a boolean value.
62 #if (TARGET_OS_IPHONE && __LP64__) || TARGET_OS_WATCH
63 #define OBJC_BOOL_IS_BOOL 1
66 #define OBJC_BOOL_IS_CHAR 1
67 typedef signed char BOOL
;
68 // BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
69 // even if -funsigned-char is used.
72 #if __has_feature(objc_bool)
73 #define YES __objc_yes
81 # if __has_feature(cxx_nullptr)
84 # define Nil __DARWIN_NULL
89 # if __has_feature(cxx_nullptr)
92 # define nil __DARWIN_NULL
96 #if ! (defined(__OBJC_GC__) || __has_feature(objc_arc))
97 #define __strong /* empty */
100 #if !__has_feature(objc_arc)
101 #define __unsafe_unretained /* empty */
102 #define __autoreleasing /* empty */
107 * Returns the name of the method specified by a given selector.
109 * @param sel A pointer of type \c SEL. Pass the selector whose name you wish to determine.
111 * @return A C string indicating the name of the selector.
113 OBJC_EXPORT
const char *sel_getName(SEL sel
)
114 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
117 * Registers a method with the Objective-C runtime system, maps the method
118 * name to a selector, and returns the selector value.
120 * @param str A pointer to a C string. Pass the name of the method you wish to register.
122 * @return A pointer of type SEL specifying the selector for the named method.
124 * @note You must register a method name with the Objective-C runtime system to obtain the
125 * method’s selector before you can add the method to a class definition. If the method name
126 * has already been registered, this function simply returns the selector.
128 OBJC_EXPORT SEL
sel_registerName(const char *str
)
129 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
132 * Returns the class name of a given object.
134 * @param obj An Objective-C object.
136 * @return The name of the class of which \e obj is an instance.
138 OBJC_EXPORT
const char *object_getClassName(id obj
)
139 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
142 * Returns a pointer to any extra bytes allocated with an instance given object.
144 * @param obj An Objective-C object.
146 * @return A pointer to any extra bytes allocated with \e obj. If \e obj was
147 * not allocated with any extra bytes, then dereferencing the returned pointer is undefined.
149 * @note This function returns a pointer to any extra bytes allocated with the instance
150 * (as specified by \c class_createInstance with extraBytes>0). This memory follows the
151 * object's ordinary ivars, but may not be adjacent to the last ivar.
152 * @note The returned pointer is guaranteed to be pointer-size aligned, even if the area following
153 * the object's last ivar is less aligned than that. Alignment greater than pointer-size is never
154 * guaranteed, even if the area following the object's last ivar is more aligned than that.
155 * @note In a garbage-collected environment, the memory is scanned conservatively.
157 OBJC_EXPORT
void *object_getIndexedIvars(id obj
)
158 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
161 * Identifies a selector as being valid or invalid.
163 * @param sel The selector you want to identify.
165 * @return YES if selector is valid and has a function implementation, NO otherwise.
167 * @warning On some platforms, an invalid reference (to invalid memory addresses) can cause
170 OBJC_EXPORT BOOL
sel_isMapped(SEL sel
)
171 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
174 * Registers a method name with the Objective-C runtime system.
176 * @param str A pointer to a C string. Pass the name of the method you wish to register.
178 * @return A pointer of type SEL specifying the selector for the named method.
180 * @note The implementation of this method is identical to the implementation of \c sel_registerName.
181 * @note Prior to OS X version 10.0, this method tried to find the selector mapped to the given name
182 * and returned \c NULL if the selector was not found. This was changed for safety, because it was
183 * observed that many of the callers of this function did not check the return value for \c NULL.
185 OBJC_EXPORT SEL
sel_getUid(const char *str
)
186 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
189 // Obsolete ARC conversions. Deprecation forthcoming.
190 // Use CFBridgingRetain, CFBridgingRelease, and __bridge casts instead.
192 typedef const void* objc_objectptr_t
;
194 #if __has_feature(objc_arc)
195 # define objc_retainedObject(o) ((__bridge_transfer id)(objc_objectptr_t)(o))
196 # define objc_unretainedObject(o) ((__bridge id)(objc_objectptr_t)(o))
197 # define objc_unretainedPointer(o) ((__bridge objc_objectptr_t)(id)(o))
199 # define objc_retainedObject(o) ((id)(objc_objectptr_t)(o))
200 # define objc_unretainedObject(o) ((id)(objc_objectptr_t)(o))
201 # define objc_unretainedPointer(o) ((objc_objectptr_t)(id)(o))
207 // The following declarations are provided here for source compatibility.
209 #if defined(__LP64__)
210 typedef long arith_t
;
211 typedef unsigned long uarith_t
;
212 # define ARITH_SHIFT 32
215 typedef unsigned uarith_t
;
216 # define ARITH_SHIFT 16
221 #define ISSELECTOR(sel) sel_isMapped(sel)
222 #define SELNAME(sel) sel_getName(sel)
223 #define SELUID(str) sel_getUid(str)
224 #define NAMEOF(obj) object_getClassName(obj)
225 #define IV(obj) object_getIndexedIvars(obj)
229 #endif /* _OBJC_OBJC_H_ */