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@
24 #ifndef _OBJC_MESSAGE_H
25 #define _OBJC_MESSAGE_H
27 #pragma GCC system_header
29 #include <objc/objc.h>
30 #include <objc/runtime.h>
32 #pragma GCC system_header
37 /// Specifies the superclass of an instance.
39 /// Specifies an instance of a class.
40 __unsafe_unretained id receiver
;
42 /// Specifies the particular superclass of the instance to message.
43 #if !defined(__cplusplus) && !__OBJC2__
44 /* For compatibility with old objc-runtime.h header */
45 __unsafe_unretained Class
class;
47 __unsafe_unretained Class super_class
;
49 /* super_class is the first class to search */
54 /* Basic Messaging Primitives
56 * On some architectures, use objc_msgSend_stret for some struct return types.
57 * On some architectures, use objc_msgSend_fpret for some float return types.
58 * On some architectures, use objc_msgSend_fp2ret for some float return types.
60 * These functions must be cast to an appropriate function pointer type
61 * before being called.
63 #if !OBJC_OLD_DISPATCH_PROTOTYPES
64 OBJC_EXPORT
void objc_msgSend(void /* id self, SEL op, ... */ )
65 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
66 OBJC_EXPORT
void objc_msgSendSuper(void /* struct objc_super *super, SEL op, ... */ )
67 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
70 * Sends a message with a simple return value to an instance of a class.
72 * @param self A pointer to the instance of the class that is to receive the message.
73 * @param op The selector of the method that handles the message.
75 * A variable argument list containing the arguments to the method.
77 * @return The return value of the method.
79 * @note When it encounters a method call, the compiler generates a call to one of the
80 * functions \c objc_msgSend, \c objc_msgSend_stret, \c objc_msgSendSuper, or \c objc_msgSendSuper_stret.
81 * Messages sent to an object’s superclass (using the \c super keyword) are sent using \c objc_msgSendSuper;
82 * other messages are sent using \c objc_msgSend. Methods that have data structures as return values
83 * are sent using \c objc_msgSendSuper_stret and \c objc_msgSend_stret.
85 OBJC_EXPORT id
objc_msgSend(id self
, SEL op
, ...)
86 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
88 * Sends a message with a simple return value to the superclass of an instance of a class.
90 * @param super A pointer to an \c objc_super data structure. Pass values identifying the
91 * context the message was sent to, including the instance of the class that is to receive the
92 * message and the superclass at which to start searching for the method implementation.
93 * @param op A pointer of type SEL. Pass the selector of the method that will handle the message.
95 * A variable argument list containing the arguments to the method.
97 * @return The return value of the method identified by \e op.
101 OBJC_EXPORT id
objc_msgSendSuper(struct objc_super
*super
, SEL op
, ...)
102 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
106 /* Struct-returning Messaging Primitives
108 * Use these functions to call methods that return structs on the stack.
109 * On some architectures, some structures are returned in registers.
110 * Consult your local function call ABI documentation for details.
112 * These functions must be cast to an appropriate function pointer type
113 * before being called.
115 #if !OBJC_OLD_DISPATCH_PROTOTYPES
116 OBJC_EXPORT
void objc_msgSend_stret(void /* id self, SEL op, ... */ )
117 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0)
118 OBJC_ARM64_UNAVAILABLE
;
119 OBJC_EXPORT
void objc_msgSendSuper_stret(void /* struct objc_super *super, SEL op, ... */ )
120 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0)
121 OBJC_ARM64_UNAVAILABLE
;
124 * Sends a message with a data-structure return value to an instance of a class.
128 OBJC_EXPORT
void objc_msgSend_stret(id self
, SEL op
, ...)
129 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0)
130 OBJC_ARM64_UNAVAILABLE
;
133 * Sends a message with a data-structure return value to the superclass of an instance of a class.
135 * @see objc_msgSendSuper
137 OBJC_EXPORT
void objc_msgSendSuper_stret(struct objc_super
*super
, SEL op
, ...)
138 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0)
139 OBJC_ARM64_UNAVAILABLE
;
143 /* Floating-point-returning Messaging Primitives
145 * Use these functions to call methods that return floating-point values
147 * Consult your local function call ABI documentation for details.
149 * arm: objc_msgSend_fpret not used
150 * i386: objc_msgSend_fpret used for `float`, `double`, `long double`.
151 * x86-64: objc_msgSend_fpret used for `long double`.
153 * arm: objc_msgSend_fp2ret not used
154 * i386: objc_msgSend_fp2ret not used
155 * x86-64: objc_msgSend_fp2ret used for `_Complex long double`.
157 * These functions must be cast to an appropriate function pointer type
158 * before being called.
160 #if !OBJC_OLD_DISPATCH_PROTOTYPES
162 # if defined(__i386__)
164 OBJC_EXPORT
void objc_msgSend_fpret(void /* id self, SEL op, ... */ )
165 OBJC_AVAILABLE(10.4, 2.0, 9.0, 1.0);
167 # elif defined(__x86_64__)
169 OBJC_EXPORT
void objc_msgSend_fpret(void /* id self, SEL op, ... */ )
170 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
171 OBJC_EXPORT
void objc_msgSend_fp2ret(void /* id self, SEL op, ... */ )
172 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
176 // !OBJC_OLD_DISPATCH_PROTOTYPES
178 // OBJC_OLD_DISPATCH_PROTOTYPES
179 # if defined(__i386__)
182 * Sends a message with a floating-point return value to an instance of a class.
185 * @note On the i386 platform, the ABI for functions returning a floating-point value is
186 * incompatible with that for functions returning an integral type. On the i386 platform, therefore,
187 * you must use \c objc_msgSend_fpret for functions returning non-integral type. For \c float or
188 * \c long \c double return types, cast the function to an appropriate function pointer type first.
190 OBJC_EXPORT
double objc_msgSend_fpret(id self
, SEL op
, ...)
191 OBJC_AVAILABLE(10.4, 2.0, 9.0, 1.0);
193 /* Use objc_msgSendSuper() for fp-returning messages to super. */
194 /* See also objc_msgSendv_fpret() below. */
196 # elif defined(__x86_64__)
198 * Sends a message with a floating-point return value to an instance of a class.
202 OBJC_EXPORT
long double objc_msgSend_fpret(id self
, SEL op
, ...)
203 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
205 # if __STDC_VERSION__ >= 199901L
206 OBJC_EXPORT _Complex
long double objc_msgSend_fp2ret(id self
, SEL op
, ...)
207 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
209 OBJC_EXPORT
void objc_msgSend_fp2ret(id self
, SEL op
, ...)
210 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
213 /* Use objc_msgSendSuper() for fp-returning messages to super. */
214 /* See also objc_msgSendv_fpret() below. */
218 // OBJC_OLD_DISPATCH_PROTOTYPES
222 /* Direct Method Invocation Primitives
223 * Use these functions to call the implementation of a given Method.
224 * This is faster than calling method_getImplementation() and method_getName().
226 * The receiver must not be nil.
228 * These functions must be cast to an appropriate function pointer type
229 * before being called.
231 #if !OBJC_OLD_DISPATCH_PROTOTYPES
232 OBJC_EXPORT
void method_invoke(void /* id receiver, Method m, ... */ )
233 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
234 OBJC_EXPORT
void method_invoke_stret(void /* id receiver, Method m, ... */ )
235 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0)
236 OBJC_ARM64_UNAVAILABLE
;
238 OBJC_EXPORT id
method_invoke(id receiver
, Method m
, ...)
239 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
240 OBJC_EXPORT
void method_invoke_stret(id receiver
, Method m
, ...)
241 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0)
242 OBJC_ARM64_UNAVAILABLE
;
246 /* Message Forwarding Primitives
247 * Use these functions to forward a message as if the receiver did not
250 * The receiver must not be nil.
252 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
253 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
255 * These functions must be cast to an appropriate function pointer type
256 * before being called.
258 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
259 * but may be compared to other IMP values.
261 #if !OBJC_OLD_DISPATCH_PROTOTYPES
262 OBJC_EXPORT
void _objc_msgForward(void /* id receiver, SEL sel, ... */ )
263 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
264 OBJC_EXPORT
void _objc_msgForward_stret(void /* id receiver, SEL sel, ... */ )
265 OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0)
266 OBJC_ARM64_UNAVAILABLE
;
268 OBJC_EXPORT id
_objc_msgForward(id receiver
, SEL sel
, ...)
269 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
270 OBJC_EXPORT
void _objc_msgForward_stret(id receiver
, SEL sel
, ...)
271 OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0)
272 OBJC_ARM64_UNAVAILABLE
;
276 /* Variable-argument Messaging Primitives
278 * Use these functions to call methods with a list of arguments, such
279 * as the one passed to forward:: .
281 * The contents of the argument list are architecture-specific.
282 * Consult your local function call ABI documentation for details.
284 * These functions must be cast to an appropriate function pointer type
285 * before being called, except for objc_msgSendv_stret() which must not
286 * be cast to a struct-returning type.
289 typedef void* marg_list
;
291 OBJC_EXPORT id
objc_msgSendv(id self
, SEL op
, size_t arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
292 OBJC_EXPORT
void objc_msgSendv_stret(void *stretAddr
, id self
, SEL op
, size_t arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
293 /* Note that objc_msgSendv_stret() does not return a structure type,
294 * and should not be cast to do so. This is unlike objc_msgSend_stret()
295 * and objc_msgSendSuper_stret().
297 #if defined(__i386__)
298 OBJC_EXPORT
double objc_msgSendv_fpret(id self
, SEL op
, unsigned arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
302 /* The following marg_list macros are of marginal utility. They
303 * are included for compatibility with the old objc-class.h header. */
307 #define marg_prearg_size 0
309 #define marg_malloc(margs, method) \
311 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
314 #define marg_free(margs) \
319 #define marg_adjustedOffset(method, offset) \
320 (marg_prearg_size + offset)
322 #define marg_getRef(margs, offset, type) \
323 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
325 #define marg_getValue(margs, offset, type) \
326 ( *marg_getRef(margs, offset, type) )
328 #define marg_setValue(margs, offset, type, value) \
329 ( marg_getValue(margs, offset, type) = (value) )