1 /* GNU Objective-C Runtime API - Traditional API
2 Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005,
3 2007, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef __objc_api_INCLUDE_GNU
27 #define __objc_api_INCLUDE_GNU
29 /* This file declares the "traditional" GNU Objective-C Runtime API.
30 It is the API supported by older versions of the GNU Objective-C
31 Runtime. Include this file to use it.
33 This API is being replaced by the "modern" GNU Objective-C Runtime
34 API, which is declared in objc/runtime.h. The "modern" API is very
35 similar to the API used by the modern Apple/NeXT runtime.
37 The last version of GCC supporting the traditional API is GCC 4.6.
38 This file will not exist in later versions of GCC.
40 Because the two APIs have some conflicting definitions (in
41 particular, Method and Category are defined differently) you should
42 include either objc/objc-api.h (to use the traditional GNU
43 Objective-C Runtime API) or objc/runtime.h (to use the modern GNU
44 Objective-C Runtime API), but not both. */
45 #ifdef __objc_runtime_INCLUDE_GNU
46 # error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one.
49 /* TODO: A deprecation warning any time the file is included ? */
52 #ifndef GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF
53 # include "deprecated/hash.h"
56 #include "objc-decls.h"
62 #endif /* __cplusplus */
64 #include "deprecated/METHOD_NULL.h"
66 /* Method descriptor returned by introspective Object methods.
67 This is really just the first part of the more complete objc_method
68 structure defined below and used internally by the runtime. */
69 struct objc_method_description
71 SEL name
; /* this is a selector, not a string */
72 char *types
; /* type encoding */
75 /* The following are used in encode strings to describe the type of
88 #define _C_LNG_LNG 'q'
89 #define _C_ULNG_LNG 'Q'
92 #define _C_LNG_DBL 'D'
98 #define _C_CHARPTR '*'
101 #define _C_UNION_B '('
102 #define _C_UNION_E ')'
103 #define _C_STRUCT_B '{'
104 #define _C_STRUCT_E '}'
105 #define _C_VECTOR '!'
106 #define _C_COMPLEX 'j'
108 /* _C_ATOM is never generated by the compiler. You can treat it as
109 equivalent to "*". */
112 #include "deprecated/objc_error.h"
114 #include "deprecated/struct_objc_static_instances.h"
115 #include "deprecated/struct_objc_symtab.h"
116 #include "deprecated/struct_objc_module.h"
117 #include "deprecated/struct_objc_ivar.h"
118 #include "deprecated/struct_objc_ivar_list.h"
119 #include "deprecated/struct_objc_method.h"
120 typedef struct objc_method Method
, *Method_t
;
122 #include "deprecated/struct_objc_method_list.h"
123 #include "deprecated/struct_objc_protocol_list.h"
126 ** This is used to assure consistent access to the info field of
129 #ifndef HOST_BITS_PER_LONG
130 #define HOST_BITS_PER_LONG (sizeof(long)*8)
133 #define __CLS_INFO(cls) ((cls)->info)
134 #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
135 #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
137 /* The structure is of type MetaClass */
138 #define _CLS_META 0x2L
139 #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
142 /* The structure is of type Class */
143 #define _CLS_CLASS 0x1L
144 #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
147 ** The class is initialized within the runtime. This means that
148 ** it has had correct super and sublinks assigned
150 #define _CLS_RESOLV 0x8L
151 #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
152 #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
155 ** The class has been send a +initialize message or a such is not
156 ** defined for this class
158 #define _CLS_INITIALIZED 0x04L
159 #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
160 #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
163 ** The class number of this class. This must be the same for both the
164 ** class and its meta class object
166 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
167 #define CLS_SETNUMBER(cls, num) \
168 ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
169 (cls)->info >>= (HOST_BITS_PER_LONG/2); \
170 __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
172 #include "deprecated/struct_objc_category.h"
174 typedef struct objc_category Category
, *Category_t
;
176 /* We include message.h for compatibility with the old objc-api.h
177 which included the declarations currently in message.h. The
178 Apple/NeXT runtime does not do this and only includes message.h in
179 objc-runtime.h. It does not matter that much since most of the
180 definitions in message.h are runtime-specific. */
184 ** This is a hook which is called by objc_lookup_class and
185 ** objc_get_class if the runtime is not able to find the class.
186 ** This may e.g. try to load in the class using dynamic loading.
187 ** The function is guaranteed to be passed a non-NULL name string.
188 ** In the Modern API, this is replaced by
189 ** objc_setGetUnknownClassHandler ().
191 objc_EXPORT
Class (*_objc_lookup_class
)(const char *name
);
194 ** This is a hook which is called by __objc_exec_class every time a class
195 ** or a category is loaded into the runtime. This may e.g. help a
196 ** dynamic loader determine the classes that have been loaded when
197 ** an object file is dynamically linked in.
199 objc_EXPORT
void (*_objc_load_callback
)(Class _class
, Category
* category
);
201 #include "deprecated/objc_object_alloc.h"
204 Standard functions for memory allocation and disposal. Users should
205 use these functions in their ObjC programs so that they work so that
206 they work properly with garbage collectors.
209 objc_malloc(size_t size
);
211 /* FIXME: Shouldn't the following be called objc_malloc_atomic ? The
212 GC function is GC_malloc_atomic() which makes sense.
215 objc_atomic_malloc(size_t size
);
218 objc_realloc(void *mem
, size_t size
);
221 objc_calloc(size_t nelem
, size_t size
);
224 objc_free(void *mem
);
226 #include "deprecated/objc_valloc.h"
227 #include "deprecated/objc_malloc.h"
229 #include "deprecated/objc_unexpected_exception.h"
231 objc_EXPORT Method_t
class_get_class_method(MetaClass _class
, SEL aSel
);
233 objc_EXPORT Method_t
class_get_instance_method(Class _class
, SEL aSel
);
235 objc_EXPORT Class
class_pose_as(Class impostor
, Class superclass
);
237 objc_EXPORT Class
objc_get_class(const char *name
);
239 objc_EXPORT Class
objc_lookup_class(const char *name
);
241 objc_EXPORT Class
objc_next_class(void **enum_state
);
243 objc_EXPORT
const char *sel_get_name(SEL selector
);
245 objc_EXPORT
const char *sel_get_type(SEL selector
);
247 objc_EXPORT SEL
sel_get_uid(const char *name
);
249 objc_EXPORT SEL
sel_get_any_uid(const char *name
);
251 objc_EXPORT SEL
sel_get_any_typed_uid(const char *name
);
253 objc_EXPORT SEL
sel_get_typed_uid(const char *name
, const char*);
255 objc_EXPORT SEL
sel_register_name(const char *name
);
257 objc_EXPORT SEL
sel_register_typed_name(const char *name
, const char*type
);
260 objc_EXPORT BOOL
sel_is_mapped (SEL aSel
);
262 extern id
class_create_instance(Class _class
);
264 static inline const char *
265 class_get_class_name(Class _class
)
267 return CLS_ISCLASS(_class
)?_class
->name
:((_class
==Nil
)?"Nil":0);
271 class_get_instance_size(Class _class
)
273 return CLS_ISCLASS(_class
)?_class
->instance_size
:0;
276 static inline MetaClass
277 class_get_meta_class(Class _class
)
279 return CLS_ISCLASS(_class
)?_class
->class_pointer
:Nil
;
283 class_get_super_class(Class _class
)
285 return CLS_ISCLASS(_class
)?_class
->super_class
:Nil
;
289 class_get_version(Class _class
)
291 return CLS_ISCLASS(_class
)?_class
->version
:-1;
295 class_is_class(Class _class
)
297 return CLS_ISCLASS(_class
);
301 class_is_meta_class(Class _class
)
303 return CLS_ISMETA(_class
);
308 class_set_version(Class _class
, long version
)
310 if (CLS_ISCLASS(_class
))
311 _class
->version
= version
;
315 class_get_gc_object_type (Class _class
)
317 return CLS_ISCLASS(_class
) ? _class
->gc_object_type
: NULL
;
320 /* Mark the instance variable as innaccessible to the garbage collector */
321 extern void class_ivar_set_gcinvisible (Class _class
,
322 const char* ivarname
,
325 objc_EXPORT IMP
method_get_imp(Method_t method
);
327 objc_EXPORT IMP
get_imp (Class _class
, SEL sel
);
329 /* object_copy used to take a single argument in the traditional GNU
330 Objective-C Runtime API (the one declared here), but takes 2 in the
331 modern API (implemented in the actual runtime). Define the old
332 object_copy in terms of the new one. */
333 objc_EXPORT id
object_copy (id object
, size_t size
);
334 #define object_copy(X) (object_copy ((X), 0))
336 objc_EXPORT id
object_dispose(id object
);
339 object_get_class(id object
)
341 return ((object
!=nil
)
342 ? (CLS_ISCLASS(object
->class_pointer
)
343 ? object
->class_pointer
344 : (CLS_ISMETA(object
->class_pointer
)
350 static inline const char *
351 object_get_class_name(id object
)
353 return ((object
!=nil
)?(CLS_ISCLASS(object
->class_pointer
)
354 ?object
->class_pointer
->name
355 :((Class
)object
)->name
)
359 static inline MetaClass
360 object_get_meta_class(id object
)
362 return ((object
!=nil
)?(CLS_ISCLASS(object
->class_pointer
)
363 ?object
->class_pointer
->class_pointer
364 :(CLS_ISMETA(object
->class_pointer
)
365 ?object
->class_pointer
371 object_get_super_class
374 return ((object
!=nil
)?(CLS_ISCLASS(object
->class_pointer
)
375 ?object
->class_pointer
->super_class
376 :(CLS_ISMETA(object
->class_pointer
)
377 ?((Class
)object
)->super_class
383 object_is_class (id object
)
385 return ((object
!= nil
) && CLS_ISMETA (object
->class_pointer
));
389 object_is_instance (id object
)
391 return ((object
!= nil
) && CLS_ISCLASS (object
->class_pointer
));
395 object_is_meta_class (id object
)
397 return ((object
!= nil
)
398 && !object_is_instance (object
)
399 && !object_is_class (object
));
402 #include "deprecated/objc_get_uninstalled_dtable.h"
406 #endif /* __cplusplus */
408 #endif /* not __objc_api_INCLUDE_GNU */