~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Headers/Additions/GNUstepBase/objc-gnu2next.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Definitions to allow compilation of GNU objc code with NeXT runtime
 
2
   and the reverse.
 
3
 
 
4
   Copyright (C) 1993,1994,1996,2003 Free Software Foundation, Inc.
 
5
 
 
6
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
 
7
   Date: May 1993
 
8
 
 
9
   This file is part of the GNUstep Base Library.
 
10
 
 
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.
 
15
   
 
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.
 
20
 
 
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.
 
24
*/ 
 
25
 
 
26
/* This file is by no means complete. */
 
27
 
 
28
#ifndef __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE
 
29
#define __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE
 
30
 
 
31
#if NeXT_RUNTIME
 
32
 
 
33
#include <objc/objc-class.h>
 
34
#include <objc/objc-runtime.h>
 
35
#include <stddef.h>
 
36
#include <ctype.h>
 
37
#include <stdio.h>
 
38
 
 
39
/* Disable builtin functions for gcc < 3.x since it triggers a bad bug 
 
40
   (even some 3.x versions may have this bug).  */
 
41
#if __GNUC__ < 3
 
42
#define __builtin_apply(a,b,c) 0
 
43
#define __builtin_apply_args() 0
 
44
#define __builtin_return(a)  0
 
45
#endif
 
46
 
 
47
typedef union {
 
48
  char *arg_ptr;
 
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*
 
55
 
 
56
#define METHOD_NULL  (struct objc_method *)0
 
57
 
 
58
#define _CLS_META CLS_META
 
59
#define _CLS_CLASS CLS_CLASS
 
60
 
 
61
#define class_pointer isa
 
62
typedef struct objc_super Super;
 
63
 
 
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
 
73
 
 
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)
 
80
 
 
81
#define __objc_update_dispatch_table_for_class  _objc_flush_caches
 
82
 
 
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)
 
88
 
 
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)
 
99
 
 
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)
 
110
 
 
111
#define objc_msg_sendv                  next_objc_msg_sendv
 
112
 
 
113
extern id next_objc_msg_sendv(id self, SEL op, void* arg_frame);
 
114
 
 
115
#define OBJC_READONLY 1
 
116
#define OBJC_WRITEONLY 2
 
117
 
 
118
/*
 
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.
 
123
*/
 
124
void *
 
125
objc_malloc(size_t size);
 
126
 
 
127
void *
 
128
objc_atomic_malloc(size_t size);
 
129
 
 
130
void *
 
131
objc_valloc(size_t size);
 
132
 
 
133
void *
 
134
objc_realloc(void *mem, size_t size);
 
135
 
 
136
void *
 
137
objc_calloc(size_t nelem, size_t size);
 
138
 
 
139
void
 
140
objc_free(void *mem);
 
141
 
 
142
static inline BOOL
 
143
class_is_class(Class class)
 
144
{
 
145
  return CLS_ISCLASS(class);
 
146
}
 
147
 
 
148
static inline BOOL
 
149
object_is_class(id object)
 
150
{
 
151
  return CLS_ISCLASS((Class)object);
 
152
}
 
153
 
 
154
static inline long
 
155
class_get_instance_size(Class class)
 
156
{
 
157
  return CLS_ISCLASS(class)?class->instance_size:0;
 
158
}
 
159
 
 
160
static inline IMP
 
161
method_get_imp(Method method)
 
162
{
 
163
  return (method!=0)?method->method_imp:(IMP)0;
 
164
}
 
165
 
 
166
static inline IMP
 
167
get_imp(Class class, SEL aSel)
 
168
{
 
169
  return method_get_imp(class_getInstanceMethod(class, aSel));
 
170
}
 
171
 
 
172
static inline BOOL
 
173
object_is_instance(id object)
 
174
{
 
175
  return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
 
176
}
 
177
 
 
178
/*
 
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.
 
184
**
 
185
** Users should call the normal objc routines above for
 
186
** memory allocation and disposal within their programs.
 
187
*/
 
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 *);
 
194
 
 
195
 
 
196
/* threading functions */
 
197
typedef void *objc_mutex_t;
 
198
 
 
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);
 
204
 
 
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);
 
215
 
 
216
/* Error handling */
 
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);
 
221
 
 
222
/*
 
223
** Error codes
 
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.
 
227
*/
 
228
#define OBJC_ERR_UNKNOWN 0             /* Generic error */
 
229
 
 
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 */
 
234
 
 
235
#define OBJC_ERR_MEMORY 10             /* Out of memory */
 
236
 
 
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 */
 
247
 
 
248
#define OBJC_ERR_UNIMPLEMENTED 30      /* Method is not implemented */
 
249
 
 
250
#define OBJC_ERR_BAD_STATE 40          /* Bad thread state */
 
251
 
 
252
#else   /* NeXT_RUNTIME */
 
253
 
 
254
/*
 
255
 * And to use the GNU runtime from old NeXT code ...
 
256
 */
 
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
 
266
 
 
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
 
271
 
 
272
#define _objc_flush_caches              __objc_update_dispatch_table_for_class
 
273
 
 
274
#define class_getClassMethod(CLASS, SEL)        \
 
275
  class_get_class_method((CLASS)->class_pointer, (SEL))
 
276
 
 
277
#define class_nextMethodList(aClass,anIterator) (({\
 
278
  if (*(anIterator) == 0) \
 
279
    *((struct objc_method_list**)(anIterator)) = (aClass)->methods; \
 
280
  else \
 
281
    *(anIterator) = (*((struct objc_method_list**)(anIterator)))->method_next; \
 
282
}), *(anIterator))
 
283
 
 
284
#endif /* NeXT_RUNTIME */
 
285
 
 
286
#endif /* __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE */