]> git.saurik.com Git - apple/objc4.git/blob - runtime/message.h
objc4-493.11.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 #include <objc/objc.h>
28 #include <objc/runtime.h>
29
30
31 #ifndef OBJC_SUPER
32 #define OBJC_SUPER
33 struct objc_super {
34 id receiver;
35 #if !defined(__cplusplus) && !__OBJC2__
36 Class class; /* For compatibility with old objc-runtime.h header */
37 #else
38 Class super_class;
39 #endif
40 /* super_class is the first class to search */
41 };
42 #endif
43
44
45 /* Basic Messaging Primitives
46 *
47 * On some architectures, use objc_msgSend_stret for some struct return types.
48 * On some architectures, use objc_msgSend_fpret for some float return types.
49 * On some architectures, use objc_msgSend_fp2ret for some float return types.
50 *
51 * These functions must be cast to an appropriate function pointer type
52 * before being called.
53 */
54 OBJC_EXPORT id objc_msgSend(id self, SEL op, ...)
55 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
56 OBJC_EXPORT id objc_msgSendSuper(struct objc_super *super, SEL op, ...)
57 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
58
59
60 /* Struct-returning Messaging Primitives
61 *
62 * Use these functions to call methods that return structs on the stack.
63 * On some architectures, some structures are returned in registers.
64 * Consult your local function call ABI documentation for details.
65 *
66 * These functions must be cast to an appropriate function pointer type
67 * before being called.
68 */
69 #if defined(__OBJC2__)
70 OBJC_EXPORT void objc_msgSend_stret(id self, SEL op, ...)
71 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
72 OBJC_EXPORT void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...)
73 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
74 #elif defined(__cplusplus)
75 /* For compatibility with old objc-runtime.h header */
76 OBJC_EXPORT id objc_msgSend_stret(id self, SEL op, ...)
77 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
78 OBJC_EXPORT id objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...)
79 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
80 #else
81 /* For compatibility with old objc-runtime.h header */
82 OBJC_EXPORT void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...)
83 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
84 OBJC_EXPORT void objc_msgSendSuper_stret(void * stretAddr, struct objc_super *super, SEL op, ...)
85 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
86 #endif
87
88
89 /* Floating-point-returning Messaging Primitives
90 *
91 * Use these functions to call methods that return floating-point values
92 * on the stack.
93 * Consult your local function call ABI documentation for details.
94 *
95 * arm: objc_msgSend_fpret not used
96 * i386: objc_msgSend_fpret used for `float`, `double`, `long double`.
97 * x86-64: objc_msgSend_fpret used for `long double`.
98 *
99 * arm: objc_msgSend_fp2ret not used
100 * i386: objc_msgSend_fp2ret not used
101 * x86-64: objc_msgSend_fp2ret used for `_Complex long double`.
102 *
103 * These functions must be cast to an appropriate function pointer type
104 * before being called.
105 */
106 #if defined(__i386__)
107
108 OBJC_EXPORT double objc_msgSend_fpret(id self, SEL op, ...)
109 __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0);
110
111 /* Use objc_msgSendSuper() for fp-returning messages to super. */
112 /* See also objc_msgSendv_fpret() below. */
113
114 #elif defined(__x86_64__)
115
116 OBJC_EXPORT long double objc_msgSend_fpret(id self, SEL op, ...)
117 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
118
119 # if __STDC_VERSION__ >= 199901L
120 OBJC_EXPORT _Complex long double objc_msgSend_fp2ret(id self, SEL op, ...)
121 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
122 # else
123 OBJC_EXPORT void objc_msgSend_fp2ret(id self, SEL op, ...)
124 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
125 # endif
126
127 /* Use objc_msgSendSuper() for fp-returning messages to super. */
128 /* See also objc_msgSendv_fpret() below. */
129
130 #endif
131
132
133 /* Direct Method Invocation Primitives
134 * Use these functions to call the implementation of a given Method.
135 * This is faster than calling method_getImplementation() and method_getName().
136 *
137 * The receiver must not be nil.
138 *
139 * These functions must be cast to an appropriate function pointer type
140 * before being called.
141 */
142 OBJC_EXPORT id method_invoke(id receiver, Method m, ...)
143 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
144 OBJC_EXPORT void method_invoke_stret(id receiver, Method m, ...)
145 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
146
147
148 /* Message Forwarding Primitives
149 * Use these functions to forward a message as if the receiver did not
150 * respond to it.
151 *
152 * The receiver must not be nil.
153 *
154 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
155 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
156 *
157 * These functions must be cast to an appropriate function pointer type
158 * before being called.
159 *
160 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
161 * but may be compared to other IMP values.
162 */
163 OBJC_EXPORT id _objc_msgForward(id receiver, SEL sel, ...)
164 __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
165 OBJC_EXPORT void _objc_msgForward_stret(id receiver, SEL sel, ...)
166 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0);
167
168
169 /* Variable-argument Messaging Primitives
170 *
171 * Use these functions to call methods with a list of arguments, such
172 * as the one passed to forward:: .
173 *
174 * The contents of the argument list are architecture-specific.
175 * Consult your local function call ABI documentation for details.
176 *
177 * These functions must be cast to an appropriate function pointer type
178 * before being called, except for objc_msgSendv_stret() which must not
179 * be cast to a struct-returning type.
180 */
181
182 typedef void* marg_list;
183
184 OBJC_EXPORT id objc_msgSendv(id self, SEL op, size_t arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
185 OBJC_EXPORT void objc_msgSendv_stret(void *stretAddr, id self, SEL op, size_t arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
186 /* Note that objc_msgSendv_stret() does not return a structure type,
187 * and should not be cast to do so. This is unlike objc_msgSend_stret()
188 * and objc_msgSendSuper_stret().
189 */
190 #if defined(__i386__)
191 OBJC_EXPORT double objc_msgSendv_fpret(id self, SEL op, unsigned arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
192 #endif
193
194
195 /* The following marg_list macros are of marginal utility. They
196 * are included for compatibility with the old objc-class.h header. */
197
198 #if !__OBJC2__
199
200 #define marg_prearg_size 0
201
202 #define marg_malloc(margs, method) \
203 do { \
204 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
205 } while (0)
206
207 #define marg_free(margs) \
208 do { \
209 free(margs); \
210 } while (0)
211
212 #define marg_adjustedOffset(method, offset) \
213 (marg_prearg_size + offset)
214
215 #define marg_getRef(margs, offset, type) \
216 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
217
218 #define marg_getValue(margs, offset, type) \
219 ( *marg_getRef(margs, offset, type) )
220
221 #define marg_setValue(margs, offset, type, value) \
222 ( marg_getValue(margs, offset, type) = (value) )
223
224 #endif
225
226 #endif