]> git.saurik.com Git - apple/objc4.git/blob - runtime/message.h
objc4-532.2.tar.gz
[apple/objc4.git] / runtime / message.h
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 #ifndef _OBJC_MESSAGE_H
25 #define _OBJC_MESSAGE_H
26
27 #pragma GCC system_header
28
29 #include <objc/objc.h>
30 #include <objc/runtime.h>
31
32
33 #ifndef OBJC_SUPER
34 #define OBJC_SUPER
35 struct objc_super {
36 __unsafe_unretained id receiver;
37 #if !defined(__cplusplus) && !__OBJC2__
38 __unsafe_unretained Class class; /* For compatibility with old objc-runtime.h header */
39 #else
40 __unsafe_unretained Class super_class;
41 #endif
42 /* super_class is the first class to search */
43 };
44 #endif
45
46
47 /* Basic Messaging Primitives
48 *
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.
52 *
53 * These functions must be cast to an appropriate function pointer type
54 * before being called.
55 */
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);
61 #else
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);
66 #endif
67
68
69 /* Struct-returning Messaging Primitives
70 *
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.
74 *
75 * These functions must be cast to an appropriate function pointer type
76 * before being called.
77 */
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);
83 #else
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);
88 #endif
89
90
91 /* Floating-point-returning Messaging Primitives
92 *
93 * Use these functions to call methods that return floating-point values
94 * on the stack.
95 * Consult your local function call ABI documentation for details.
96 *
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`.
100 *
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`.
104 *
105 * These functions must be cast to an appropriate function pointer type
106 * before being called.
107 */
108 #if !OBJC_OLD_DISPATCH_PROTOTYPES
109
110 # if defined(__i386__)
111
112 OBJC_EXPORT void objc_msgSend_fpret(void /* id self, SEL op, ... */ )
113 __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0);
114
115 # elif defined(__x86_64__)
116
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);
121
122 # endif
123
124 // !OBJC_OLD_DISPATCH_PROTOTYPES
125 #else
126 // OBJC_OLD_DISPATCH_PROTOTYPES
127 # if defined(__i386__)
128
129 OBJC_EXPORT double objc_msgSend_fpret(id self, SEL op, ...)
130 __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0);
131
132 /* Use objc_msgSendSuper() for fp-returning messages to super. */
133 /* See also objc_msgSendv_fpret() below. */
134
135 # elif defined(__x86_64__)
136
137 OBJC_EXPORT long double objc_msgSend_fpret(id self, SEL op, ...)
138 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
139
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);
143 # else
144 OBJC_EXPORT void objc_msgSend_fp2ret(id self, SEL op, ...)
145 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
146 # endif
147
148 /* Use objc_msgSendSuper() for fp-returning messages to super. */
149 /* See also objc_msgSendv_fpret() below. */
150
151 # endif
152
153 // OBJC_OLD_DISPATCH_PROTOTYPES
154 #endif
155
156
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().
160 *
161 * The receiver must not be nil.
162 *
163 * These functions must be cast to an appropriate function pointer type
164 * before being called.
165 */
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);
171 #else
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);
176 #endif
177
178
179 /* Message Forwarding Primitives
180 * Use these functions to forward a message as if the receiver did not
181 * respond to it.
182 *
183 * The receiver must not be nil.
184 *
185 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
186 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
187 *
188 * These functions must be cast to an appropriate function pointer type
189 * before being called.
190 *
191 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
192 * but may be compared to other IMP values.
193 */
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);
199 #else
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);
204 #endif
205
206
207 /* Variable-argument Messaging Primitives
208 *
209 * Use these functions to call methods with a list of arguments, such
210 * as the one passed to forward:: .
211 *
212 * The contents of the argument list are architecture-specific.
213 * Consult your local function call ABI documentation for details.
214 *
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.
218 */
219
220 typedef void* marg_list;
221
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().
227 */
228 #if defined(__i386__)
229 OBJC_EXPORT double objc_msgSendv_fpret(id self, SEL op, unsigned arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
230 #endif
231
232
233 /* The following marg_list macros are of marginal utility. They
234 * are included for compatibility with the old objc-class.h header. */
235
236 #if !__OBJC2__
237
238 #define marg_prearg_size 0
239
240 #define marg_malloc(margs, method) \
241 do { \
242 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
243 } while (0)
244
245 #define marg_free(margs) \
246 do { \
247 free(margs); \
248 } while (0)
249
250 #define marg_adjustedOffset(method, offset) \
251 (marg_prearg_size + offset)
252
253 #define marg_getRef(margs, offset, type) \
254 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
255
256 #define marg_getValue(margs, offset, type) \
257 ( *marg_getRef(margs, offset, type) )
258
259 #define marg_setValue(margs, offset, type, value) \
260 ( marg_getValue(margs, offset, type) = (value) )
261
262 #endif
263
264 #endif