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.
50 * These functions must be cast to an appropriate function pointer type
51 * before being called.
53 OBJC_EXPORT id
objc_msgSend(id self
, SEL op
, ...);
54 OBJC_EXPORT id
objc_msgSendSuper(struct objc_super
*super
, SEL op
, ...);
57 /* Struct-returning Messaging Primitives
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.
63 * These functions must be cast to an appropriate function pointer type
64 * before being called.
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
, ...);
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
, ...);
80 /* Floating-point-returning Messaging Primitives
82 * Use these functions to call methods that return floating-point values
84 * Consult your local function call ABI documentation for details.
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`.
91 * These functions must be cast to an appropriate function pointer type
92 * before being called.
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. */
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().
109 * The receiver must not be nil.
111 * These functions must be cast to an appropriate function pointer type
112 * before being called.
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
;
120 /* Message Forwarding Primitives
121 * Use these functions to forward a message as if the receiver did not
124 * The receiver must not be nil.
126 * class_getMethodImplementation() may return (IMP)_objc_msgForward.
127 * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret
129 * These functions must be cast to an appropriate function pointer type
130 * before being called.
132 * Before Mac OS X 10.6, _objc_msgForward must not be called directly
133 * but may be compared to other IMP values.
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
;
141 /* Variable-argument Messaging Primitives
143 * Use these functions to call methods with a list of arguments, such
144 * as the one passed to forward:: .
146 * The contents of the argument list are architecture-specific.
147 * Consult your local function call ABI documentation for details.
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.
154 typedef void* marg_list
;
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().
162 #if defined(__i386__)
163 OBJC_EXPORT
double objc_msgSendv_fpret(id self
, SEL op
, unsigned arg_size
, marg_list arg_frame
) OBJC2_UNAVAILABLE
;
167 /* The following marg_list macros are of marginal utility. They
168 * are included for compatibility with the old objc-class.h header. */
172 #if defined(__ppc__) || defined(ppc)
173 #define marg_prearg_size (13*sizeof(double)+6*sizeof(uintptr_t))
175 #define marg_prearg_size 0
178 #define marg_malloc(margs, method) \
180 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
183 #define marg_free(margs) \
188 #define marg_adjustedOffset(method, offset) \
189 (marg_prearg_size + offset)
191 #define marg_getRef(margs, offset, type) \
192 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
194 #define marg_getValue(margs, offset, type) \
195 ( *marg_getRef(margs, offset, type) )
197 #define marg_setValue(margs, offset, type, value) \
198 ( marg_getValue(margs, offset, type) = (value) )