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