]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-runtime.h
1b94c3bbd158559e3ac9070e536800dc6d109b35
[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 * 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
12 * this file.
13 *
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
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * objc-runtime.h
26 * Copyright 1988-1996, NeXT Software, Inc.
27 */
28
29 #ifndef _OBJC_RUNTIME_H_
30 #define _OBJC_RUNTIME_H_
31
32 #ifndef NeXT_PDO
33 #import <stdarg.h>
34 #endif
35 #import <objc/objc.h>
36 #import <objc/objc-class.h>
37
38 typedef struct objc_symtab *Symtab;
39
40 struct objc_symtab {
41 unsigned long sel_ref_cnt;
42 SEL *refs;
43 unsigned short cls_def_cnt;
44 unsigned short cat_def_cnt;
45 #ifdef NeXT_PDO
46 arith_t obj_defs;
47 arith_t proto_defs;
48 #endif
49 void *defs[1]; /* variable size */
50 };
51
52 typedef struct objc_module *Module;
53
54 struct objc_module {
55 unsigned long version;
56 unsigned long size;
57 const char *name;
58 Symtab symtab;
59 };
60
61 #ifdef __cplusplus
62 extern "Objective-C" {
63 #endif
64 struct objc_super {
65 id receiver;
66 Class class;
67 };
68 #ifdef __cplusplus
69 }
70 #endif
71
72 /* kernel operations */
73
74 OBJC_EXPORT id objc_getClass(const char *name);
75 OBJC_EXPORT id objc_getMetaClass(const char *name);
76 OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);
77 #if defined(WINNT) || defined(__cplusplus)
78 // The compiler on NT is broken when dealing with structure-returns.
79 // Help out the compiler group by tweaking the prototype.
80 OBJC_EXPORT id objc_msgSend_stret(id self, SEL op, ...);
81 #else
82 OBJC_EXPORT void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...);
83 #endif
84 OBJC_EXPORT id objc_msgSendSuper(struct objc_super *super, SEL op, ...);
85 #if defined(WINNT) || defined(__cplusplus)
86 // The compiler on NT is broken when dealing with structure-returns.
87 // Help out the compiler group by tweaking the prototype.
88 OBJC_EXPORT id objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);
89 #else
90 OBJC_EXPORT void objc_msgSendSuper_stret(void * stretAddr, struct objc_super *super, SEL op, ...);
91 #endif
92
93 /* forwarding operations */
94
95 OBJC_EXPORT id objc_msgSendv(id self, SEL op, unsigned arg_size, marg_list arg_frame);
96 OBJC_EXPORT void objc_msgSendv_stret(void * stretAddr, id self, SEL op, unsigned arg_size, marg_list arg_frame);
97
98 /*
99 getting all the classes in the application...
100
101 int objc_getClassList(buffer, bufferLen)
102 classes is an array of Class values (which are pointers)
103 which will be filled by the function; if this
104 argument is NULL, no copying is done, only the
105 return value is returned
106 bufferLen is the number of Class values the given buffer
107 can hold; if the buffer is not large enough to
108 hold all the classes, the buffer is filled to
109 the indicated capacity with some arbitrary subset
110 of the known classes, which could be different
111 from call to call
112 returns the number of classes, which is the number put
113 in the buffer if the buffer was large enough,
114 or the length the buffer should have been
115
116 int numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
117 Class *classes = NULL;
118 while (numClasses < newNumClasses) {
119 numClasses = newNumClasses;
120 classes = realloc(classes, sizeof(Class) * numClasses);
121 newNumClasses = objc_getClassList(classes, numClasses);
122 }
123 // now, can use the classes list; if NULL, there are no classes
124 free(classes);
125
126 */
127 OBJC_EXPORT int objc_getClassList(Class *buffer, int bufferLen);
128
129 #define OBSOLETE_OBJC_GETCLASSES 1
130 #if OBSOLETE_OBJC_GETCLASSES
131 OBJC_EXPORT void *objc_getClasses(void);
132 #endif
133
134 OBJC_EXPORT id objc_lookUpClass(const char *name);
135 OBJC_EXPORT void objc_addClass(Class myClass);
136
137 /* customizing the error handling for objc_getClass/objc_getMetaClass */
138
139 OBJC_EXPORT void objc_setClassHandler(int (*)(const char *));
140
141 /* Making the Objective-C runtime thread safe. */
142 OBJC_EXPORT void objc_setMultithreaded (BOOL flag);
143
144 /* overriding the default object allocation and error handling routines */
145
146 OBJC_EXPORT id (*_alloc)(Class, unsigned int);
147 OBJC_EXPORT id (*_copy)(id, unsigned int);
148 OBJC_EXPORT id (*_realloc)(id, unsigned int);
149 OBJC_EXPORT id (*_dealloc)(id);
150 OBJC_EXPORT id (*_zoneAlloc)(Class, unsigned int, void *);
151 OBJC_EXPORT id (*_zoneRealloc)(id, unsigned int, void *);
152 OBJC_EXPORT id (*_zoneCopy)(id, unsigned int, void *);
153
154 OBJC_EXPORT void (*_error)(id, const char *, va_list);
155
156
157 #endif /* _OBJC_RUNTIME_H_ */