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>
36 __unsafe_unretained id receiver
;
37 #if !defined(__cplusplus) && !__OBJC2__
38 __unsafe_unretained Class
class; /* For compatibility with old objc-runtime.h header */
40 __unsafe_unretained Class super_class
;
42 /* super_class is the first class to search */
47 /* Basic Messaging Primitives
49 * On some architectures, use objc_msgSend_stret for some struct return types.
50 * On some architectures, use objc_msgSend_fpret for some float return types.
51 * On some architectures, use objc_msgSend_fp2ret for some float return types.
53 * These functions must be cast to an appropriate function pointer type
54 * before being called.
56 #if !OBJC_OLD_DISPATCH_PROTOTYPES
57 OBJC_EXPORT
void objc_msgSend(void /* id self, SEL op, ... */ )
58 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
59 OBJC_EXPORT
void objc_msgSendSuper(void /* struct objc_super *super, SEL op, ... */ )
60 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
62 OBJC_EXPORT id
objc_msgSend(id self
, SEL op
, ...)
63 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
64 OBJC_EXPORT id
objc_msgSendSuper(struct objc_super
*super
, SEL op
, ...)
65 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
69 /* Struct-returning Messaging Primitives
71 * Use these functions to call methods that return structs on the stack.
72 * On some architectures, some structures are returned in registers.
73 * Consult your local function call ABI documentation for details.
75 * These functions must be cast to an appropriate function pointer type
76 * before being called.
78 #if !OBJC_OLD_DISPATCH_PROTOTYPES
79 OBJC_EXPORT
void objc_msgSend_stret(void /* id self, SEL op, ... */ )
80 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
81 OBJC_EXPORT
void objc_msgSendSuper_stret(void /* struct objc_super *super, SEL op, ... */ )
82 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
84 OBJC_EXPORT
void objc_msgSend_stret(id self
, SEL op
, ...)
85 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
86 OBJC_EXPORT
void objc_msgSendSuper_stret(struct objc_super
*super
, SEL op
, ...)
87 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
91 /* Floating-point-returning Messaging Primitives
93 * Use these functions to call methods that return floating-point values
95 * Consult your local function call ABI documentation for details.
97 * arm: objc_msgSend_fpret not used
98 * i386: objc_msgSend_fpret used for `float`, `double`, `long double`.
99 * x86-64: objc_msgSend_fpret used for `long double`.
101 * arm: objc_msgSend_fp2ret not used
102 * i386: objc_msgSend_fp2ret not used
103 * x86-64: objc_msgSend_fp2ret used for `_Complex long double`.
105 * These functions must be cast to an appropriate function pointer type
106 * before being called.
108 #if !OBJC_OLD_DISPATCH_PROTOTYPES
110 # if defined(__i386__)
112 OBJC_EXPORT
void objc_msgSend_fpret(void /* id self, SEL op, ... */ )
113 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
115 # elif defined(__x86_64__)
117 OBJC_EXPORT
void objc_msgSend_fpret(void /* id self, SEL op, ... */ )
118 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
119 OBJC_EXPORT
void objc_msgSend_fp2ret(void /* id self, SEL op, ... */ )
120 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
124 // !OBJC_OLD_DISPATCH_PROTOTYPES
126 // OBJC_OLD_DISPATCH_PROTOTYPES
127 # if defined(__i386__)
129 OBJC_EXPORT
double objc_msgSend_fpret(id self
, SEL op
, ...)
130 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
132 /* Use objc_msgSendSuper() for fp-returning messages to super. */
133 /* See also objc_msgSendv_fpret() below. */
135 # elif defined(__x86_64__)
137 OBJC_EXPORT
long double objc_msgSend_fpret(id self
, SEL op
, ...)
138 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
140 # if __STDC_VERSION__ >= 199901L
141 OBJC_EXPORT _Complex
long double objc_msgSend_fp2ret(id self
, SEL op
, ...)
142 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
144 OBJC_EXPORT
void objc_msgSend_fp2ret(id self
, SEL op
, ...)
145 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
148 /* Use objc_msgSendSuper() for fp-returning messages to super. */
149 /* See also objc_msgSendv_fpret() below. */
153 // OBJC_OLD_DISPATCH_PROTOTYPES
157 /* Direct Method Invocation Primitives
158 * Use these functions to call the implementation of a given Method.
159 * This is faster than calling method_getImplementation() and method_getName().
161 * The receiver must not be nil.
163 * These functions must be cast to an appropriate function pointer type
164 * before being called.
166 #if !OBJC_OLD_DISPATCH_PROTOTYPES
167 OBJC_EXPORT
void method_invoke(void /* id receiver, Method m, ... */ )
168 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
169 OBJC_EXPORT
void method_invoke_stret(void /* id receiver, Method m, ... */ )
170 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
172 OBJC_EXPORT id
method_invoke(id receiver
, Method m
, ...)
173 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
174 OBJC_EXPORT
void method_invoke_stret(id receiver
, Method m
, ...)
175 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
179 /* Message Forwarding Primitives
180 * Use these functions to forward a message as if the receiver did not
183 * The receiver must not be nil.
185 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
186 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
188 * These functions must be cast to an appropriate function pointer type
189 * before being called.
191 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
192 * but may be compared to other IMP values.
194 #if !OBJC_OLD_DISPATCH_PROTOTYPES
195 OBJC_EXPORT
void _objc_msgForward(void /* id receiver, SEL sel, ... */ )
196 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
197 OBJC_EXPORT
void _objc_msgForward_stret(void /* id receiver, SEL sel, ... */ )
198 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_0
);
200 OBJC_EXPORT id
_objc_msgForward(id receiver
, SEL sel
, ...)
201 __OSX_AVAILABLE_STARTING(__MAC_10_0
, __IPHONE_2_0
);
202 OBJC_EXPORT
void _objc_msgForward_stret(id receiver
, SEL sel
, ...)
203 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_3_0
);
207 /* Variable-argument Messaging Primitives
209 * Use these functions to call methods with a list of arguments, such
210 * as the one passed to forward:: .
212 * The contents of the argument list are architecture-specific.
213 * Consult your local function call ABI documentation for details.
215 * These functions must be cast to an appropriate function pointer type
216 * before being called, except for objc_msgSendv_stret() which must not
217 * be cast to a struct-returning type.
220 typedef void* marg_list
;
222 OBJC_EXPORT id
objc_msgSendv(id self
, SEL op
, size_t arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
223 OBJC_EXPORT
void objc_msgSendv_stret(void *stretAddr
, id self
, SEL op
, size_t arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
224 /* Note that objc_msgSendv_stret() does not return a structure type,
225 * and should not be cast to do so. This is unlike objc_msgSend_stret()
226 * and objc_msgSendSuper_stret().
228 #if defined(__i386__)
229 OBJC_EXPORT
double objc_msgSendv_fpret(id self
, SEL op
, unsigned arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
233 /* The following marg_list macros are of marginal utility. They
234 * are included for compatibility with the old objc-class.h header. */
238 #define marg_prearg_size 0
240 #define marg_malloc(margs, method) \
242 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
245 #define marg_free(margs) \
250 #define marg_adjustedOffset(method, offset) \
251 (marg_prearg_size + offset)
253 #define marg_getRef(margs, offset, type) \
254 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
256 #define marg_getValue(margs, offset, type) \
257 ( *marg_getRef(margs, offset, type) )
259 #define marg_setValue(margs, offset, type, value) \
260 ( marg_getValue(margs, offset, type) = (value) )