]>
git.saurik.com Git - apple/objc4.git/blob - runtime/objc-class.h
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Copyright 1988-1996, NeXT Software, Inc.
30 #ifndef _OBJC_CLASS_H_
31 #define _OBJC_CLASS_H_
38 struct objc_class
*isa
;
39 struct objc_class
*super_class
;
44 struct objc_ivar_list
*ivars
;
46 struct objc_method_list
**methodLists
;
48 struct objc_cache
*cache
;
49 struct objc_protocol_list
*protocols
;
51 #define CLS_GETINFO(cls,infomask) ((cls)->info & (infomask))
52 #define CLS_SETINFO(cls,infomask) ((cls)->info |= (infomask))
54 #define CLS_CLASS 0x1L
56 #define CLS_INITIALIZED 0x4L
57 #define CLS_POSING 0x8L
58 #define CLS_MAPPED 0x10L
59 #define CLS_FLUSH_CACHE 0x20L
60 #define CLS_GROW_CACHE 0x40L
61 #define CLS_NEED_BIND 0x80L
62 #define CLS_METHOD_ARRAY 0x100L
63 // the JavaBridge constructs classes with these markers
64 #define CLS_JAVA_HYBRID 0x200L
65 #define CLS_JAVA_CLASS 0x400L
66 // thread-safe +initialize
67 #define CLS_INITIALIZING 0x800
70 * (true as of 2001-9-24)
71 * Thread-safety note: changes to these flags are not atomic, so
72 * the only thing preventing lost updates is the timing of the changes.
74 * As long as the following are isolated from each other for any one class,
75 * nearly all flag updates will be safe:
77 * - loading in one thread (not including +load) without messaging
78 * - initializing in one thread with messaging from that thread only
79 * - multi-threaded messaging with method caching
81 * The current code doesn't protect loading yet.
83 * Times when the flags may change:
84 * CLS_CLASS: compile-time, hand-built classes
85 * CLS_META: compile time, hand-built classes
86 * CLS_INITIALIZED: initialize
87 * CLS_POSING: unsafe, but posing has other thread-safety problems
88 * CLS_MAPPED: compile-time
89 * CLS_FLUSH_CACHE: messaging
90 * CLS_GROW_CACHE: messaging
91 * FLUSH_CACHE and GROW_CACHE are protected from each other by the
93 * CLS_NEED_BIND: load, initialize
94 * CLS_METHOD_ARRAY: load
95 * CLS_JAVA_HYBRID: hand-built classes
96 * CLS_JAVA_CLASS: hand-built classes, initialize
97 * CLS_INITIALIZING: initialize
99 * The only unsafe updates are:
100 * - posing (unsafe anyway)
101 * - hand-built classes (including JavaBridge classes)
102 * There is a short time between objc_addClass inserts the new class
103 * into the class_hash and the builder setting the right flags.
104 * A thread looking at the class_hash could send a message to the class
105 * and trigger initialization, and the changes to the initialization
106 * flags and the hand-adjusted flags could collide.
107 * Solution: don't do that.
114 typedef struct objc_category
*Category
;
116 struct objc_category
{
119 struct objc_method_list
*instance_methods
;
120 struct objc_method_list
*class_methods
;
121 struct objc_protocol_list
*protocols
;
125 * Instance Variable Template
127 typedef struct objc_ivar
*Ivar
;
138 struct objc_ivar_list
{
143 struct objc_ivar ivar_list
[1]; /* variable length structure */
146 OBJC_EXPORT Ivar
object_setInstanceVariable(id
, const char *name
, void *);
147 OBJC_EXPORT Ivar
object_getInstanceVariable(id
, const char *name
, void **);
152 typedef struct objc_method
*Method
;
160 struct objc_method_list
{
161 struct objc_method_list
*obsolete
;
167 struct objc_method method_list
[1]; /* variable length structure */
170 /* Protocol support */
174 struct objc_protocol_list
{
175 struct objc_protocol_list
*next
;
180 /* Definitions of filer types */
199 #define _C_CHARPTR '*'
202 #define _C_UNION_B '('
203 #define _C_UNION_E ')'
204 #define _C_STRUCT_B '{'
205 #define _C_STRUCT_E '}'
207 /* Structure for method cache - allocated/sized at runtime */
209 typedef struct objc_cache
* Cache
;
211 #define CACHE_BUCKET_NAME(B) ((B)->method_name)
212 #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
213 #define CACHE_BUCKET_VALID(B) (B)
214 #define CACHE_HASH(sel, mask) (((uarith_t)(sel)>>2) & (mask))
216 unsigned int mask
; /* total = mask + 1 */
217 unsigned int occupied
;
222 OBJC_EXPORT id
class_createInstance(Class
, unsigned idxIvars
);
223 OBJC_EXPORT id
class_createInstanceFromZone(Class
, unsigned idxIvars
, void *z
);
225 OBJC_EXPORT
void class_setVersion(Class
, int);
226 OBJC_EXPORT
int class_getVersion(Class
);
228 OBJC_EXPORT Ivar
class_getInstanceVariable(Class
, const char *);
229 OBJC_EXPORT Method
class_getInstanceMethod(Class
, SEL
);
230 OBJC_EXPORT Method
class_getClassMethod(Class
, SEL
);
232 OBJC_EXPORT
void class_addMethods(Class
, struct objc_method_list
*);
233 OBJC_EXPORT
void class_removeMethods(Class
, struct objc_method_list
*);
235 OBJC_EXPORT Class
class_poseAs(Class imposter
, Class original
);
237 OBJC_EXPORT
unsigned method_getNumberOfArguments(Method
);
238 OBJC_EXPORT
unsigned method_getSizeOfArguments(Method
);
239 OBJC_EXPORT
unsigned method_getArgumentInfo(Method m
, int arg
, const char **type
, int *offset
);
241 // usage for nextMethodList
243 // void *iterator = 0;
244 // struct objc_method_list *mlist;
245 // while ( mlist = class_nextMethodList( cls, &iterator ) )
247 #define OBJC_NEXT_METHOD_LIST 1
248 OBJC_EXPORT
struct objc_method_list
*class_nextMethodList(Class
, void **);
250 typedef void *marg_list
;
252 #if defined(__ppc__) || defined(ppc)
253 #define marg_prearg_size 128
255 #define marg_prearg_size 0
258 #define marg_malloc(margs, method) \
260 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
264 #define marg_free(margs) \
269 #define marg_adjustedOffset(method, offset) \
270 (marg_prearg_size + offset)
275 #define marg_getRef(margs, offset, type) \
276 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
278 #define marg_getValue(margs, offset, type) \
279 ( *marg_getRef(margs, offset, type) )
281 #define marg_setValue(margs, offset, type, value) \
282 ( marg_getValue(margs, offset, type) = (value) )
284 /* Load categories and non-referenced classes from libraries. */
286 #endif /* _OBJC_CLASS_H_ */