]> git.saurik.com Git - apple/objc4.git/blob - runtime/message.h
objc4-371.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 #import <objc/objc.h>
25 #import <objc/runtime.h>
26
27
28 struct objc_super {
29 id receiver;
30 #if !defined(__cplusplus) && !__OBJC2__
31 Class class; /* For compatibility with old objc-runtime.h header */
32 #else
33 Class super_class;
34 #endif
35 /* super_class is the first class to search */
36 };
37
38
39 /* Basic Messaging Primitives
40 *
41 * On some architectures, use objc_msgSend_stret for some struct return types.
42 * On some architectures, use objc_msgSend_fpret for some float return types.
43 *
44 * These functions must be cast to an appropriate function pointer type
45 * before being called.
46 */
47 OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);
48 OBJC_EXPORT id objc_msgSendSuper(struct objc_super *super, SEL op, ...);
49
50
51 /* Struct-returning Messaging Primitives
52 *
53 * Use these functions to call methods that return structs on the stack.
54 * On some architectures, some structures are returned in registers.
55 * Consult your local function call ABI documentation for details.
56 *
57 * These functions must be cast to an appropriate function pointer type
58 * before being called.
59 */
60 #if defined(__OBJC2__)
61 OBJC_EXPORT void objc_msgSend_stret(id self, SEL op, ...);
62 OBJC_EXPORT void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);
63 #elif defined(__cplusplus)
64 /* For compatibility with old objc-runtime.h header */
65 OBJC_EXPORT id objc_msgSend_stret(id self, SEL op, ...);
66 OBJC_EXPORT id objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);
67 #else
68 /* For compatibility with old objc-runtime.h header */
69 OBJC_EXPORT void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...);
70 OBJC_EXPORT void objc_msgSendSuper_stret(void * stretAddr, struct objc_super *super, SEL op, ...);
71 #endif
72
73
74 /* Floating-point-returning Messaging Primitives
75 *
76 * Use these functions to call methods that return floating-point values
77 * on the stack.
78 * Consult your local function call ABI documentation for details.
79 *
80 * ppc: objc_msgSend_fpret not used
81 * ppc64: objc_msgSend_fpret not used
82 * i386: objc_msgSend_fpret used for `float`, `double`, `long double`.
83 * x86-64: objc_msgSend_fpret used for `long double`.
84 *
85 * These functions must be cast to an appropriate function pointer type
86 * before being called.
87 */
88 #if defined(__i386__)
89 OBJC_EXPORT double objc_msgSend_fpret(id self, SEL op, ...);
90 /* Use objc_msgSendSuper() for fp-returning messages to super. */
91 /* See also objc_msgSendv_fpret() below. */
92 #elif defined(__x86_64__)
93 OBJC_EXPORT long double objc_msgSend_fpret(id self, SEL op, ...);
94 /* Use objc_msgSendSuper() for fp-returning messages to super. */
95 /* See also objc_msgSendv_fpret() below. */
96 #endif
97
98
99 /* Direct Method Invocation Primitives
100 * Use these functions to call the implementation of a given Method.
101 * This is faster than calling method_getImplementation() and method_getName().
102 *
103 * The receiver must not be nil.
104 *
105 * These functions must be cast to an appropriate function pointer type
106 * before being called.
107 */
108 OBJC_EXPORT id method_invoke(id receiver, Method m, ...)
109 AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
110 OBJC_EXPORT void method_invoke_stret(id receiver, Method m, ...)
111 AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
112
113
114 /* Variable-argument Messaging Primitives
115 *
116 * Use these functions to call methods with a list of arguments, such
117 * as the one passed to forward:: .
118 *
119 * The contents of the argument list are architecture-specific.
120 * Consult your local function call ABI documentation for details.
121 *
122 * These functions must be cast to an appropriate function pointer type
123 * before being called, except for objc_msgSendv_stret() which must not
124 * be cast to a struct-returning type.
125 */
126
127 typedef void* marg_list;
128
129 OBJC_EXPORT id objc_msgSendv(id self, SEL op, size_t arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
130 OBJC_EXPORT void objc_msgSendv_stret(void *stretAddr, id self, SEL op, size_t arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
131 /* Note that objc_msgSendv_stret() does not return a structure type,
132 * and should not be cast to do so. This is unlike objc_msgSend_stret()
133 * and objc_msgSendSuper_stret().
134 */
135 #if defined(__i386__)
136 OBJC_EXPORT double objc_msgSendv_fpret(id self, SEL op, unsigned arg_size, marg_list arg_frame) OBJC2_UNAVAILABLE;
137 #endif
138
139
140 /* The following marg_list macros are of marginal utility. They
141 * are included for compatibility with the old objc-class.h header. */
142
143 #if !__OBJC2__
144
145 #if defined(__ppc__) || defined(ppc)
146 #define marg_prearg_size (13*sizeof(double)+6*sizeof(uintptr_t))
147 #else
148 #define marg_prearg_size 0
149 #endif
150
151 #define marg_malloc(margs, method) \
152 do { \
153 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
154 } while (0)
155
156 #define marg_free(margs) \
157 do { \
158 free(margs); \
159 } while (0)
160
161 #define marg_adjustedOffset(method, offset) \
162 (marg_prearg_size + offset)
163
164 #define marg_getRef(margs, offset, type) \
165 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
166
167 #define marg_getValue(margs, offset, type) \
168 ( *marg_getRef(margs, offset, type) )
169
170 #define marg_setValue(margs, offset, type, value) \
171 ( marg_getValue(margs, offset, type) = (value) )
172
173 #endif