]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-runtime.h
objc4-235.tar.gz
[apple/objc4.git] / runtime / objc-runtime.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * objc-runtime.h
27 * Copyright 1988-1996, NeXT Software, Inc.
28 */
29
30 #ifndef _OBJC_RUNTIME_H_
31 #define _OBJC_RUNTIME_H_
32
33 #import <stdarg.h>
34 #import <AvailabilityMacros.h>
35 #import <objc/objc.h>
36 #import <objc/objc-class.h>
37
38 #if !defined(AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER)
39 /* For 10.2 compatibility */
40 # define AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
41 #endif
42
43 typedef struct objc_symtab *Symtab;
44
45 struct objc_symtab {
46 unsigned long sel_ref_cnt;
47 SEL *refs;
48 unsigned short cls_def_cnt;
49 unsigned short cat_def_cnt;
50 void *defs[1]; /* variable size */
51 };
52
53 typedef struct objc_module *Module;
54
55 struct objc_module {
56 unsigned long version;
57 unsigned long size;
58 const char *name;
59 Symtab symtab;
60 };
61
62 struct objc_super {
63 id receiver;
64 Class class;
65 };
66
67 /*
68 * Messaging Primitives (prototypes)
69 */
70
71 OBJC_EXPORT id objc_getClass(const char *name);
72 OBJC_EXPORT id objc_getMetaClass(const char *name);
73 OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);
74 OBJC_EXPORT id objc_msgSendSuper(struct objc_super *super, SEL op, ...);
75
76
77 /* Struct-returning Messaging Primitives (prototypes)
78 *
79 * For historical reasons, the prototypes for the struct-returning
80 * messengers are unusual. The portable, correct way to call these functions
81 * is to cast them to your desired return type first.
82 *
83 * For example, `NSRect result = [myNSView frame]` could be written as:
84 * NSRect (*msgSend_stret_fn)(id, SEL, ...) = (NSRect(*)(id, SEL, ...))objc_msgSend_stret;
85 * NSRect result = (*msgSend_stret_fn)(myNSView, @selector(frame));
86 * or, without the function pointer:
87 * NSRect result = (*(NSRect(*)(id, SEL, ...))objc_msgSend_stret)(myNSView, @selector(frame));
88 *
89 * BE WARNED that these prototypes have changed in the past and will change
90 * in the future. Code that uses a cast like the example above will be
91 * unaffected.
92 */
93
94 #if defined(__cplusplus)
95 OBJC_EXPORT id objc_msgSend_stret(id self, SEL op, ...);
96 OBJC_EXPORT id objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);
97 #else
98 OBJC_EXPORT void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...);
99 OBJC_EXPORT void objc_msgSendSuper_stret(void * stretAddr, struct objc_super *super, SEL op, ...);
100 #endif
101
102
103 /* Forwarding */
104
105 OBJC_EXPORT id objc_msgSendv(id self, SEL op, unsigned arg_size, marg_list arg_frame);
106 OBJC_EXPORT void objc_msgSendv_stret(void * stretAddr, id self, SEL op, unsigned arg_size, marg_list arg_frame);
107
108 /*
109 getting all the classes in the application...
110
111 int objc_getClassList(buffer, bufferLen)
112 classes is an array of Class values (which are pointers)
113 which will be filled by the function; if this
114 argument is NULL, no copying is done, only the
115 return value is returned
116 bufferLen is the number of Class values the given buffer
117 can hold; if the buffer is not large enough to
118 hold all the classes, the buffer is filled to
119 the indicated capacity with some arbitrary subset
120 of the known classes, which could be different
121 from call to call
122 returns the number of classes, which is the number put
123 in the buffer if the buffer was large enough,
124 or the length the buffer should have been
125
126 int numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
127 Class *classes = NULL;
128 while (numClasses < newNumClasses) {
129 numClasses = newNumClasses;
130 classes = realloc(classes, sizeof(Class) * numClasses);
131 newNumClasses = objc_getClassList(classes, numClasses);
132 }
133 // now, can use the classes list; if NULL, there are no classes
134 free(classes);
135
136 */
137 OBJC_EXPORT int objc_getClassList(Class *buffer, int bufferLen);
138
139 #define OBSOLETE_OBJC_GETCLASSES 1
140 #if OBSOLETE_OBJC_GETCLASSES
141 OBJC_EXPORT void *objc_getClasses(void);
142 #endif
143
144 OBJC_EXPORT id objc_lookUpClass(const char *name);
145 OBJC_EXPORT void objc_addClass(Class myClass);
146
147 /* customizing the error handling for objc_getClass/objc_getMetaClass */
148
149 OBJC_EXPORT void objc_setClassHandler(int (*)(const char *));
150
151 /* Making the Objective-C runtime thread safe. */
152 OBJC_EXPORT void objc_setMultithreaded (BOOL flag);
153
154 /* overriding the default object allocation and error handling routines */
155
156 OBJC_EXPORT id (*_alloc)(Class, unsigned int);
157 OBJC_EXPORT id (*_copy)(id, unsigned int);
158 OBJC_EXPORT id (*_realloc)(id, unsigned int);
159 OBJC_EXPORT id (*_dealloc)(id);
160 OBJC_EXPORT id (*_zoneAlloc)(Class, unsigned int, void *);
161 OBJC_EXPORT id (*_zoneRealloc)(id, unsigned int, void *);
162 OBJC_EXPORT id (*_zoneCopy)(id, unsigned int, void *);
163
164 OBJC_EXPORT void (*_error)(id, const char *, va_list);
165
166
167 #endif /* _OBJC_RUNTIME_H_ */