xref: /dflybsd-src/contrib/gcc-4.7/libobjc/objc/runtime.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* GNU Objective-C Runtime API - Modern API
2*e4b17023SJohn Marino    Copyright (C) 2010 Free Software Foundation, Inc.
3*e4b17023SJohn Marino    Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
4*e4b17023SJohn Marino 
5*e4b17023SJohn Marino This file is part of GCC.
6*e4b17023SJohn Marino 
7*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it
8*e4b17023SJohn Marino under the terms of the GNU General Public License as published by the
9*e4b17023SJohn Marino Free Software Foundation; either version 3, or (at your option) any
10*e4b17023SJohn Marino later version.
11*e4b17023SJohn Marino 
12*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT
13*e4b17023SJohn Marino ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15*e4b17023SJohn Marino License for more details.
16*e4b17023SJohn Marino 
17*e4b17023SJohn Marino Under Section 7 of GPL version 3, you are granted additional
18*e4b17023SJohn Marino permissions described in the GCC Runtime Library Exception, version
19*e4b17023SJohn Marino 3.1, as published by the Free Software Foundation.
20*e4b17023SJohn Marino 
21*e4b17023SJohn Marino You should have received a copy of the GNU General Public License and
22*e4b17023SJohn Marino a copy of the GCC Runtime Library Exception along with this program;
23*e4b17023SJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
25*e4b17023SJohn Marino 
26*e4b17023SJohn Marino #ifndef __objc_runtime_INCLUDE_GNU
27*e4b17023SJohn Marino #define __objc_runtime_INCLUDE_GNU
28*e4b17023SJohn Marino 
29*e4b17023SJohn Marino /*
30*e4b17023SJohn Marino   This file declares the "modern" GNU Objective-C Runtime API.
31*e4b17023SJohn Marino 
32*e4b17023SJohn Marino   This API replaced the "traditional" GNU Objective-C Runtime API
33*e4b17023SJohn Marino   (which used to be declared in objc/objc-api.h) which is the one
34*e4b17023SJohn Marino   supported by older versions of the GNU Objective-C Runtime.  The
35*e4b17023SJohn Marino   "modern" API is very similar to the API used by the modern
36*e4b17023SJohn Marino   Apple/NeXT runtime.
37*e4b17023SJohn Marino */
38*e4b17023SJohn Marino #include "objc.h"
39*e4b17023SJohn Marino #include "objc-decls.h"
40*e4b17023SJohn Marino 
41*e4b17023SJohn Marino #ifdef __cplusplus
42*e4b17023SJohn Marino extern "C" {
43*e4b17023SJohn Marino #endif /* __cplusplus */
44*e4b17023SJohn Marino 
45*e4b17023SJohn Marino /* An 'Ivar' represents an instance variable.  It holds information
46*e4b17023SJohn Marino    about the name, type and offset of the instance variable.  */
47*e4b17023SJohn Marino typedef struct objc_ivar *Ivar;
48*e4b17023SJohn Marino 
49*e4b17023SJohn Marino /* A 'Property' represents a property.  It holds information about the
50*e4b17023SJohn Marino    name of the property, and its attributes.
51*e4b17023SJohn Marino 
52*e4b17023SJohn Marino    Compatibility Note: the Apple/NeXT runtime defines this as
53*e4b17023SJohn Marino    objc_property_t, so we define it that way as well, but obviously
54*e4b17023SJohn Marino    Property is the right name.  */
55*e4b17023SJohn Marino typedef struct objc_property *Property;
56*e4b17023SJohn Marino typedef struct objc_property *objc_property_t;
57*e4b17023SJohn Marino 
58*e4b17023SJohn Marino /* A 'Method' represents a method.  It holds information about the
59*e4b17023SJohn Marino    name, types and the IMP of the method.  */
60*e4b17023SJohn Marino typedef struct objc_method *Method;
61*e4b17023SJohn Marino 
62*e4b17023SJohn Marino /* A 'Category' represents a category.  It holds information about the
63*e4b17023SJohn Marino    name of the category, the class it belongs to, and the methods,
64*e4b17023SJohn Marino    protocols and such like provided by the category.  */
65*e4b17023SJohn Marino typedef struct objc_category *Category;
66*e4b17023SJohn Marino 
67*e4b17023SJohn Marino /* 'Protocol' is defined in objc/objc.h (which is included by this
68*e4b17023SJohn Marino    file).  */
69*e4b17023SJohn Marino 
70*e4b17023SJohn Marino /* Method descriptor returned by introspective Object methods.  At the
71*e4b17023SJohn Marino    moment, this is really just the first part of the more complete
72*e4b17023SJohn Marino    objc_method structure used internally by the runtime.  (PS: In the
73*e4b17023SJohn Marino    GNU Objective-C Runtime, selectors already include a type, so an
74*e4b17023SJohn Marino    objc_method_description does not add much to a SEL.  But in other
75*e4b17023SJohn Marino    runtimes, that is not the case, which is why
76*e4b17023SJohn Marino    objc_method_description exists).  */
77*e4b17023SJohn Marino struct objc_method_description
78*e4b17023SJohn Marino {
79*e4b17023SJohn Marino   SEL name;      /* Selector (name and signature) */
80*e4b17023SJohn Marino   char *types;   /* Type encoding */
81*e4b17023SJohn Marino };
82*e4b17023SJohn Marino 
83*e4b17023SJohn Marino /* The following are used in encode strings to describe the type of
84*e4b17023SJohn Marino    Ivars and Methods.  */
85*e4b17023SJohn Marino #define _C_ID       '@'
86*e4b17023SJohn Marino #define _C_CLASS    '#'
87*e4b17023SJohn Marino #define _C_SEL      ':'
88*e4b17023SJohn Marino #define _C_CHR      'c'
89*e4b17023SJohn Marino #define _C_UCHR     'C'
90*e4b17023SJohn Marino #define _C_SHT      's'
91*e4b17023SJohn Marino #define _C_USHT     'S'
92*e4b17023SJohn Marino #define _C_INT      'i'
93*e4b17023SJohn Marino #define _C_UINT     'I'
94*e4b17023SJohn Marino #define _C_LNG      'l'
95*e4b17023SJohn Marino #define _C_ULNG     'L'
96*e4b17023SJohn Marino #define _C_LNG_LNG  'q'
97*e4b17023SJohn Marino #define _C_ULNG_LNG 'Q'
98*e4b17023SJohn Marino #define _C_FLT      'f'
99*e4b17023SJohn Marino #define _C_DBL      'd'
100*e4b17023SJohn Marino #define _C_LNG_DBL  'D'
101*e4b17023SJohn Marino #define _C_BFLD     'b'
102*e4b17023SJohn Marino #define _C_BOOL     'B'
103*e4b17023SJohn Marino #define _C_VOID     'v'
104*e4b17023SJohn Marino #define _C_UNDEF    '?'
105*e4b17023SJohn Marino #define _C_PTR      '^'
106*e4b17023SJohn Marino #define _C_CHARPTR  '*'
107*e4b17023SJohn Marino #define _C_ARY_B    '['
108*e4b17023SJohn Marino #define _C_ARY_E    ']'
109*e4b17023SJohn Marino #define _C_UNION_B  '('
110*e4b17023SJohn Marino #define _C_UNION_E  ')'
111*e4b17023SJohn Marino #define _C_STRUCT_B '{'
112*e4b17023SJohn Marino #define _C_STRUCT_E '}'
113*e4b17023SJohn Marino #define _C_VECTOR   '!'
114*e4b17023SJohn Marino #define _C_COMPLEX  'j'
115*e4b17023SJohn Marino 
116*e4b17023SJohn Marino /* _C_ATOM is never generated by the compiler.  You can treat it as
117*e4b17023SJohn Marino    equivalent to "*".  */
118*e4b17023SJohn Marino #define _C_ATOM     '%'
119*e4b17023SJohn Marino 
120*e4b17023SJohn Marino /* The following are used in encode strings to describe some
121*e4b17023SJohn Marino    qualifiers of method and ivar types.  */
122*e4b17023SJohn Marino #define _C_CONST	'r'
123*e4b17023SJohn Marino #define _C_IN		'n'
124*e4b17023SJohn Marino #define _C_INOUT	'N'
125*e4b17023SJohn Marino #define _C_OUT      	'o'
126*e4b17023SJohn Marino #define _C_BYCOPY	'O'
127*e4b17023SJohn Marino #define _C_BYREF	'R'
128*e4b17023SJohn Marino #define _C_ONEWAY	'V'
129*e4b17023SJohn Marino #define _C_GCINVISIBLE	'|'
130*e4b17023SJohn Marino 
131*e4b17023SJohn Marino /* The same when used as flags.  */
132*e4b17023SJohn Marino #define _F_CONST	0x01
133*e4b17023SJohn Marino #define _F_IN		0x01
134*e4b17023SJohn Marino #define _F_OUT		0x02
135*e4b17023SJohn Marino #define _F_INOUT	0x03
136*e4b17023SJohn Marino #define _F_BYCOPY	0x04
137*e4b17023SJohn Marino #define _F_BYREF	0x08
138*e4b17023SJohn Marino #define _F_ONEWAY	0x10
139*e4b17023SJohn Marino #define _F_GCINVISIBLE	0x20
140*e4b17023SJohn Marino 
141*e4b17023SJohn Marino 
142*e4b17023SJohn Marino /** Implementation: the following functions are defined inline.  */
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino /* Return the class of 'object', or Nil if the object is nil.  If
145*e4b17023SJohn Marino    'object' is a class, the meta class is returned; if 'object' is a
146*e4b17023SJohn Marino    meta class, the root meta class is returned (note that this is
147*e4b17023SJohn Marino    different from the traditional GNU Objective-C Runtime API function
148*e4b17023SJohn Marino    object_get_class(), which for a meta class would return the meta
149*e4b17023SJohn Marino    class itself).  This function is inline, so it is really fast and
150*e4b17023SJohn Marino    should be used instead of accessing object->class_pointer
151*e4b17023SJohn Marino    directly.  */
152*e4b17023SJohn Marino static inline Class
object_getClass(id object)153*e4b17023SJohn Marino object_getClass (id object)
154*e4b17023SJohn Marino {
155*e4b17023SJohn Marino   if (object != nil)
156*e4b17023SJohn Marino     return object->class_pointer;
157*e4b17023SJohn Marino   else
158*e4b17023SJohn Marino     return Nil;
159*e4b17023SJohn Marino }
160*e4b17023SJohn Marino 
161*e4b17023SJohn Marino 
162*e4b17023SJohn Marino /** Implementation: the following functions are in selector.c.  */
163*e4b17023SJohn Marino 
164*e4b17023SJohn Marino /* Return the name of a given selector.  If 'selector' is NULL, return
165*e4b17023SJohn Marino    "<null selector>".  */
166*e4b17023SJohn Marino objc_EXPORT const char *sel_getName (SEL selector);
167*e4b17023SJohn Marino 
168*e4b17023SJohn Marino /* Return the type of a given selector.  Return NULL if selector is
169*e4b17023SJohn Marino    NULL.
170*e4b17023SJohn Marino 
171*e4b17023SJohn Marino    Compatibility Note: the Apple/NeXT runtime has untyped selectors,
172*e4b17023SJohn Marino    so it does not have this function, which is specific to the GNU
173*e4b17023SJohn Marino    Runtime.  */
174*e4b17023SJohn Marino objc_EXPORT const char *sel_getTypeEncoding (SEL selector);
175*e4b17023SJohn Marino 
176*e4b17023SJohn Marino /* This is the same as sel_registerName ().  Please use
177*e4b17023SJohn Marino    sel_registerName () instead.  */
178*e4b17023SJohn Marino objc_EXPORT SEL sel_getUid (const char *name);
179*e4b17023SJohn Marino 
180*e4b17023SJohn Marino /* Register a selector with a given name (but unspecified types).  If
181*e4b17023SJohn Marino    you know the types, it is better to call sel_registerTypedName().
182*e4b17023SJohn Marino    If a selector with this name and no types already exists, it is
183*e4b17023SJohn Marino    returned.  Note that this function should really be called
184*e4b17023SJohn Marino    'objc_registerSelector'.  Return NULL if 'name' is NULL.  */
185*e4b17023SJohn Marino objc_EXPORT SEL sel_registerName (const char *name);
186*e4b17023SJohn Marino 
187*e4b17023SJohn Marino /* Register a selector with a given name and types.  If a selector
188*e4b17023SJohn Marino    with this name and types already exists, it is returned.  Note that
189*e4b17023SJohn Marino    this function should really be called 'objc_registerTypedSelector',
190*e4b17023SJohn Marino    and it's called 'sel_registerTypedName' only for consistency with
191*e4b17023SJohn Marino    'sel_registerName'.  Return NULL if 'name' is NULL.
192*e4b17023SJohn Marino 
193*e4b17023SJohn Marino    Compatibility Note: the Apple/NeXT runtime has untyped selectors,
194*e4b17023SJohn Marino    so it does not have this function, which is specific to the GNU
195*e4b17023SJohn Marino    Runtime.  */
196*e4b17023SJohn Marino objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type);
197*e4b17023SJohn Marino 
198*e4b17023SJohn Marino /* Return YES if first_selector is the same as second_selector, and NO
199*e4b17023SJohn Marino    if not.  */
200*e4b17023SJohn Marino objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector);
201*e4b17023SJohn Marino 
202*e4b17023SJohn Marino /* Return all the selectors with the supplied name.  In the GNU
203*e4b17023SJohn Marino    runtime, selectors are typed and there may be multiple selectors
204*e4b17023SJohn Marino    with the same name but a different type.  The return value of the
205*e4b17023SJohn Marino    function is a pointer to an area, allocated with malloc(), that
206*e4b17023SJohn Marino    contains all the selectors with the supplier name known to the
207*e4b17023SJohn Marino    runtime.  The list is terminated by NULL.  Optionally, if you pass
208*e4b17023SJohn Marino    a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int
209*e4b17023SJohn Marino    that it points to will be filled with the number of selectors
210*e4b17023SJohn Marino    returned.
211*e4b17023SJohn Marino 
212*e4b17023SJohn Marino    Compatibility Note: the Apple/NeXT runtime has untyped selectors,
213*e4b17023SJohn Marino    so it does not have this function, which is specific to the GNU
214*e4b17023SJohn Marino    Runtime.  */
215*e4b17023SJohn Marino objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name,
216*e4b17023SJohn Marino 					     unsigned int *numberOfReturnedSelectors);
217*e4b17023SJohn Marino 
218*e4b17023SJohn Marino /* Return a selector with name 'name' and a non-zero type encoding, if
219*e4b17023SJohn Marino    there is a single selector with a type, and with that name,
220*e4b17023SJohn Marino    registered with the runtime.  If there is no such selector, or if
221*e4b17023SJohn Marino    there are multiple selectors with the same name but conflicting
222*e4b17023SJohn Marino    types, NULL is returned.  Return NULL if 'name' is NULL.
223*e4b17023SJohn Marino 
224*e4b17023SJohn Marino    This is useful if you have the name of the selector, and would
225*e4b17023SJohn Marino    really like to get a selector for it that includes the type
226*e4b17023SJohn Marino    encoding.  Unfortunately, if the program contains multiple selector
227*e4b17023SJohn Marino    with the same name but different types, sel_getTypedSelector can
228*e4b17023SJohn Marino    not possibly know which one you need, and so will return NULL.
229*e4b17023SJohn Marino 
230*e4b17023SJohn Marino    Compatibility Note: the Apple/NeXT runtime has untyped selectors,
231*e4b17023SJohn Marino    so it does not have this function, which is specific to the GNU
232*e4b17023SJohn Marino    Runtime.  */
233*e4b17023SJohn Marino objc_EXPORT SEL sel_getTypedSelector (const char *name);
234*e4b17023SJohn Marino 
235*e4b17023SJohn Marino 
236*e4b17023SJohn Marino /** Implementation: the following functions are in objects.c.  */
237*e4b17023SJohn Marino 
238*e4b17023SJohn Marino /* Create an instance of class 'class_', adding extraBytes to the size
239*e4b17023SJohn Marino    of the returned object.  This method allocates the appropriate
240*e4b17023SJohn Marino    amount of memory for the instance, initializes it to zero, then
241*e4b17023SJohn Marino    calls all the C++ constructors on appropriate C++ instance
242*e4b17023SJohn Marino    variables of the instance (if any) (TODO: The C++ constructors bit
243*e4b17023SJohn Marino    is not implemented yet).  */
244*e4b17023SJohn Marino objc_EXPORT id class_createInstance (Class class_, size_t extraBytes);
245*e4b17023SJohn Marino 
246*e4b17023SJohn Marino /* Copy an object and return the copy.  extraBytes should be identical
247*e4b17023SJohn Marino    to the extraBytes parameter that was passed when creating the
248*e4b17023SJohn Marino    original object.  */
249*e4b17023SJohn Marino objc_EXPORT id object_copy (id object, size_t extraBytes);
250*e4b17023SJohn Marino 
251*e4b17023SJohn Marino /* Dispose of an object.  This method calls the appropriate C++
252*e4b17023SJohn Marino    destructors on appropriate C++ instance variables of the instance
253*e4b17023SJohn Marino    (if any) (TODO: This is not implemented yet), then frees the memory
254*e4b17023SJohn Marino    for the instance.  */
255*e4b17023SJohn Marino objc_EXPORT id object_dispose (id object);
256*e4b17023SJohn Marino 
257*e4b17023SJohn Marino /* Return the name of the class of 'object'.  If 'object' is 'nil',
258*e4b17023SJohn Marino    returns "Nil".  */
259*e4b17023SJohn Marino objc_EXPORT const char * object_getClassName (id object);
260*e4b17023SJohn Marino 
261*e4b17023SJohn Marino /* Change the class of object to be class_.  Return the previous class
262*e4b17023SJohn Marino    of object.  This is currently not really thread-safe.  */
263*e4b17023SJohn Marino objc_EXPORT Class object_setClass (id object, Class class_);
264*e4b17023SJohn Marino 
265*e4b17023SJohn Marino 
266*e4b17023SJohn Marino /** Implementation: the following functions are in ivars.c.  */
267*e4b17023SJohn Marino 
268*e4b17023SJohn Marino /* Return an instance variable given the class and the instance
269*e4b17023SJohn Marino    variable name.  This is an expensive function to call, so try to
270*e4b17023SJohn Marino    reuse the returned Ivar if you can.  */
271*e4b17023SJohn Marino objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name);
272*e4b17023SJohn Marino 
273*e4b17023SJohn Marino /* Return a class variable given the class and the class variable
274*e4b17023SJohn Marino    name.  This is an expensive function to call, so try to reuse the
275*e4b17023SJohn Marino    returned Ivar if you can.
276*e4b17023SJohn Marino 
277*e4b17023SJohn Marino    This function always returns NULL since class variables are
278*e4b17023SJohn Marino    currently unavailable in Objective-C.  */
279*e4b17023SJohn Marino objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name);
280*e4b17023SJohn Marino 
281*e4b17023SJohn Marino /* If the object was created in class_createInstance() with some
282*e4b17023SJohn Marino    extraBytes, returns a pointer to them.  If it was not, then the
283*e4b17023SJohn Marino    returned pointer may make no sense.  */
284*e4b17023SJohn Marino objc_EXPORT void * object_getIndexedIvars (id object);
285*e4b17023SJohn Marino 
286*e4b17023SJohn Marino /* Get the value of an instance variable of type 'id'.  The function
287*e4b17023SJohn Marino    returns the instance variable.  To get the value of the instance
288*e4b17023SJohn Marino    variable, you should pass as 'returnValue' a pointer to an 'id';
289*e4b17023SJohn Marino    the value will be copied there.  Note that 'returnValue' is really
290*e4b17023SJohn Marino    a 'void *', not a 'void **'.  This function really works only with
291*e4b17023SJohn Marino    instance variables of type 'id'; for other types of instance
292*e4b17023SJohn Marino    variables, access directly the data at (char *)object +
293*e4b17023SJohn Marino    ivar_getOffset (ivar).  */
294*e4b17023SJohn Marino objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue);
295*e4b17023SJohn Marino 
296*e4b17023SJohn Marino /* Set the value of an instance variable.  The value to set is passed
297*e4b17023SJohn Marino    in 'newValue' (which really is an 'id', not a 'void *').  The
298*e4b17023SJohn Marino    function returns the instance variable.  This function really works
299*e4b17023SJohn Marino    only with instance variables of type 'id'; for other types of
300*e4b17023SJohn Marino    instance variables, access directly the data at (char *)object +
301*e4b17023SJohn Marino    ivar_getOffset (ivar).  */
302*e4b17023SJohn Marino objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue);
303*e4b17023SJohn Marino 
304*e4b17023SJohn Marino /* Get the value of an instance variable of type 'id' of the object
305*e4b17023SJohn Marino    'object'.  This is faster than object_getInstanceVariable if you
306*e4b17023SJohn Marino    already have the instance variable because it avoids the expensive
307*e4b17023SJohn Marino    call to class_getInstanceVariable that is done by
308*e4b17023SJohn Marino    object_getInstanceVariable.  */
309*e4b17023SJohn Marino objc_EXPORT id object_getIvar (id object, Ivar variable);
310*e4b17023SJohn Marino 
311*e4b17023SJohn Marino /* Set the value of an instance variable of type 'id' of the object
312*e4b17023SJohn Marino    'object'.  This is faster than object_setInstanceVariable if you
313*e4b17023SJohn Marino    already have the instance variable because it avoids the expensive
314*e4b17023SJohn Marino    call to class_getInstanceVariable that is done by
315*e4b17023SJohn Marino    object_setInstanceVariable.  */
316*e4b17023SJohn Marino objc_EXPORT void object_setIvar (id object, Ivar variable, id value);
317*e4b17023SJohn Marino 
318*e4b17023SJohn Marino /* Return the name of the instance variable.  Return NULL if
319*e4b17023SJohn Marino    'variable' is NULL.  */
320*e4b17023SJohn Marino objc_EXPORT const char * ivar_getName (Ivar variable);
321*e4b17023SJohn Marino 
322*e4b17023SJohn Marino /* Return the offset of the instance variable from the start of the
323*e4b17023SJohn Marino    object data.  Return 0 if 'variable' is NULL.  */
324*e4b17023SJohn Marino objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable);
325*e4b17023SJohn Marino 
326*e4b17023SJohn Marino /* Return the type encoding of the variable.  Return NULL if
327*e4b17023SJohn Marino    'variable' is NULL.  */
328*e4b17023SJohn Marino objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable);
329*e4b17023SJohn Marino 
330*e4b17023SJohn Marino /* Return all the instance variables of the class.  The return value
331*e4b17023SJohn Marino    of the function is a pointer to an area, allocated with malloc(),
332*e4b17023SJohn Marino    that contains all the instance variables of the class.  It does not
333*e4b17023SJohn Marino    include instance variables of superclasses.  The list is terminated
334*e4b17023SJohn Marino    by NULL.  Optionally, if you pass a non-NULL
335*e4b17023SJohn Marino    'numberOfReturnedIvars' pointer, the unsigned int that it points to
336*e4b17023SJohn Marino    will be filled with the number of instance variables returned.
337*e4b17023SJohn Marino    Return NULL for classes still in construction (ie, allocated using
338*e4b17023SJohn Marino    objc_allocatedClassPair() but not yet registered with the runtime
339*e4b17023SJohn Marino    using objc_registerClassPair()).  */
340*e4b17023SJohn Marino objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars);
341*e4b17023SJohn Marino 
342*e4b17023SJohn Marino /* Add an instance variable with name 'ivar_name' to class 'class_',
343*e4b17023SJohn Marino    where 'class_' is a class in construction that has been created
344*e4b17023SJohn Marino    using objc_allocateClassPair() and has not been registered with the
345*e4b17023SJohn Marino    runtime using objc_registerClassPair() yet.  You can not add
346*e4b17023SJohn Marino    instance variables to classes already registered with the runtime.
347*e4b17023SJohn Marino    'size' is the size of the instance variable, 'log_2_of_alignment'
348*e4b17023SJohn Marino    the alignment as a power of 2 (so 0 means alignment to a 1 byte
349*e4b17023SJohn Marino    boundary, 1 means alignment to a 2 byte boundary, 2 means alignment
350*e4b17023SJohn Marino    to a 4 byte boundary, etc), and 'type' the type encoding of the
351*e4b17023SJohn Marino    variable type.  You can use sizeof(), log2(__alignof__()) and
352*e4b17023SJohn Marino    @encode() to determine the right 'size', 'alignment' and 'type' for
353*e4b17023SJohn Marino    your instance variable.  For example, to add an instance variable
354*e4b17023SJohn Marino    name "my_variable" and of type 'id', you can use:
355*e4b17023SJohn Marino 
356*e4b17023SJohn Marino    class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)),
357*e4b17023SJohn Marino                   @encode (id));
358*e4b17023SJohn Marino 
359*e4b17023SJohn Marino    Return YES if the variable was added, and NO if not.  In
360*e4b17023SJohn Marino    particular, return NO if 'class_' is Nil, or a meta-class or a
361*e4b17023SJohn Marino    class not in construction.  Return Nil also if 'ivar_name' or
362*e4b17023SJohn Marino    'type' is NULL, or 'size' is 0.
363*e4b17023SJohn Marino  */
364*e4b17023SJohn Marino objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size,
365*e4b17023SJohn Marino 				unsigned char log_2_of_alignment, const char *type);
366*e4b17023SJohn Marino 
367*e4b17023SJohn Marino /* Return the name of the property.  Return NULL if 'property' is
368*e4b17023SJohn Marino    NULL.  */
369*e4b17023SJohn Marino objc_EXPORT const char * property_getName (Property property);
370*e4b17023SJohn Marino 
371*e4b17023SJohn Marino /* Return the attributes of the property as a string.  Return NULL if
372*e4b17023SJohn Marino    'property' is NULL.  */
373*e4b17023SJohn Marino objc_EXPORT const char * property_getAttributes (Property property);
374*e4b17023SJohn Marino 
375*e4b17023SJohn Marino /* Return the property with name 'propertyName' of the class 'class_'.
376*e4b17023SJohn Marino    This function returns NULL if the required property can not be
377*e4b17023SJohn Marino    found.  Return NULL if 'class_' or 'propertyName' is NULL.
378*e4b17023SJohn Marino 
379*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of properties
380*e4b17023SJohn Marino    of a class in a compiled module, so the traditional ABI will always
381*e4b17023SJohn Marino    return NULL.  */
382*e4b17023SJohn Marino objc_EXPORT Property class_getProperty (Class class_, const char *propertyName);
383*e4b17023SJohn Marino 
384*e4b17023SJohn Marino /* Return all the properties of the class.  The return value
385*e4b17023SJohn Marino    of the function is a pointer to an area, allocated with malloc(),
386*e4b17023SJohn Marino    that contains all the properties of the class.  It does not
387*e4b17023SJohn Marino    include properties of superclasses.  The list is terminated
388*e4b17023SJohn Marino    by NULL.  Optionally, if you pass a non-NULL
389*e4b17023SJohn Marino    'numberOfReturnedIvars' pointer, the unsigned int that it points to
390*e4b17023SJohn Marino    will be filled with the number of properties returned.
391*e4b17023SJohn Marino 
392*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of properties
393*e4b17023SJohn Marino    of a class in a compiled module, so the traditional ABI will always
394*e4b17023SJohn Marino    return an empty list.  */
395*e4b17023SJohn Marino objc_EXPORT Property * class_copyPropertyList
396*e4b17023SJohn Marino (Class class_, unsigned int *numberOfReturnedProperties);
397*e4b17023SJohn Marino 
398*e4b17023SJohn Marino /* Return the ivar layout for class 'class_'.
399*e4b17023SJohn Marino 
400*e4b17023SJohn Marino    At the moment this function always returns NULL.  */
401*e4b17023SJohn Marino objc_EXPORT const char * class_getIvarLayout (Class class_);
402*e4b17023SJohn Marino 
403*e4b17023SJohn Marino /* Return the weak ivar layout for class 'class_'.
404*e4b17023SJohn Marino 
405*e4b17023SJohn Marino    At the moment this function always returns NULL.  */
406*e4b17023SJohn Marino objc_EXPORT const char * class_getWeakIvarLayout (Class class_);
407*e4b17023SJohn Marino 
408*e4b17023SJohn Marino /* Set the ivar layout for class 'class_'.
409*e4b17023SJohn Marino 
410*e4b17023SJohn Marino    At the moment, this function does nothing.  */
411*e4b17023SJohn Marino objc_EXPORT void class_setIvarLayout (Class class_, const char *layout);
412*e4b17023SJohn Marino 
413*e4b17023SJohn Marino /* Set the weak ivar layout for class 'class_'.
414*e4b17023SJohn Marino 
415*e4b17023SJohn Marino    At the moment, this function does nothing.  With the GNU runtime,
416*e4b17023SJohn Marino    you should use class_ivar_set_gcinvisible () to hide variables from
417*e4b17023SJohn Marino    the Garbage Collector.  */
418*e4b17023SJohn Marino objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout);
419*e4b17023SJohn Marino 
420*e4b17023SJohn Marino 
421*e4b17023SJohn Marino /** Implementation: the following functions are in class.c.  */
422*e4b17023SJohn Marino 
423*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime does not have
424*e4b17023SJohn Marino    objc_get_unknown_class_handler and
425*e4b17023SJohn Marino    objc_setGetUnknownClassHandler().  They provide functionality that
426*e4b17023SJohn Marino    the traditional GNU Objective-C Runtime API used to provide via the
427*e4b17023SJohn Marino    _objc_lookup_class hook.  */
428*e4b17023SJohn Marino 
429*e4b17023SJohn Marino /* An 'objc_get_unknown_class_handler' function is used by
430*e4b17023SJohn Marino    objc_getClass() to get a class that is currently unknown to the
431*e4b17023SJohn Marino    compiler.  You could use it for example to have the class loaded by
432*e4b17023SJohn Marino    dynamically loading a library.  'class_name' is the name of the
433*e4b17023SJohn Marino    class.  The function should return the Class object if it manages to
434*e4b17023SJohn Marino    load the class, and Nil if not.  */
435*e4b17023SJohn Marino typedef Class (*objc_get_unknown_class_handler)(const char *class_name);
436*e4b17023SJohn Marino 
437*e4b17023SJohn Marino /* Sets a new handler function for getting unknown classes (to be used
438*e4b17023SJohn Marino    by objc_getClass () and related), and returns the previous one.
439*e4b17023SJohn Marino    This function is not safe to call in a multi-threaded environment
440*e4b17023SJohn Marino    because other threads may be trying to use the get unknown class
441*e4b17023SJohn Marino    handler while you change it!  */
442*e4b17023SJohn Marino objc_EXPORT
443*e4b17023SJohn Marino objc_get_unknown_class_handler
444*e4b17023SJohn Marino objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler);
445*e4b17023SJohn Marino 
446*e4b17023SJohn Marino /* Return the class with name 'name', if it is already registered with
447*e4b17023SJohn Marino    the runtime.  If it is not registered, and
448*e4b17023SJohn Marino    objc_setGetUnknownClassHandler() has been called to set a handler
449*e4b17023SJohn Marino    for unknown classes, the handler is called to give it a chance to
450*e4b17023SJohn Marino    load the class in some other way.  If the class is not known to the
451*e4b17023SJohn Marino    runtime and the handler is not set or returns Nil, objc_getClass()
452*e4b17023SJohn Marino    returns Nil.  */
453*e4b17023SJohn Marino objc_EXPORT Class objc_getClass (const char *name);
454*e4b17023SJohn Marino 
455*e4b17023SJohn Marino /* Return the class with name 'name', if it is already registered with
456*e4b17023SJohn Marino    the runtime.  Return Nil if not.  This function does not call the
457*e4b17023SJohn Marino    objc_get_unknown_class_handler function if the class is not
458*e4b17023SJohn Marino    found.  */
459*e4b17023SJohn Marino objc_EXPORT Class objc_lookUpClass (const char *name);
460*e4b17023SJohn Marino 
461*e4b17023SJohn Marino /* Return the meta class associated to the class with name 'name', if
462*e4b17023SJohn Marino    it is already registered with the runtime.  First, it finds the
463*e4b17023SJohn Marino    class using objc_getClass().  Then, it returns the associated meta
464*e4b17023SJohn Marino    class.  If the class could not be found using objc_getClass(),
465*e4b17023SJohn Marino    returns Nil.  */
466*e4b17023SJohn Marino objc_EXPORT Class objc_getMetaClass (const char *name);
467*e4b17023SJohn Marino 
468*e4b17023SJohn Marino /* This is identical to objc_getClass(), but if the class is not found,
469*e4b17023SJohn Marino    it aborts the process instead of returning Nil.  */
470*e4b17023SJohn Marino objc_EXPORT Class objc_getRequiredClass (const char *name);
471*e4b17023SJohn Marino 
472*e4b17023SJohn Marino /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of
473*e4b17023SJohn Marino    classes currently registered with the runtime.  If 'returnValue' is
474*e4b17023SJohn Marino    not NULL, it should be a (Class *) pointer to an area of memory
475*e4b17023SJohn Marino    which can contain up to 'maxNumberOfClassesToReturn' Class records.
476*e4b17023SJohn Marino    'objc_getClassList' will fill the area pointed to by 'returnValue'
477*e4b17023SJohn Marino    with all the Classes registered with the runtime (or up to
478*e4b17023SJohn Marino    maxNumberOfClassesToReturn if there are more than
479*e4b17023SJohn Marino    maxNumberOfClassesToReturn).  The function return value is the
480*e4b17023SJohn Marino    number of classes actually returned in 'returnValue'.  */
481*e4b17023SJohn Marino objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn);
482*e4b17023SJohn Marino 
483*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime also has
484*e4b17023SJohn Marino 
485*e4b17023SJohn Marino     Class objc_getFutureClass (const char *name);
486*e4b17023SJohn Marino     void objc_setFutureClass (Class class_, const char *name);
487*e4b17023SJohn Marino 
488*e4b17023SJohn Marino    the documentation is unclear on what they are supposed to do, and
489*e4b17023SJohn Marino    the GNU Objective-C Runtime currently does not provide them.  */
490*e4b17023SJohn Marino 
491*e4b17023SJohn Marino /* Return the name of the class 'class_', or the string "nil" if the
492*e4b17023SJohn Marino    class_ is Nil.  */
493*e4b17023SJohn Marino objc_EXPORT const char * class_getName (Class class_);
494*e4b17023SJohn Marino 
495*e4b17023SJohn Marino /* Return YES if 'class_' is a meta class, and NO if not.  If 'class_'
496*e4b17023SJohn Marino    is Nil, return NO.  */
497*e4b17023SJohn Marino objc_EXPORT BOOL class_isMetaClass (Class class_);
498*e4b17023SJohn Marino 
499*e4b17023SJohn Marino /* Return the superclass of 'class_'.  If 'class_' is Nil, or it is a
500*e4b17023SJohn Marino    root class, return Nil.  This function also works if 'class_' is a
501*e4b17023SJohn Marino    class being constructed, that is, a class returned by
502*e4b17023SJohn Marino    objc_allocateClassPair() but before it has been registered with the
503*e4b17023SJohn Marino    runtime using objc_registerClassPair().  */
504*e4b17023SJohn Marino objc_EXPORT Class class_getSuperclass (Class class_);
505*e4b17023SJohn Marino 
506*e4b17023SJohn Marino /* Return the 'version' number of the class, which is an integer that
507*e4b17023SJohn Marino    can be used to track changes in the class API, methods and
508*e4b17023SJohn Marino    variables.  If class_ is Nil, return 0.  If class_ is not Nil, the
509*e4b17023SJohn Marino    version is 0 unless class_setVersion() has been called to set a
510*e4b17023SJohn Marino    different one.
511*e4b17023SJohn Marino 
512*e4b17023SJohn Marino    Please note that internally the version is a long, but the API only
513*e4b17023SJohn Marino    allows you to set and retrieve int values.  */
514*e4b17023SJohn Marino objc_EXPORT int class_getVersion (Class class_);
515*e4b17023SJohn Marino 
516*e4b17023SJohn Marino /* Set the 'version' number of the class, which is an integer that can
517*e4b17023SJohn Marino    be used to track changes in the class API, methods and variables.
518*e4b17023SJohn Marino    If 'class_' is Nil, does nothing.
519*e4b17023SJohn Marino 
520*e4b17023SJohn Marino    This is typically used internally by "Foundation" libraries such as
521*e4b17023SJohn Marino    GNUstep Base to support serialization / deserialization of objects
522*e4b17023SJohn Marino    that work across changes in the classes.  If you are using such a
523*e4b17023SJohn Marino    library, you probably want to use their versioning API, which may
524*e4b17023SJohn Marino    be based on this one, but is integrated with the rest of the
525*e4b17023SJohn Marino    library.
526*e4b17023SJohn Marino 
527*e4b17023SJohn Marino    Please note that internally the version is a long, but the API only
528*e4b17023SJohn Marino    allows you to set and retrieve int values.  */
529*e4b17023SJohn Marino objc_EXPORT void class_setVersion (Class class_, int version);
530*e4b17023SJohn Marino 
531*e4b17023SJohn Marino /* Return the size in bytes (a byte is the size of a char) of an
532*e4b17023SJohn Marino    instance of the class.  If class_ is Nil, return 0; else it return
533*e4b17023SJohn Marino    a non-zero number (since the 'isa' instance variable is required
534*e4b17023SJohn Marino    for all classes).  */
535*e4b17023SJohn Marino objc_EXPORT size_t class_getInstanceSize (Class class_);
536*e4b17023SJohn Marino 
537*e4b17023SJohn Marino /* Change the implementation of the method.  It also searches all
538*e4b17023SJohn Marino    classes for any class implementing the method, and replaces the
539*e4b17023SJohn Marino    existing implementation with the new one.  For that to work,
540*e4b17023SJohn Marino    'method' must be a method returned by class_getInstanceMethod() or
541*e4b17023SJohn Marino    class_getClassMethod() as the matching is done by comparing the
542*e4b17023SJohn Marino    pointers; in that case, only the implementation in the class is
543*e4b17023SJohn Marino    modified.  Return the previous implementation that has been
544*e4b17023SJohn Marino    replaced.  If method or implementation is NULL, do nothing and
545*e4b17023SJohn Marino    return NULL.  */
546*e4b17023SJohn Marino objc_EXPORT IMP
547*e4b17023SJohn Marino method_setImplementation (Method method, IMP implementation);
548*e4b17023SJohn Marino 
549*e4b17023SJohn Marino /* Swap the implementation of two methods in a single, atomic
550*e4b17023SJohn Marino    operation.  This is equivalent to getting the implementation of
551*e4b17023SJohn Marino    each method and then calling method_setImplementation() on the
552*e4b17023SJohn Marino    other one.  For this to work, the two methods must have been
553*e4b17023SJohn Marino    returned by class_getInstanceMethod() or class_getClassMethod().
554*e4b17023SJohn Marino    If 'method_a' or 'method_b' is NULL, do nothing.  */
555*e4b17023SJohn Marino objc_EXPORT void
556*e4b17023SJohn Marino method_exchangeImplementations (Method method_a, Method method_b);
557*e4b17023SJohn Marino 
558*e4b17023SJohn Marino /* Create a new class/meta-class pair.  This function is called to
559*e4b17023SJohn Marino    create a new class at runtime.  The class is created with
560*e4b17023SJohn Marino    superclass 'superclass' (use 'Nil' to create a new root class) and
561*e4b17023SJohn Marino    name 'class_name'.  'extraBytes' can be used to specify some extra
562*e4b17023SJohn Marino    space for indexed variables to be added at the end of the class and
563*e4b17023SJohn Marino    meta-class objects (it is recommended that you set extraBytes to
564*e4b17023SJohn Marino    0).  Once you have created the class, it is not usable yet.  You
565*e4b17023SJohn Marino    need to add any instance variables (by using class_addIvar()), any
566*e4b17023SJohn Marino    instance methods (by using class_addMethod()) and any class methods
567*e4b17023SJohn Marino    (by using class_addMethod() on the meta-class, as in
568*e4b17023SJohn Marino    class_addMethod (object_getClass (class), method)) that are
569*e4b17023SJohn Marino    required, and then you need to call objc_registerClassPair() to
570*e4b17023SJohn Marino    activate the class.  If you need to create a hierarchy of classes,
571*e4b17023SJohn Marino    you need to create and register them one at a time.  You can not
572*e4b17023SJohn Marino    create a new class using another class in construction as
573*e4b17023SJohn Marino    superclass.  Return Nil if 'class-name' is NULL or if a class with
574*e4b17023SJohn Marino    that name already exists or 'superclass' is a class still in
575*e4b17023SJohn Marino    construction.
576*e4b17023SJohn Marino 
577*e4b17023SJohn Marino    Implementation Note: in the GNU runtime, allocating a class pair
578*e4b17023SJohn Marino    only creates the structures for the class pair, but does not
579*e4b17023SJohn Marino    register anything with the runtime.  The class is registered with
580*e4b17023SJohn Marino    the runtime only when objc_registerClassPair() is called.  In
581*e4b17023SJohn Marino    particular, if a class is in construction, objc_getClass() will not
582*e4b17023SJohn Marino    find it, the superclass will not know about it,
583*e4b17023SJohn Marino    class_getSuperclass() will return Nil and another thread may
584*e4b17023SJohn Marino    allocate a class pair with the same name; the conflict will only be
585*e4b17023SJohn Marino    detected when the classes are registered with the runtime.
586*e4b17023SJohn Marino  */
587*e4b17023SJohn Marino objc_EXPORT Class
588*e4b17023SJohn Marino objc_allocateClassPair (Class super_class, const char *class_name,
589*e4b17023SJohn Marino 			size_t extraBytes);
590*e4b17023SJohn Marino 
591*e4b17023SJohn Marino /* Register a class pair that was created with
592*e4b17023SJohn Marino    objc_allocateClassPair().  After you register a class, you can no
593*e4b17023SJohn Marino    longer make changes to its instance variables, but you can start
594*e4b17023SJohn Marino    creating instances of it.  Do nothing if 'class_' is NULL or if it
595*e4b17023SJohn Marino    is not a class allocated by objc_allocateClassPair() and still in
596*e4b17023SJohn Marino    construction.  */
597*e4b17023SJohn Marino objc_EXPORT void
598*e4b17023SJohn Marino objc_registerClassPair (Class class_);
599*e4b17023SJohn Marino 
600*e4b17023SJohn Marino /* Dispose of a class pair created using objc_allocateClassPair().
601*e4b17023SJohn Marino    Call this function if you started creating a new class with
602*e4b17023SJohn Marino    objc_allocateClassPair() but then want to abort the process.  You
603*e4b17023SJohn Marino    should not access 'class_' after calling this method.  Note that if
604*e4b17023SJohn Marino    'class_' has already been registered with the runtime via
605*e4b17023SJohn Marino    objc_registerClassPair(), this function does nothing; you can only
606*e4b17023SJohn Marino    dispose of class pairs that are still being constructed.  Do
607*e4b17023SJohn Marino    nothing if class is 'Nil' or if 'class_' is not a class being
608*e4b17023SJohn Marino    constructed.  */
609*e4b17023SJohn Marino objc_EXPORT void
610*e4b17023SJohn Marino objc_disposeClassPair (Class class_);
611*e4b17023SJohn Marino 
612*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime has the function
613*e4b17023SJohn Marino    objc_duplicateClass () but it's undocumented.  The GNU runtime does
614*e4b17023SJohn Marino    not have it.  */
615*e4b17023SJohn Marino 
616*e4b17023SJohn Marino 
617*e4b17023SJohn Marino /** Implementation: the following functions are in sendmsg.c.  */
618*e4b17023SJohn Marino 
619*e4b17023SJohn Marino /* Return the instance method with selector 'selector' of class
620*e4b17023SJohn Marino    'class_', or NULL if the class (or one of its superclasses) does
621*e4b17023SJohn Marino    not implement the method.  Return NULL if class_ is Nil or selector
622*e4b17023SJohn Marino    is NULL.  Calling this function may trigger a call to
623*e4b17023SJohn Marino    +resolveInstanceMethod:, but does not return a forwarding
624*e4b17023SJohn Marino    function.  */
625*e4b17023SJohn Marino objc_EXPORT Method class_getInstanceMethod (Class class_, SEL selector);
626*e4b17023SJohn Marino 
627*e4b17023SJohn Marino /* Return the class method with selector 'selector' of class 'class_',
628*e4b17023SJohn Marino    or NULL if the class (or one of its superclasses) does not
629*e4b17023SJohn Marino    implement the method.  Return NULL if class_ is Nil or selector is
630*e4b17023SJohn Marino    NULL.  Calling this function may trigger a call to
631*e4b17023SJohn Marino    +resolveClassMethod:, but does not return a forwarding
632*e4b17023SJohn Marino    function.  */
633*e4b17023SJohn Marino objc_EXPORT Method class_getClassMethod (Class class_, SEL selector);
634*e4b17023SJohn Marino 
635*e4b17023SJohn Marino /* Return the IMP (pointer to the function implementing a method) for
636*e4b17023SJohn Marino    the instance method with selector 'selector' in class 'class_'.
637*e4b17023SJohn Marino    This is the same routine that is used while messaging, and should
638*e4b17023SJohn Marino    be very fast.  Note that you most likely would need to cast the
639*e4b17023SJohn Marino    return function pointer to a function pointer with the appropriate
640*e4b17023SJohn Marino    arguments and return type before calling it.  To get a class
641*e4b17023SJohn Marino    method, you can pass the meta-class as the class_ argument (ie, use
642*e4b17023SJohn Marino    class_getMethodImplementation (object_getClass (class_),
643*e4b17023SJohn Marino    selector)).  Return NULL if class_ is Nil or selector is NULL.
644*e4b17023SJohn Marino    This function first looks for an existing method; if it is not
645*e4b17023SJohn Marino    found, it calls +resolveClassMethod: or +resolveInstanceMethod:
646*e4b17023SJohn Marino    (depending on whether a class or instance method is being looked
647*e4b17023SJohn Marino    up) if it is implemented.  If the method returns YES, then it tries
648*e4b17023SJohn Marino    the look up again (the assumption being that +resolveClassMethod:
649*e4b17023SJohn Marino    or resolveInstanceMethod: will add the method using
650*e4b17023SJohn Marino    class_addMethod()).  If it is still not found, it returns a
651*e4b17023SJohn Marino    forwarding function.  */
652*e4b17023SJohn Marino objc_EXPORT IMP class_getMethodImplementation (Class class_, SEL selector);
653*e4b17023SJohn Marino 
654*e4b17023SJohn Marino /* Compatibility Note: the Apple/NeXT runtime has the function
655*e4b17023SJohn Marino    class_getMethodImplementation_stret () which currently does not
656*e4b17023SJohn Marino    exist on the GNU runtime because the messaging implementation is
657*e4b17023SJohn Marino    different.  */
658*e4b17023SJohn Marino 
659*e4b17023SJohn Marino /* Return YES if class 'class_' has an instance method implementing
660*e4b17023SJohn Marino    selector 'selector', and NO if not.  Return NO if class_ is Nil or
661*e4b17023SJohn Marino    selector is NULL.  If you need to check a class method, use the
662*e4b17023SJohn Marino    meta-class as the class_ argument (ie, use class_respondsToSelector
663*e4b17023SJohn Marino    (object_getClass (class_), selector)).  */
664*e4b17023SJohn Marino objc_EXPORT BOOL class_respondsToSelector (Class class_, SEL selector);
665*e4b17023SJohn Marino 
666*e4b17023SJohn Marino /* Add a method to a class.  Use this function to add a new method to
667*e4b17023SJohn Marino    a class (potentially overriding a method with the same selector in
668*e4b17023SJohn Marino    the superclass); if you want to modify an existing method, use
669*e4b17023SJohn Marino    method_setImplementation() instead (or class_replaceMethod ()).
670*e4b17023SJohn Marino    This method adds an instance method to 'class_'; to add a class
671*e4b17023SJohn Marino    method, get the meta class first, then add the method to the meta
672*e4b17023SJohn Marino    class, that is, use
673*e4b17023SJohn Marino 
674*e4b17023SJohn Marino    class_addMethod (object_getClass (class_), selector,
675*e4b17023SJohn Marino    implementation, type);
676*e4b17023SJohn Marino 
677*e4b17023SJohn Marino    Return YES if the method was added, and NO if not.  Do nothing if
678*e4b17023SJohn Marino    one of the arguments is NULL.  */
679*e4b17023SJohn Marino objc_EXPORT BOOL class_addMethod (Class class_, SEL selector, IMP implementation,
680*e4b17023SJohn Marino 				  const char *method_types);
681*e4b17023SJohn Marino 
682*e4b17023SJohn Marino /* Replace a method in a class.  If the class already have a method
683*e4b17023SJohn Marino    with this 'selector', find it and use method_setImplementation() to
684*e4b17023SJohn Marino    replace the implementation with 'implementation' (method_types is
685*e4b17023SJohn Marino    ignored in that case).  If the class does not already have a method
686*e4b17023SJohn Marino    with this 'selector', call 'class_addMethod() to add it.
687*e4b17023SJohn Marino 
688*e4b17023SJohn Marino    Return the previous implementation of the method, or NULL if none
689*e4b17023SJohn Marino    was found.  Return NULL if any of the arguments is NULL.  */
690*e4b17023SJohn Marino objc_EXPORT IMP class_replaceMethod (Class class_, SEL selector, IMP implementation,
691*e4b17023SJohn Marino 				     const char *method_types);
692*e4b17023SJohn Marino 
693*e4b17023SJohn Marino 
694*e4b17023SJohn Marino /** Implementation: the following functions are in methods.c.  */
695*e4b17023SJohn Marino 
696*e4b17023SJohn Marino /* Return the selector for method 'method'.  Return NULL if 'method'
697*e4b17023SJohn Marino    is NULL.
698*e4b17023SJohn Marino 
699*e4b17023SJohn Marino    This function is misnamed; it should be called
700*e4b17023SJohn Marino    'method_getSelector'.  To get the actual name, get the selector,
701*e4b17023SJohn Marino    then the name from the selector (ie, use sel_getName
702*e4b17023SJohn Marino    (method_getName (method))).  */
703*e4b17023SJohn Marino objc_EXPORT SEL method_getName (Method method);
704*e4b17023SJohn Marino 
705*e4b17023SJohn Marino /* Return the IMP of the method.  Return NULL if 'method' is NULL.  */
706*e4b17023SJohn Marino objc_EXPORT IMP method_getImplementation (Method method);
707*e4b17023SJohn Marino 
708*e4b17023SJohn Marino /* Return the type encoding of the method.  Return NULL if 'method' is
709*e4b17023SJohn Marino    NULL.  */
710*e4b17023SJohn Marino objc_EXPORT const char * method_getTypeEncoding (Method method);
711*e4b17023SJohn Marino 
712*e4b17023SJohn Marino /* Return a method description for the method.  Return NULL if
713*e4b17023SJohn Marino    'method' is NULL.  */
714*e4b17023SJohn Marino objc_EXPORT struct objc_method_description * method_getDescription (Method method);
715*e4b17023SJohn Marino 
716*e4b17023SJohn Marino /* Return all the instance methods of the class.  The return value of
717*e4b17023SJohn Marino    the function is a pointer to an area, allocated with malloc(), that
718*e4b17023SJohn Marino    contains all the instance methods of the class.  It does not
719*e4b17023SJohn Marino    include instance methods of superclasses.  The list is terminated
720*e4b17023SJohn Marino    by NULL.  Optionally, if you pass a non-NULL
721*e4b17023SJohn Marino    'numberOfReturnedMethods' pointer, the unsigned int that it points
722*e4b17023SJohn Marino    to will be filled with the number of instance methods returned.  To
723*e4b17023SJohn Marino    get the list of class methods, pass the meta-class in the 'class_'
724*e4b17023SJohn Marino    argument, (ie, use class_copyMethodList (object_getClass (class_),
725*e4b17023SJohn Marino    &numberOfReturnedMethods)).  */
726*e4b17023SJohn Marino objc_EXPORT Method * class_copyMethodList (Class class_, unsigned int *numberOfReturnedMethods);
727*e4b17023SJohn Marino 
728*e4b17023SJohn Marino 
729*e4b17023SJohn Marino /** Implementation: the following functions are in encoding.c.  */
730*e4b17023SJohn Marino 
731*e4b17023SJohn Marino /* Return the number of arguments that the method 'method' expects.
732*e4b17023SJohn Marino    Note that all methods need two implicit arguments ('self' for the
733*e4b17023SJohn Marino    receiver, and '_cmd' for the selector).  Return 0 if 'method' is
734*e4b17023SJohn Marino    NULL.  */
735*e4b17023SJohn Marino objc_EXPORT unsigned int method_getNumberOfArguments (Method method);
736*e4b17023SJohn Marino 
737*e4b17023SJohn Marino /* Return the string encoding for the return type of method 'method'.
738*e4b17023SJohn Marino    The string is a standard zero-terminated string in an area of
739*e4b17023SJohn Marino    memory allocated with malloc(); you should free it with free() when
740*e4b17023SJohn Marino    you finish using it.  Return an empty string if method is NULL.  */
741*e4b17023SJohn Marino objc_EXPORT char * method_copyReturnType (Method method);
742*e4b17023SJohn Marino 
743*e4b17023SJohn Marino /* Return the string encoding for the argument type of method
744*e4b17023SJohn Marino    'method', argument number 'argumentNumber' ('argumentNumber' is 0
745*e4b17023SJohn Marino    for self, 1 for _cmd, and 2 or more for the additional arguments if
746*e4b17023SJohn Marino    any).  The string is a standard zero-terminated string in an area
747*e4b17023SJohn Marino    of memory allocated with malloc(); you should free it with free()
748*e4b17023SJohn Marino    when you finish using it.  Return an empty string if method is NULL
749*e4b17023SJohn Marino    or if 'argumentNumber' refers to a non-existing argument.  */
750*e4b17023SJohn Marino objc_EXPORT char * method_copyArgumentType (Method method, unsigned int argumentNumber);
751*e4b17023SJohn Marino 
752*e4b17023SJohn Marino /* Return the string encoding for the return type of method 'method'.
753*e4b17023SJohn Marino    The string is returned by copying it into the supplied
754*e4b17023SJohn Marino    'returnValue' string, which is of size 'returnValueSize'.  No more
755*e4b17023SJohn Marino    than 'returnValueSize' characters are copied; if the encoding is
756*e4b17023SJohn Marino    smaller than 'returnValueSize', the rest of 'returnValue' is filled
757*e4b17023SJohn Marino    with zeros.  If it is bigger, it is truncated (and would not be
758*e4b17023SJohn Marino    zero-terminated).  You should supply a big enough
759*e4b17023SJohn Marino    'returnValueSize'.  If the method is NULL, returnValue is set to a
760*e4b17023SJohn Marino    string of zeros.  */
761*e4b17023SJohn Marino objc_EXPORT void method_getReturnType (Method method, char *returnValue,
762*e4b17023SJohn Marino 				       size_t returnValueSize);
763*e4b17023SJohn Marino 
764*e4b17023SJohn Marino /* Return the string encoding for the argument type of method
765*e4b17023SJohn Marino    'method', argument number 'argumentNumber' ('argumentNumber' is 0
766*e4b17023SJohn Marino    for self, 1 for _cmd, and 2 or more for the additional arguments if
767*e4b17023SJohn Marino    any).  The string is returned by copying it into the supplied
768*e4b17023SJohn Marino    'returnValue' string, which is of size 'returnValueSize'.  No more
769*e4b17023SJohn Marino    than 'returnValueSize' characters are copied; if the encoding is
770*e4b17023SJohn Marino    smaller than 'returnValueSize', the rest of 'returnValue' is filled
771*e4b17023SJohn Marino    with zeros.  If it is bigger, it is truncated (and would not be
772*e4b17023SJohn Marino    zero-terminated).  You should supply a big enough
773*e4b17023SJohn Marino    'returnValueSize'.  If the method is NULL, returnValue is set to a
774*e4b17023SJohn Marino    string of zeros.  */
775*e4b17023SJohn Marino objc_EXPORT void method_getArgumentType (Method method, unsigned int argumentNumber,
776*e4b17023SJohn Marino 					 char *returnValue, size_t returnValueSize);
777*e4b17023SJohn Marino 
778*e4b17023SJohn Marino 
779*e4b17023SJohn Marino /** Implementation: the following functions are in protocols.c.  */
780*e4b17023SJohn Marino 
781*e4b17023SJohn Marino /* Return the protocol with name 'name', or nil if it the protocol is
782*e4b17023SJohn Marino    not known to the runtime.  */
783*e4b17023SJohn Marino objc_EXPORT Protocol *objc_getProtocol (const char *name);
784*e4b17023SJohn Marino 
785*e4b17023SJohn Marino /* Return all the protocols known to the runtime.  The return value of
786*e4b17023SJohn Marino    the function is a pointer to an area, allocated with malloc(), that
787*e4b17023SJohn Marino    contains all the protocols known to the runtime; the list is
788*e4b17023SJohn Marino    terminated by NULL.  You should free this area using free() once
789*e4b17023SJohn Marino    you no longer need it.  Optionally, if you pass a non-NULL
790*e4b17023SJohn Marino    'numberOfReturnedProtocols' pointer, the unsigned int that it
791*e4b17023SJohn Marino    points to will be filled with the number of protocols returned.  If
792*e4b17023SJohn Marino    there are no protocols known to the runtime, NULL is returned.  */
793*e4b17023SJohn Marino objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProtocols);
794*e4b17023SJohn Marino 
795*e4b17023SJohn Marino /* Add a protocol to a class, and return YES if it was done
796*e4b17023SJohn Marino    succesfully, and NO if not.  At the moment, NO should only happen
797*e4b17023SJohn Marino    if class_ or protocol are nil, if the protocol is not a Protocol
798*e4b17023SJohn Marino    object or if the class already conforms to the protocol.  */
799*e4b17023SJohn Marino objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol);
800*e4b17023SJohn Marino 
801*e4b17023SJohn Marino /* Return YES if the class 'class_' conforms to Protocol 'protocol',
802*e4b17023SJohn Marino    and NO if not.  This function does not check superclasses; if you
803*e4b17023SJohn Marino    want to check for superclasses (in the way that [NSObject
804*e4b17023SJohn Marino    +conformsToProtocol:] does) you need to iterate over the class
805*e4b17023SJohn Marino    hierarchy using class_getSuperclass(), and call
806*e4b17023SJohn Marino    class_conformsToProtocol() for each of them.  */
807*e4b17023SJohn Marino objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol);
808*e4b17023SJohn Marino 
809*e4b17023SJohn Marino /* Return all the protocols that the class conforms to.  The return
810*e4b17023SJohn Marino    value of the function is a pointer to an area, allocated with
811*e4b17023SJohn Marino    malloc(), that contains all the protocols formally adopted by the
812*e4b17023SJohn Marino    class.  It does not include protocols adopted by superclasses.  The
813*e4b17023SJohn Marino    list is terminated by NULL.  Optionally, if you pass a non-NULL
814*e4b17023SJohn Marino    'numberOfReturnedProtocols' pointer, the unsigned int that it
815*e4b17023SJohn Marino    points to will be filled with the number of protocols returned.
816*e4b17023SJohn Marino    This function does not return protocols that superclasses conform
817*e4b17023SJohn Marino    to.  */
818*e4b17023SJohn Marino objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols);
819*e4b17023SJohn Marino 
820*e4b17023SJohn Marino /* Return YES if protocol 'protocol' conforms to protocol
821*e4b17023SJohn Marino    'anotherProtocol', and NO if not.  Note that if one of the two
822*e4b17023SJohn Marino    protocols is nil, it returns NO.  */
823*e4b17023SJohn Marino objc_EXPORT BOOL protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol);
824*e4b17023SJohn Marino 
825*e4b17023SJohn Marino /* Return YES if protocol 'protocol' is the same as protocol
826*e4b17023SJohn Marino    'anotherProtocol', and 'NO' if not.  Note that it returns YES if
827*e4b17023SJohn Marino    the two protocols are both nil.  */
828*e4b17023SJohn Marino objc_EXPORT BOOL protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol);
829*e4b17023SJohn Marino 
830*e4b17023SJohn Marino /* Return the name of protocol 'protocol'.  If 'protocol' is nil or is
831*e4b17023SJohn Marino    not a Protocol, return NULL.  */
832*e4b17023SJohn Marino objc_EXPORT const char *protocol_getName (Protocol *protocol);
833*e4b17023SJohn Marino 
834*e4b17023SJohn Marino /* Return the method description for the method with selector
835*e4b17023SJohn Marino    'selector' in protocol 'protocol'; if 'requiredMethod' is YES, the
836*e4b17023SJohn Marino    function searches the list of required methods; if NO, the list of
837*e4b17023SJohn Marino    optional methods.  If 'instanceMethod' is YES, the function search
838*e4b17023SJohn Marino    for an instance method; if NO, for a class method.  If there is no
839*e4b17023SJohn Marino    matching method, an objc_method_description structure with both
840*e4b17023SJohn Marino    name and types set to NULL is returned.  This function will only
841*e4b17023SJohn Marino    find methods that are directly declared in the protocol itself, not
842*e4b17023SJohn Marino    in other protocols that this protocol adopts.
843*e4b17023SJohn Marino 
844*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of optional
845*e4b17023SJohn Marino    methods of a protocol in a compiled module, so the traditional ABI
846*e4b17023SJohn Marino    will always return (NULL, NULL) when requiredMethod == NO.  */
847*e4b17023SJohn Marino objc_EXPORT struct objc_method_description protocol_getMethodDescription (Protocol *protocol,
848*e4b17023SJohn Marino 									  SEL selector,
849*e4b17023SJohn Marino 									  BOOL requiredMethod,
850*e4b17023SJohn Marino 									  BOOL instanceMethod);
851*e4b17023SJohn Marino 
852*e4b17023SJohn Marino /* Return the method descriptions of all the methods of the protocol.
853*e4b17023SJohn Marino    The return value of the function is a pointer to an area, allocated
854*e4b17023SJohn Marino    with malloc(), that contains all the method descriptions of the
855*e4b17023SJohn Marino    methods of the protocol.  It does not recursively include methods
856*e4b17023SJohn Marino    of the protocols adopted by this protocol.  The list is terminated
857*e4b17023SJohn Marino    by a NULL objc_method_description (one with both fields set to
858*e4b17023SJohn Marino    NULL).  Optionally, if you pass a non-NULL
859*e4b17023SJohn Marino    'numberOfReturnedMethods' pointer, the unsigned int that it points
860*e4b17023SJohn Marino    to will be filled with the number of properties returned.
861*e4b17023SJohn Marino 
862*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of optional
863*e4b17023SJohn Marino    methods of a protocol in a compiled module, so the traditional ABI
864*e4b17023SJohn Marino    will always return an empty list if requiredMethod is set to
865*e4b17023SJohn Marino    NO.  */
866*e4b17023SJohn Marino objc_EXPORT struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *protocol,
867*e4b17023SJohn Marino 										BOOL requiredMethod,
868*e4b17023SJohn Marino 										BOOL instanceMethod,
869*e4b17023SJohn Marino 										unsigned int *numberOfReturnedMethods);
870*e4b17023SJohn Marino 
871*e4b17023SJohn Marino /* Return the property with name 'propertyName' of the protocol
872*e4b17023SJohn Marino    'protocol'.  If 'requiredProperty' is YES, the function searches
873*e4b17023SJohn Marino    the list of required properties; if NO, the list of optional
874*e4b17023SJohn Marino    properties.  If 'instanceProperty' is YES, the function searches
875*e4b17023SJohn Marino    the list of instance properties; if NO, the list of class
876*e4b17023SJohn Marino    properties.  At the moment, optional properties and class
877*e4b17023SJohn Marino    properties are not part of the Objective-C language, so both
878*e4b17023SJohn Marino    'requiredProperty' and 'instanceProperty' should be set to YES.
879*e4b17023SJohn Marino    This function returns NULL if the required property can not be
880*e4b17023SJohn Marino    found.
881*e4b17023SJohn Marino 
882*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of properties
883*e4b17023SJohn Marino    of a protocol in a compiled module, so the traditional ABI will
884*e4b17023SJohn Marino    always return NULL.  */
885*e4b17023SJohn Marino objc_EXPORT Property protocol_getProperty (Protocol *protocol, const char *propertyName,
886*e4b17023SJohn Marino 					   BOOL requiredProperty, BOOL instanceProperty);
887*e4b17023SJohn Marino 
888*e4b17023SJohn Marino /* Return all the properties of the protocol.  The return value of the
889*e4b17023SJohn Marino    function is a pointer to an area, allocated with malloc(), that
890*e4b17023SJohn Marino    contains all the properties of the protocol.  It does not
891*e4b17023SJohn Marino    recursively include properties of the protocols adopted by this
892*e4b17023SJohn Marino    protocol.  The list is terminated by NULL.  Optionally, if you pass
893*e4b17023SJohn Marino    a non-NULL 'numberOfReturnedProperties' pointer, the unsigned int
894*e4b17023SJohn Marino    that it points to will be filled with the number of properties
895*e4b17023SJohn Marino    returned.
896*e4b17023SJohn Marino 
897*e4b17023SJohn Marino    Note that the traditional ABI does not store the list of properties
898*e4b17023SJohn Marino    of a protocol in a compiled module, so the traditional ABI will
899*e4b17023SJohn Marino    always return NULL and store 0 in numberOfReturnedProperties.  */
900*e4b17023SJohn Marino objc_EXPORT Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfReturnedProperties);
901*e4b17023SJohn Marino 
902*e4b17023SJohn Marino /* Return all the protocols that the protocol conforms to.  The return
903*e4b17023SJohn Marino    value of the function is a pointer to an area, allocated with
904*e4b17023SJohn Marino    malloc(), that contains all the protocols formally adopted by the
905*e4b17023SJohn Marino    protocol.  It does not recursively include protocols adopted by the
906*e4b17023SJohn Marino    protocols adopted by this protocol.  The list is terminated by
907*e4b17023SJohn Marino    NULL.  Optionally, if you pass a non-NULL
908*e4b17023SJohn Marino    'numberOfReturnedProtocols' pointer, the unsigned int that it
909*e4b17023SJohn Marino    points to will be filled with the number of protocols returned.  */
910*e4b17023SJohn Marino objc_EXPORT Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOfReturnedProtocols);
911*e4b17023SJohn Marino 
912*e4b17023SJohn Marino 
913*e4b17023SJohn Marino /** Implementation: the following hook is in init.c.  */
914*e4b17023SJohn Marino 
915*e4b17023SJohn Marino /* This is a hook which is called by __objc_exec_class every time a
916*e4b17023SJohn Marino    class or a category is loaded into the runtime.  This may e.g. help
917*e4b17023SJohn Marino    a dynamic loader determine the classes that have been loaded when
918*e4b17023SJohn Marino    an object file is dynamically linked in.  */
919*e4b17023SJohn Marino objc_EXPORT void (*_objc_load_callback)(Class _class, struct objc_category *category);
920*e4b17023SJohn Marino 
921*e4b17023SJohn Marino 
922*e4b17023SJohn Marino /** Implementation: the following functions are in objc-foreach.c.  */
923*e4b17023SJohn Marino 
924*e4b17023SJohn Marino /* 'objc_enumerationMutation()' is called when a collection is
925*e4b17023SJohn Marino    mutated while being "fast enumerated".  That is a hard error, and
926*e4b17023SJohn Marino    objc_enumerationMutation is called to deal with it.  'collection'
927*e4b17023SJohn Marino    is the collection object that was mutated during an enumeration.
928*e4b17023SJohn Marino 
929*e4b17023SJohn Marino    objc_enumerationMutation() will invoke the mutation handler if any
930*e4b17023SJohn Marino    is set.  Then, it will abort the program.
931*e4b17023SJohn Marino 
932*e4b17023SJohn Marino    Compatibility note: the Apple runtime will not abort the program
933*e4b17023SJohn Marino    after calling the mutation handler.  */
934*e4b17023SJohn Marino objc_EXPORT void objc_enumerationMutation (id collection);
935*e4b17023SJohn Marino 
936*e4b17023SJohn Marino /* 'objc_set_enumeration_mutation_handler' can be used to set a
937*e4b17023SJohn Marino    function that will be called (instead of aborting) when a fast
938*e4b17023SJohn Marino    enumeration is mutated during enumeration.  The handler will be
939*e4b17023SJohn Marino    called with the 'collection' being mutated as the only argument and
940*e4b17023SJohn Marino    it should not return; it should either exit the program, or could
941*e4b17023SJohn Marino    throw an exception.  The recommended implementation is to throw an
942*e4b17023SJohn Marino    exception - the user can then use exception handlers to deal with
943*e4b17023SJohn Marino    it.
944*e4b17023SJohn Marino 
945*e4b17023SJohn Marino    This function is not thread safe (other threads may be trying to
946*e4b17023SJohn Marino    invoke the enumeration mutation handler while you are changing it!)
947*e4b17023SJohn Marino    and should be called during during the program initialization
948*e4b17023SJohn Marino    before threads are started.  It is mostly reserved for "Foundation"
949*e4b17023SJohn Marino    libraries; in the case of GNUstep, GNUstep Base may be using this
950*e4b17023SJohn Marino    function to improve the standard enumeration mutation handling.
951*e4b17023SJohn Marino    You probably shouldn't use this function unless you are writing
952*e4b17023SJohn Marino    your own Foundation library.  */
953*e4b17023SJohn Marino objc_EXPORT void objc_setEnumerationMutationHandler (void (*handler)(id));
954*e4b17023SJohn Marino 
955*e4b17023SJohn Marino /* This structure (used during fast enumeration) is automatically
956*e4b17023SJohn Marino    defined by the compiler (it is as if this definition was always
957*e4b17023SJohn Marino    included in all Objective-C files).  Note that it is usually
958*e4b17023SJohn Marino    defined again with the name of NSFastEnumeration by "Foundation"
959*e4b17023SJohn Marino    libraries such as GNUstep Base.  And if NSFastEnumeration is
960*e4b17023SJohn Marino    defined, the compiler will use it instead of
961*e4b17023SJohn Marino    __objcFastEnumerationState when doing fast enumeration.  */
962*e4b17023SJohn Marino /*
963*e4b17023SJohn Marino struct __objcFastEnumerationState
964*e4b17023SJohn Marino {
965*e4b17023SJohn Marino   unsigned long state;
966*e4b17023SJohn Marino   id            *itemsPtr;
967*e4b17023SJohn Marino   unsigned long *mutationsPtr;
968*e4b17023SJohn Marino   unsigned long extra[5];
969*e4b17023SJohn Marino };
970*e4b17023SJohn Marino */
971*e4b17023SJohn Marino 
972*e4b17023SJohn Marino 
973*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime has the functions
974*e4b17023SJohn Marino    objc_copyImageNames (), class_getImageName () and
975*e4b17023SJohn Marino    objc_copyClassNamesForImage () but they are undocumented.  The GNU
976*e4b17023SJohn Marino    runtime does not have them at the moment.  */
977*e4b17023SJohn Marino 
978*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime has the functions
979*e4b17023SJohn Marino    objc_setAssociatedObject (), objc_getAssociatedObject (),
980*e4b17023SJohn Marino    objc_removeAssociatedObjects () and the objc_AssociationPolicy type
981*e4b17023SJohn Marino    and related enum.  The GNU runtime does not have them yet.
982*e4b17023SJohn Marino    TODO: Implement them.  */
983*e4b17023SJohn Marino 
984*e4b17023SJohn Marino /* Compatibility Note: The Apple/NeXT runtime has the function
985*e4b17023SJohn Marino    objc_setForwardHandler ().  The GNU runtime does not have it
986*e4b17023SJohn Marino    because messaging (and, in particular, forwarding) works in a
987*e4b17023SJohn Marino    different (incompatible) way with the GNU runtime.  If you need to
988*e4b17023SJohn Marino    customize message forwarding at the Objective-C runtime level (that
989*e4b17023SJohn Marino    is, if you are implementing your own "Foundation" library such as
990*e4b17023SJohn Marino    GNUstep Base on top of the Objective-C runtime), in objc/message.h
991*e4b17023SJohn Marino    there are hooks (that work in the framework of the GNU runtime) to
992*e4b17023SJohn Marino    do so.  */
993*e4b17023SJohn Marino 
994*e4b17023SJohn Marino 
995*e4b17023SJohn Marino /** Implementation: the following functions are in memory.c.  */
996*e4b17023SJohn Marino 
997*e4b17023SJohn Marino /* Traditional GNU Objective-C Runtime functions that are used for
998*e4b17023SJohn Marino    memory allocation and disposal.  These functions are used in the
999*e4b17023SJohn Marino    same way as you use malloc, realloc, calloc and free and make sure
1000*e4b17023SJohn Marino    that memory allocation works properly with the garbage
1001*e4b17023SJohn Marino    collector.
1002*e4b17023SJohn Marino 
1003*e4b17023SJohn Marino    Compatibility Note: these functions are not available with the
1004*e4b17023SJohn Marino    Apple/NeXT runtime.  */
1005*e4b17023SJohn Marino 
1006*e4b17023SJohn Marino objc_EXPORT void *objc_malloc(size_t size);
1007*e4b17023SJohn Marino 
1008*e4b17023SJohn Marino /* FIXME: Shouldn't the following be called objc_malloc_atomic ?  The
1009*e4b17023SJohn Marino    GC function is GC_malloc_atomic() which makes sense.
1010*e4b17023SJohn Marino  */
1011*e4b17023SJohn Marino objc_EXPORT void *objc_atomic_malloc(size_t size);
1012*e4b17023SJohn Marino 
1013*e4b17023SJohn Marino objc_EXPORT void *objc_realloc(void *mem, size_t size);
1014*e4b17023SJohn Marino 
1015*e4b17023SJohn Marino objc_EXPORT void *objc_calloc(size_t nelem, size_t size);
1016*e4b17023SJohn Marino 
1017*e4b17023SJohn Marino objc_EXPORT void objc_free(void *mem);
1018*e4b17023SJohn Marino 
1019*e4b17023SJohn Marino 
1020*e4b17023SJohn Marino /** Implementation: the following functions are in gc.c.  */
1021*e4b17023SJohn Marino 
1022*e4b17023SJohn Marino /* The GNU Objective-C Runtime has a different implementation of
1023*e4b17023SJohn Marino    garbage collection.
1024*e4b17023SJohn Marino 
1025*e4b17023SJohn Marino    Compatibility Note: these functions are not available with the
1026*e4b17023SJohn Marino    Apple/NeXT runtime.  */
1027*e4b17023SJohn Marino 
1028*e4b17023SJohn Marino /* Mark the instance variable as inaccessible to the garbage
1029*e4b17023SJohn Marino    collector.  */
1030*e4b17023SJohn Marino objc_EXPORT void class_ivar_set_gcinvisible (Class _class,
1031*e4b17023SJohn Marino 					     const char* ivarname,
1032*e4b17023SJohn Marino 					     BOOL gcInvisible);
1033*e4b17023SJohn Marino 
1034*e4b17023SJohn Marino 
1035*e4b17023SJohn Marino /** Implementation: the following functions are in encoding.c.  */
1036*e4b17023SJohn Marino 
1037*e4b17023SJohn Marino /* Traditional GNU Objective-C Runtime functions that are currently
1038*e4b17023SJohn Marino    used to implement method forwarding.
1039*e4b17023SJohn Marino 
1040*e4b17023SJohn Marino    Compatibility Note: these functions are not available with the
1041*e4b17023SJohn Marino    Apple/NeXT runtime.  */
1042*e4b17023SJohn Marino 
1043*e4b17023SJohn Marino /* Return the size of a variable which has the specified 'type'
1044*e4b17023SJohn Marino    encoding.  */
1045*e4b17023SJohn Marino objc_EXPORT int objc_sizeof_type (const char *type);
1046*e4b17023SJohn Marino 
1047*e4b17023SJohn Marino /* Return the align of a variable which has the specified 'type'
1048*e4b17023SJohn Marino    encoding.  */
1049*e4b17023SJohn Marino objc_EXPORT int objc_alignof_type (const char *type);
1050*e4b17023SJohn Marino 
1051*e4b17023SJohn Marino /* Return the aligned size of a variable which has the specified
1052*e4b17023SJohn Marino    'type' encoding.  The aligned size is the size rounded up to the
1053*e4b17023SJohn Marino    nearest alignment.  */
1054*e4b17023SJohn Marino objc_EXPORT int objc_aligned_size (const char *type);
1055*e4b17023SJohn Marino 
1056*e4b17023SJohn Marino /* Return the promoted size of a variable which has the specified
1057*e4b17023SJohn Marino    'type' encoding.  This is the size rounded up to the nearest
1058*e4b17023SJohn Marino    integral of the wordsize, taken to be the size of a void *.  */
1059*e4b17023SJohn Marino objc_EXPORT int objc_promoted_size (const char *type);
1060*e4b17023SJohn Marino 
1061*e4b17023SJohn Marino 
1062*e4b17023SJohn Marino /* The following functions are used when parsing the type encoding of
1063*e4b17023SJohn Marino    methods, to skip over parts that are ignored.  They take as
1064*e4b17023SJohn Marino    argument a pointer to a location inside the type encoding of a
1065*e4b17023SJohn Marino    method (which is a string) and return a new pointer, pointing to a
1066*e4b17023SJohn Marino    new location inside the string after having skipped the unwanted
1067*e4b17023SJohn Marino    information.  */
1068*e4b17023SJohn Marino 
1069*e4b17023SJohn Marino /* Skip some type qualifiers (_C_CONST, _C_IN, etc).  These may
1070*e4b17023SJohn Marino   eventually precede typespecs occurring in method prototype
1071*e4b17023SJohn Marino   encodings.  */
1072*e4b17023SJohn Marino objc_EXPORT const char *objc_skip_type_qualifiers (const char *type);
1073*e4b17023SJohn Marino 
1074*e4b17023SJohn Marino /* Skip one typespec element (_C_CLASS, _C_SEL, etc).  If the typespec
1075*e4b17023SJohn Marino   is prepended by type qualifiers, these are skipped as well.  */
1076*e4b17023SJohn Marino objc_EXPORT const char *objc_skip_typespec (const char *type);
1077*e4b17023SJohn Marino 
1078*e4b17023SJohn Marino /* Skip an offset.  */
1079*e4b17023SJohn Marino objc_EXPORT const char *objc_skip_offset (const char *type);
1080*e4b17023SJohn Marino 
1081*e4b17023SJohn Marino /* Skip an argument specification (ie, skipping a typespec, which may
1082*e4b17023SJohn Marino    include qualifiers, and an offset too).  */
1083*e4b17023SJohn Marino objc_EXPORT const char *objc_skip_argspec (const char *type);
1084*e4b17023SJohn Marino 
1085*e4b17023SJohn Marino /* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type'
1086*e4b17023SJohn Marino    (stopping at the first non-type qualifier found) and return an
1087*e4b17023SJohn Marino    unsigned int which is the logical OR of all the corresponding flags
1088*e4b17023SJohn Marino    (_F_CONST, _F_IN etc).  */
1089*e4b17023SJohn Marino objc_EXPORT unsigned objc_get_type_qualifiers (const char *type);
1090*e4b17023SJohn Marino 
1091*e4b17023SJohn Marino 
1092*e4b17023SJohn Marino /* Note that the following functions work for very simple structures,
1093*e4b17023SJohn Marino    but get easily confused by more complicated ones (for example,
1094*e4b17023SJohn Marino    containing vectors).  A better solution is required.  These
1095*e4b17023SJohn Marino    functions are likely to change in the next GCC release.  */
1096*e4b17023SJohn Marino 
1097*e4b17023SJohn Marino /* The following three functions can be used to determine how a
1098*e4b17023SJohn Marino    structure is laid out by the compiler. For example:
1099*e4b17023SJohn Marino 
1100*e4b17023SJohn Marino   struct objc_struct_layout layout;
1101*e4b17023SJohn Marino   int i;
1102*e4b17023SJohn Marino 
1103*e4b17023SJohn Marino   objc_layout_structure (type, &layout);
1104*e4b17023SJohn Marino   while (objc_layout_structure_next_member (&layout))
1105*e4b17023SJohn Marino     {
1106*e4b17023SJohn Marino       int position, align;
1107*e4b17023SJohn Marino       const char *type;
1108*e4b17023SJohn Marino 
1109*e4b17023SJohn Marino       objc_layout_structure_get_info (&layout, &position, &align, &type);
1110*e4b17023SJohn Marino       printf ("element %d has offset %d, alignment %d\n",
1111*e4b17023SJohn Marino               i++, position, align);
1112*e4b17023SJohn Marino     }
1113*e4b17023SJohn Marino 
1114*e4b17023SJohn Marino   These functions are used by objc_sizeof_type and objc_alignof_type
1115*e4b17023SJohn Marino   functions to compute the size and alignment of structures. The
1116*e4b17023SJohn Marino   previous method of computing the size and alignment of a structure
1117*e4b17023SJohn Marino   was not working on some architectures, particulary on AIX, and in
1118*e4b17023SJohn Marino   the presence of bitfields inside the structure.  */
1119*e4b17023SJohn Marino struct objc_struct_layout
1120*e4b17023SJohn Marino {
1121*e4b17023SJohn Marino   const char *original_type;
1122*e4b17023SJohn Marino   const char *type;
1123*e4b17023SJohn Marino   const char *prev_type;
1124*e4b17023SJohn Marino   unsigned int record_size;
1125*e4b17023SJohn Marino   unsigned int record_align;
1126*e4b17023SJohn Marino };
1127*e4b17023SJohn Marino 
1128*e4b17023SJohn Marino objc_EXPORT void objc_layout_structure (const char *type,
1129*e4b17023SJohn Marino                             struct objc_struct_layout *layout);
1130*e4b17023SJohn Marino objc_EXPORT BOOL  objc_layout_structure_next_member (struct objc_struct_layout *layout);
1131*e4b17023SJohn Marino objc_EXPORT void objc_layout_finish_structure (struct objc_struct_layout *layout,
1132*e4b17023SJohn Marino 					       unsigned int *size,
1133*e4b17023SJohn Marino 					       unsigned int *align);
1134*e4b17023SJohn Marino objc_EXPORT void objc_layout_structure_get_info (struct objc_struct_layout *layout,
1135*e4b17023SJohn Marino 						 unsigned int *offset,
1136*e4b17023SJohn Marino 						 unsigned int *align,
1137*e4b17023SJohn Marino 						 const char **type);
1138*e4b17023SJohn Marino 
1139*e4b17023SJohn Marino #ifdef __cplusplus
1140*e4b17023SJohn Marino }
1141*e4b17023SJohn Marino #endif /* __cplusplus */
1142*e4b17023SJohn Marino 
1143*e4b17023SJohn Marino #endif
1144