]>
git.saurik.com Git - apple/objc4.git/blob - runtime/message.h
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 #include <objc/objc.h>
28 #include <objc/runtime.h>
35 #if !defined(__cplusplus) && !__OBJC2__
36 Class
class; /* For compatibility with old objc-runtime.h header */
40 /* super_class is the first class to search */
45 /* Basic Messaging Primitives
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.
51 * These functions must be cast to an appropriate function pointer type
52 * before being called.
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
);
60 /* Struct-returning Messaging Primitives
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.
66 * These functions must be cast to an appropriate function pointer type
67 * before being called.
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
);
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
);
89 /* Floating-point-returning Messaging Primitives
91 * Use these functions to call methods that return floating-point values
93 * Consult your local function call ABI documentation for details.
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`.
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`.
103 * These functions must be cast to an appropriate function pointer type
104 * before being called.
106 #if defined(__i386__)
108 OBJC_EXPORT
double objc_msgSend_fpret(id self
, SEL op
, ...)
109 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
111 /* Use objc_msgSendSuper() for fp-returning messages to super. */
112 /* See also objc_msgSendv_fpret() below. */
114 #elif defined(__x86_64__)
116 OBJC_EXPORT
long double objc_msgSend_fpret(id self
, SEL op
, ...)
117 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
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
);
123 OBJC_EXPORT
void objc_msgSend_fp2ret(id self
, SEL op
, ...)
124 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
127 /* Use objc_msgSendSuper() for fp-returning messages to super. */
128 /* See also objc_msgSendv_fpret() below. */
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().
137 * The receiver must not be nil.
139 * These functions must be cast to an appropriate function pointer type
140 * before being called.
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
);
148 /* Message Forwarding Primitives
149 * Use these functions to forward a message as if the receiver did not
152 * The receiver must not be nil.
154 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
155 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
157 * These functions must be cast to an appropriate function pointer type
158 * before being called.
160 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
161 * but may be compared to other IMP values.
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
);
169 /* Variable-argument Messaging Primitives
171 * Use these functions to call methods with a list of arguments, such
172 * as the one passed to forward:: .
174 * The contents of the argument list are architecture-specific.
175 * Consult your local function call ABI documentation for details.
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.
182 typedef void* marg_list
;
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().
190 #if defined(__i386__)
191 OBJC_EXPORT
double objc_msgSendv_fpret(id self
, SEL op
, unsigned arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
195 /* The following marg_list macros are of marginal utility. They
196 * are included for compatibility with the old objc-class.h header. */
200 #define marg_prearg_size 0
202 #define marg_malloc(margs, method) \
204 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
207 #define marg_free(margs) \
212 #define marg_adjustedOffset(method, offset) \
213 (marg_prearg_size + offset)
215 #define marg_getRef(margs, offset, type) \
216 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
218 #define marg_getValue(margs, offset, type) \
219 ( *marg_getRef(margs, offset, type) )
221 #define marg_setValue(margs, offset, type, value) \
222 ( marg_getValue(margs, offset, type) = (value) )