1
/* Definitions to allow compilation of GNU objc code with NeXT runtime
4
Copyright (C) 1993,1994,1996,2003 Free Software Foundation, Inc.
6
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
9
This file is part of the GNUstep Base Library.
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Library General Public
13
License as published by the Free Software Foundation; either
14
version 2 of the License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Library General Public License for more details.
21
You should have received a copy of the GNU Library General Public
22
License along with this library; if not, write to the Free
23
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
26
/* This file is by no means complete. */
28
#ifndef __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE
29
#define __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE
33
#include <objc/objc-class.h>
34
#include <objc/objc-runtime.h>
39
/* Disable builtin functions for gcc < 3.x since it triggers a bad bug
40
(even some 3.x versions may have this bug). */
42
#define __builtin_apply(a,b,c) 0
43
#define __builtin_apply_args() 0
44
#define __builtin_return(a) 0
49
char arg_regs[sizeof (char*)];
50
} *arglist_t; /* argument frame */
51
//#define arglist_t marg_list
52
#define retval_t void*
53
typedef void(*apply_t)(void); /* function pointer */
54
#define TypedStream void*
56
#define METHOD_NULL (struct objc_method *)0
58
#define _CLS_META CLS_META
59
#define _CLS_CLASS CLS_CLASS
61
#define class_pointer isa
62
typedef struct objc_super Super;
64
#define class_create_instance(CLASS) class_createInstance(CLASS, 0)
65
#define class_get_instance_method class_getInstanceMethod
66
#define class_add_method_list class_addMethods
67
#define class_set_version class_setVersion
68
#define class_get_version class_getVersion
69
#define class_pose_as class_poseAs
70
#define method_get_sizeof_arguments method_getSizeOfArguments
71
#define objc_lookup_class objc_lookUpClass
72
#define objc_get_class objc_getClass
74
#define sel_register_name sel_registerName
75
#define sel_is_mapped sel_isMapped
76
#define sel_get_name sel_getName
77
#define sel_get_any_uid sel_getUid
78
#define sel_get_uid sel_getUid
79
#define sel_eq(s1, s2) (s1 == s2)
81
#define __objc_update_dispatch_table_for_class _objc_flush_caches
83
/* There's no support for typed sels in NeXT. These may not work */
84
#define sel_get_typed_uid(_s, _t) sel_getUid(_s)
85
#define sel_get_any_typed_uid sel_getUid
86
#define sel_register_typed_name(_s, _t) sel_registerName(_s)
87
#define sel_get_type(_s) (NULL)
89
#define class_get_class_name(CLASSPOINTER) \
90
(((struct objc_class*)(CLASSPOINTER))->name)
91
#define object_get_class(OBJECT) \
92
(((struct objc_class*)(OBJECT))->isa)
93
#define class_get_super_class(CLASSPOINTER) \
94
(((struct objc_class*)(CLASSPOINTER))->super_class)
95
#define object_get_super_class(OBJECT) \
96
(((struct objc_class*)(object_get_class(OBJECT)))->super_class)
97
#define object_get_class_name(OBJECT) \
98
(((struct objc_class*)(object_get_class(OBJECT)))->name)
100
#define __objc_responds_to(OBJECT,SEL) \
101
(class_getInstanceMethod(object_get_class(OBJECT), SEL) != METHOD_NULL)
102
#define CLS_ISCLASS(CLASSPOINTER) \
103
((((struct objc_class*)(CLASSPOINTER))->info) & CLS_CLASS)
104
#define CLS_ISMETA(CLASSPOINTER) \
105
((((struct objc_class*)(CLASSPOINTER))->info) & CLS_META)
106
#define objc_msg_lookup(OBJ,SEL) \
107
(class_getInstanceMethod(object_get_class(OBJ), SEL)->method_imp)
108
#define objc_msg_lookup_super(OBJ,SEL) \
109
(class_getInstanceMethod(object_get_class(OBJ), SEL)->method_imp)
111
#define objc_msg_sendv next_objc_msg_sendv
113
extern id next_objc_msg_sendv(id self, SEL op, void* arg_frame);
115
#define OBJC_READONLY 1
116
#define OBJC_WRITEONLY 2
119
** Standard functions for memory allocation and disposal.
120
** Users should use these functions in their ObjC programs so
121
** that they work properly with garbage collectors as well as
122
** can take advantage of the exception/error handling available.
125
objc_malloc(size_t size);
128
objc_atomic_malloc(size_t size);
131
objc_valloc(size_t size);
134
objc_realloc(void *mem, size_t size);
137
objc_calloc(size_t nelem, size_t size);
140
objc_free(void *mem);
143
class_is_class(Class class)
145
return CLS_ISCLASS(class);
149
object_is_class(id object)
151
return CLS_ISCLASS((Class)object);
155
class_get_instance_size(Class class)
157
return CLS_ISCLASS(class)?class->instance_size:0;
161
method_get_imp(Method method)
163
return (method!=0)?method->method_imp:(IMP)0;
167
get_imp(Class class, SEL aSel)
169
return method_get_imp(class_getInstanceMethod(class, aSel));
173
object_is_instance(id object)
175
return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
179
** Hook functions for memory allocation and disposal.
180
** This makes it easy to substitute garbage collection systems
181
** such as Boehm's GC by assigning these function pointers
182
** to the GC's allocation routines. By default these point
183
** to the ANSI standard malloc, realloc, free, etc.
185
** Users should call the normal objc routines above for
186
** memory allocation and disposal within their programs.
188
extern void *(*_objc_malloc)(size_t);
189
extern void *(*_objc_atomic_malloc)(size_t);
190
extern void *(*_objc_valloc)(size_t);
191
extern void *(*_objc_realloc)(void *, size_t);
192
extern void *(*_objc_calloc)(size_t, size_t);
193
extern void (*_objc_free)(void *);
196
/* threading functions */
197
typedef void *objc_mutex_t;
199
objc_mutex_t objc_mutex_allocate (void);
200
int objc_mutex_deallocate (objc_mutex_t mutex);
201
int objc_mutex_lock (objc_mutex_t mutex);
202
int objc_mutex_unlock (objc_mutex_t mutex);
203
int objc_mutex_trylock (objc_mutex_t mutex);
205
/* encoding functions */
206
extern int objc_sizeof_type(const char* type);
207
extern int objc_alignof_type(const char* type);
208
extern int objc_aligned_size (const char* type);
209
extern int objc_promoted_size (const char* type);
210
extern const char *objc_skip_type_qualifiers (const char* type);
211
extern const char *objc_skip_typespec (const char* type);
212
extern const char *objc_skip_argspec (const char* type);
213
extern unsigned objc_get_type_qualifiers (const char* type);
214
extern BOOL sel_types_match (const char* t1, const char* t2);
217
extern void objc_error(id object, int code, const char* fmt, ...);
218
extern void objc_verror(id object, int code, const char* fmt, va_list ap);
219
typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap);
220
objc_error_handler objc_set_error_handler(objc_error_handler func);
224
** These are used by the runtime library, and your
225
** error handling may use them to determine if the error is
226
** hard or soft thus whether execution can continue or abort.
228
#define OBJC_ERR_UNKNOWN 0 /* Generic error */
230
#define OBJC_ERR_OBJC_VERSION 1 /* Incorrect runtime version */
231
#define OBJC_ERR_GCC_VERSION 2 /* Incorrect compiler version */
232
#define OBJC_ERR_MODULE_SIZE 3 /* Bad module size */
233
#define OBJC_ERR_PROTOCOL_VERSION 4 /* Incorrect protocol version */
235
#define OBJC_ERR_MEMORY 10 /* Out of memory */
237
#define OBJC_ERR_RECURSE_ROOT 20 /* Attempt to archive the root
238
object more than once. */
239
#define OBJC_ERR_BAD_DATA 21 /* Didn't read expected data */
240
#define OBJC_ERR_BAD_KEY 22 /* Bad key for object */
241
#define OBJC_ERR_BAD_CLASS 23 /* Unknown class */
242
#define OBJC_ERR_BAD_TYPE 24 /* Bad type specification */
243
#define OBJC_ERR_NO_READ 25 /* Cannot read stream */
244
#define OBJC_ERR_NO_WRITE 26 /* Cannot write stream */
245
#define OBJC_ERR_STREAM_VERSION 27 /* Incorrect stream version */
246
#define OBJC_ERR_BAD_OPCODE 28 /* Bad opcode */
248
#define OBJC_ERR_UNIMPLEMENTED 30 /* Method is not implemented */
250
#define OBJC_ERR_BAD_STATE 40 /* Bad thread state */
252
#else /* NeXT_RUNTIME */
255
* And to use the GNU runtime from old NeXT code ...
257
#define class_createInstance(CLASS, X) class_create_instance(CLASS)
258
#define class_getInstanceMethod class_get_instance_method
259
#define class_addMethods class_add_method_list
260
#define class_setVersion class_set_version
261
#define class_getVersion class_get_version
262
#define class_poseAs class_pose_as
263
#define method_getSizeOfArguments method_get_sizeof_arguments
264
#define objc_lookUpClass objc_lookup_class
265
#define objc_getClass objc_get_class
267
#define sel_registerName sel_register_name
268
#define sel_isMapped sel_is_mapped
269
#define sel_getName sel_get_name
270
#define sel_getUid sel_get_any_uid
272
#define _objc_flush_caches __objc_update_dispatch_table_for_class
274
#define class_getClassMethod(CLASS, SEL) \
275
class_get_class_method((CLASS)->class_pointer, (SEL))
277
#define class_nextMethodList(aClass,anIterator) (({\
278
if (*(anIterator) == 0) \
279
*((struct objc_method_list**)(anIterator)) = (aClass)->methods; \
281
*(anIterator) = (*((struct objc_method_list**)(anIterator)))->method_next; \
284
#endif /* NeXT_RUNTIME */
286
#endif /* __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE */