]>
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 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Copyright 1988-1996, NeXT Software, Inc.
29 #ifndef _OBJC_CLASS_H_
30 #define _OBJC_CLASS_H_
37 struct objc_class
*isa
;
38 struct objc_class
*super_class
;
43 struct objc_ivar_list
*ivars
;
45 struct objc_method_list
**methodLists
;
47 struct objc_cache
*cache
;
48 struct objc_protocol_list
*protocols
;
50 #define CLS_GETINFO(cls,infomask) ((cls)->info & (infomask))
51 #define CLS_SETINFO(cls,infomask) ((cls)->info |= (infomask))
53 #define CLS_CLASS 0x1L
55 #define CLS_INITIALIZED 0x4L
56 #define CLS_POSING 0x8L
57 #define CLS_MAPPED 0x10L
58 #define CLS_FLUSH_CACHE 0x20L
59 #define CLS_GROW_CACHE 0x40L
60 #define CLS_NEED_BIND 0x80L
61 #define CLS_METHOD_ARRAY 0x100L
62 // the JavaBridge constructs classes with these markers
63 #define CLS_JAVA_HYBRID 0x200L
64 #define CLS_JAVA_CLASS 0x400L
65 // thread-safe +initialize
66 #define CLS_INITIALIZING 0x800
69 * (true as of 2001-9-24)
70 * Thread-safety note: changes to these flags are not atomic, so
71 * the only thing preventing lost updates is the timing of the changes.
73 * As long as the following are isolated from each other for any one class,
74 * nearly all flag updates will be safe:
76 * - loading in one thread (not including +load) without messaging
77 * - initializing in one thread with messaging from that thread only
78 * - multi-threaded messaging with method caching
80 * The current code doesn't protect loading yet.
82 * Times when the flags may change:
83 * CLS_CLASS: compile-time, hand-built classes
84 * CLS_META: compile time, hand-built classes
85 * CLS_INITIALIZED: initialize
86 * CLS_POSING: unsafe, but posing has other thread-safety problems
87 * CLS_MAPPED: compile-time
88 * CLS_FLUSH_CACHE: messaging
89 * CLS_GROW_CACHE: messaging
90 * FLUSH_CACHE and GROW_CACHE are protected from each other by the
92 * CLS_NEED_BIND: load, initialize
93 * CLS_METHOD_ARRAY: load
94 * CLS_JAVA_HYBRID: hand-built classes
95 * CLS_JAVA_CLASS: hand-built classes, initialize
96 * CLS_INITIALIZING: initialize
98 * The only unsafe updates are:
99 * - posing (unsafe anyway)
100 * - hand-built classes (including JavaBridge classes)
101 * There is a short time between objc_addClass inserts the new class
102 * into the class_hash and the builder setting the right flags.
103 * A thread looking at the class_hash could send a message to the class
104 * and trigger initialization, and the changes to the initialization
105 * flags and the hand-adjusted flags could collide.
106 * Solution: don't do that.
113 typedef struct objc_category
*Category
;
115 struct objc_category
{
118 struct objc_method_list
*instance_methods
;
119 struct objc_method_list
*class_methods
;
120 struct objc_protocol_list
*protocols
;
124 * Instance Variable Template
126 typedef struct objc_ivar
*Ivar
;
137 struct objc_ivar_list
{
142 struct objc_ivar ivar_list
[1]; /* variable length structure */
145 OBJC_EXPORT Ivar
object_setInstanceVariable(id
, const char *name
, void *);
146 OBJC_EXPORT Ivar
object_getInstanceVariable(id
, const char *name
, void **);
151 typedef struct objc_method
*Method
;
159 struct objc_method_list
{
160 struct objc_method_list
*obsolete
;
166 struct objc_method method_list
[1]; /* variable length structure */
169 /* Protocol support */
173 struct objc_protocol_list
{
174 struct objc_protocol_list
*next
;
179 /* Definitions of filer types */
198 #define _C_CHARPTR '*'
201 #define _C_UNION_B '('
202 #define _C_UNION_E ')'
203 #define _C_STRUCT_B '{'
204 #define _C_STRUCT_E '}'
206 /* Structure for method cache - allocated/sized at runtime */
208 typedef struct objc_cache
* Cache
;
210 #define CACHE_BUCKET_NAME(B) ((B)->method_name)
211 #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
212 #define CACHE_BUCKET_VALID(B) (B)
213 #define CACHE_HASH(sel, mask) (((uarith_t)(sel)>>2) & (mask))
215 unsigned int mask
; /* total = mask + 1 */
216 unsigned int occupied
;
221 OBJC_EXPORT id
class_createInstance(Class
, unsigned idxIvars
);
222 OBJC_EXPORT id
class_createInstanceFromZone(Class
, unsigned idxIvars
, void *z
);
224 OBJC_EXPORT
void class_setVersion(Class
, int);
225 OBJC_EXPORT
int class_getVersion(Class
);
227 OBJC_EXPORT Ivar
class_getInstanceVariable(Class
, const char *);
228 OBJC_EXPORT Method
class_getInstanceMethod(Class
, SEL
);
229 OBJC_EXPORT Method
class_getClassMethod(Class
, SEL
);
231 OBJC_EXPORT
void class_addMethods(Class
, struct objc_method_list
*);
232 OBJC_EXPORT
void class_removeMethods(Class
, struct objc_method_list
*);
234 OBJC_EXPORT Class
class_poseAs(Class imposter
, Class original
);
236 OBJC_EXPORT
unsigned method_getNumberOfArguments(Method
);
237 OBJC_EXPORT
unsigned method_getSizeOfArguments(Method
);
238 OBJC_EXPORT
unsigned method_getArgumentInfo(Method m
, int arg
, const char **type
, int *offset
);
240 // usage for nextMethodList
242 // void *iterator = 0;
243 // struct objc_method_list *mlist;
244 // while ( mlist = class_nextMethodList( cls, &iterator ) )
246 #define OBJC_NEXT_METHOD_LIST 1
247 OBJC_EXPORT
struct objc_method_list
*class_nextMethodList(Class
, void **);
249 typedef void *marg_list
;
251 #if defined(__ppc__) || defined(ppc)
252 #define marg_prearg_size 128
254 #define marg_prearg_size 0
257 #define marg_malloc(margs, method) \
259 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
263 #define marg_free(margs) \
268 #define marg_adjustedOffset(method, offset) \
269 (marg_prearg_size + offset)
274 #define marg_getRef(margs, offset, type) \
275 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
277 #define marg_getValue(margs, offset, type) \
278 ( *marg_getRef(margs, offset, type) )
280 #define marg_setValue(margs, offset, type, value) \
281 ( marg_getValue(margs, offset, type) = (value) )
283 /* Load categories and non-referenced classes from libraries. */
285 #endif /* _OBJC_CLASS_H_ */