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