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 #if !defined(_OBJC_PRIVATE_H_)
30 #define _OBJC_PRIVATE_H_
32 #import <objc/objc-api.h> // for OBJC_EXPORT
34 OBJC_EXPORT
void checkUniqueness();
36 #import "objc-config.h"
39 #define mutex_alloc() (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t))
40 #define mutex_init(m) pthread_mutex_init(m, NULL)
41 #define mutex_lock(m) pthread_mutex_lock(m)
42 #define mutex_try_lock(m) (! pthread_mutex_trylock(m))
43 #define mutex_unlock(m) pthread_mutex_unlock(m)
44 #define mutex_clear(m)
45 #define mutex_t pthread_mutex_t*
46 #define mutex MUTEX_DEFINE_ERROR
55 #import <objc/objc-runtime.h>
57 // This needs <...> -- malloc.h is not ours, really...
58 #import <objc/malloc.h>
61 /* Opaque cookie used in _getObjc... routines. File format independant.
62 * This is used in place of the mach_header. In fact, when compiling
63 * for NEXTSTEP, this is really a (struct mach_header *).
65 * had been: typedef void *objc_header;
68 typedef void headerType
;
70 #import <mach-o/loader.h>
71 typedef struct mach_header headerType
;
74 #import <objc/Protocol.h>
76 typedef struct _ProtocolTemplate
{ @
defs(Protocol
) } ProtocolTemplate
;
77 typedef struct _NXConstantStringTemplate
{
81 } NXConstantStringTemplate
;
84 #define OBJC_CONSTANT_STRING_PTR NXConstantStringTemplate**
85 #define OBJC_CONSTANT_STRING_DEREF
86 #define OBJC_PROTOCOL_PTR ProtocolTemplate**
87 #define OBJC_PROTOCOL_DEREF ->
88 #elif defined(__MACH__)
89 #define OBJC_CONSTANT_STRING_PTR NXConstantStringTemplate*
90 #define OBJC_CONSTANT_STRING_DEREF &
91 #define OBJC_PROTOCOL_PTR ProtocolTemplate*
92 #define OBJC_PROTOCOL_DEREF .
96 OBJC_EXPORT headerType
** _getObjcHeaders();
97 OBJC_EXPORT Module
_getObjcModules(headerType
*head
, int *nmodules
);
98 OBJC_EXPORT Class
* _getObjcClassRefs(headerType
*head
, int *nclasses
);
99 OBJC_EXPORT
void * _getObjcHeaderData(headerType
*head
, unsigned *size
);
100 OBJC_EXPORT
const char * _getObjcHeaderName(headerType
*head
);
102 // internal routines for delaying binding
103 void _objc_resolve_categories_for_class (struct objc_class
* cls
);
104 void _objc_bindModuleContainingClass(struct objc_class
* cls
);
106 // someday a logging facility
107 // ObjC is assigned the range 0xb000 - 0xbfff for first parameter
108 #define trace(a, b, c, d) do {} while (0)
112 OBJC_EXPORT ProtocolTemplate
* _getObjcProtocols(headerType
*head
, int *nprotos
);
113 OBJC_EXPORT NXConstantStringTemplate
*_getObjcStringObjects(headerType
*head
, int *nstrs
);
114 OBJC_EXPORT SEL
* _getObjcMessageRefs(headerType
*head
, int *nmess
);
116 #define END_OF_METHODS_LIST ((struct objc_method_list*)-1)
118 typedef struct _header_info
120 const headerType
* mhdr
;
122 unsigned int mod_count
;
123 unsigned long image_slide
;
124 struct _header_info
* next
;
126 OBJC_EXPORT header_info
*_objc_headerStart ();
128 OBJC_EXPORT
int _objcModuleCount();
129 OBJC_EXPORT
const char *_objcModuleNameAtIndex(int i
);
130 OBJC_EXPORT Class
objc_getOrigClass (const char *name
);
132 extern struct objc_method_list
**get_base_method_list(Class cls
);
135 OBJC_EXPORT
const char *__S(_nameForHeader
) (const headerType
*);
138 OBJC_EXPORT
void _sel_resolve_conflicts(headerType
* header
, unsigned long slide
);
139 OBJC_EXPORT
void _class_install_relationships(Class
, long);
140 OBJC_EXPORT
void *_objc_create_zone(void);
142 OBJC_EXPORT SEL
sel_registerNameNoCopy(const char *str
);
144 /* selector fixup in method lists */
146 #define _OBJC_FIXED_UP ((void *)1771)
148 static inline struct objc_method_list
*_objc_inlined_fixup_selectors_in_method_list(struct objc_method_list
*mlist
)
152 struct objc_method_list
*old_mlist
;
154 if ( ! mlist
) return (struct objc_method_list
*)0;
155 if ( mlist
->obsolete
!= _OBJC_FIXED_UP
) {
157 size
= sizeof(struct objc_method_list
) - sizeof(struct objc_method
) + old_mlist
->method_count
* sizeof(struct objc_method
);
158 mlist
= malloc_zone_malloc(_objc_create_zone(), size
);
159 memmove(mlist
, old_mlist
, size
);
160 for ( i
= 0; i
< mlist
->method_count
; i
+= 1 ) {
161 method
= &mlist
->method_list
[i
];
162 method
->method_name
=
163 sel_registerNameNoCopy((const char *)method
->method_name
);
165 mlist
->obsolete
= _OBJC_FIXED_UP
;
171 /* -- inline version of class_nextMethodList(Class, void **) -- */
173 static inline struct objc_method_list
*_class_inlinedNextMethodList(Class cls
, void **it
)
175 struct objc_method_list
***iterator
;
177 iterator
= (struct objc_method_list
***)it
;
178 if (*iterator
== NULL
) {
179 *iterator
= &((((struct objc_class
*) cls
)->methodLists
)[0]);
181 else (*iterator
) += 1;
182 // Check for list end
183 if ((**iterator
== NULL
) || (**iterator
== END_OF_METHODS_LIST
)) {
188 **iterator
= _objc_inlined_fixup_selectors_in_method_list(**iterator
);
190 // Return method list pointer
194 OBJC_EXPORT BOOL
class_respondsToMethod(Class
, SEL
);
195 OBJC_EXPORT IMP
class_lookupMethod(Class
, SEL
);
196 OBJC_EXPORT IMP
class_lookupMethodInMethodList(struct objc_method_list
*mlist
, SEL sel
);
197 OBJC_EXPORT IMP
class_lookupNamedMethodInMethodList(struct objc_method_list
*mlist
, const char *meth_name
);
198 OBJC_EXPORT
void _objc_insertMethods( struct objc_method_list
*mlist
, struct objc_method_list
***list
);
199 OBJC_EXPORT
void _objc_removeMethods( struct objc_method_list
*mlist
, struct objc_method_list
***list
);
201 /* message dispatcher */
202 OBJC_EXPORT Cache
_cache_create(Class
);
203 OBJC_EXPORT IMP
_class_lookupMethodAndLoadCache(Class
, SEL
);
204 OBJC_EXPORT id
_objc_msgForward (id self
, SEL sel
, ...);
207 OBJC_EXPORT
volatile void __S(_objc_fatal
)(const char *message
);
208 OBJC_EXPORT
volatile void _objc_error(id
, const char *, va_list);
209 OBJC_EXPORT
volatile void __objc_error(id
, const char *, ...);
210 OBJC_EXPORT
void _objc_inform(const char *fmt
, ...);
211 OBJC_EXPORT
void _objc_syslog(const char *fmt
, ...);
214 OBJC_EXPORT Class
_objc_getFreedObjectClass (void);
215 OBJC_EXPORT
const struct objc_cache emptyCache
;
216 OBJC_EXPORT
void _objc_flush_caches (Class cls
);
219 #define MUTEX_TYPE pthread_mutex_t*
220 #define OBJC_DECLARE_LOCK(MTX) pthread_mutex_t MTX = PTHREAD_MUTEX_INITIALIZER
221 OBJC_EXPORT pthread_mutex_t classLock
;
222 OBJC_EXPORT pthread_mutex_t messageLock
;
224 OBJC_EXPORT
int _objc_multithread_mask
;
226 // _objc_msgNil is actually (unsigned dummy, id, SEL) for i386;
227 // currently not implemented for any sparc or hppa platforms
228 OBJC_EXPORT
void (*_objc_msgNil
)(id
, SEL
);
235 static inline int selEqual( SEL s1
, SEL s2
) {
239 #if defined(OBJC_COLLECTING_CACHE)
240 #define OBJC_LOCK(MUTEX) mutex_lock (MUTEX)
241 #define OBJC_UNLOCK(MUTEX) mutex_unlock (MUTEX)
242 #define OBJC_TRYLOCK(MUTEX) mutex_try_lock (MUTEX)
243 #else // not OBJC_COLLECTING_CACHE
244 #define OBJC_LOCK(MUTEX) \
247 if (!_objc_multithread_mask) \
248 mutex_lock (MUTEX); \
252 #define OBJC_UNLOCK(MUTEX) \
255 if (!_objc_multithread_mask) \
256 mutex_unlock (MUTEX); \
259 #endif /* OBJC_COLLECTING_CACHE */
261 #if !defined(SEG_OBJC)
262 #define SEG_OBJC "__OBJC" /* objective-C runtime segment */
268 static __inline__
int _objc_strcmp(const unsigned char *s1
, const unsigned char *s2
) {
273 if (a
!= b
|| 0 == a
) break;
279 static __inline__
unsigned int _objc_strhash(const unsigned char *s
) {
280 unsigned int hash
= 0;
284 hash
+= (hash
<< 8) + a
;
289 #endif /* _OBJC_PRIVATE_H_ */