148fb7bfaSmrg /* GNU Objective-C Runtime API - Modern API
2*b1e83836Smrg Copyright (C) 2010-2022 Free Software Foundation, Inc.
348fb7bfaSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
44fee23f9Smrg
54fee23f9Smrg This file is part of GCC.
64fee23f9Smrg
748fb7bfaSmrg GCC is free software; you can redistribute it and/or modify it
848fb7bfaSmrg under the terms of the GNU General Public License as published by the
948fb7bfaSmrg Free Software Foundation; either version 3, or (at your option) any
1048fb7bfaSmrg later version.
114fee23f9Smrg
1248fb7bfaSmrg GCC is distributed in the hope that it will be useful, but WITHOUT
1348fb7bfaSmrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1448fb7bfaSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
1548fb7bfaSmrg License for more details.
164fee23f9Smrg
174fee23f9Smrg Under Section 7 of GPL version 3, you are granted additional
184fee23f9Smrg permissions described in the GCC Runtime Library Exception, version
194fee23f9Smrg 3.1, as published by the Free Software Foundation.
204fee23f9Smrg
214fee23f9Smrg You should have received a copy of the GNU General Public License and
224fee23f9Smrg a copy of the GCC Runtime Library Exception along with this program;
234fee23f9Smrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
244fee23f9Smrg <http://www.gnu.org/licenses/>. */
254fee23f9Smrg
264fee23f9Smrg #ifndef __objc_runtime_INCLUDE_GNU
274fee23f9Smrg #define __objc_runtime_INCLUDE_GNU
284fee23f9Smrg
2948fb7bfaSmrg /*
3048fb7bfaSmrg This file declares the "modern" GNU Objective-C Runtime API.
314fee23f9Smrg
3248fb7bfaSmrg This API replaced the "traditional" GNU Objective-C Runtime API
3348fb7bfaSmrg (which used to be declared in objc/objc-api.h) which is the one
3448fb7bfaSmrg supported by older versions of the GNU Objective-C Runtime. The
3548fb7bfaSmrg "modern" API is very similar to the API used by the modern
3648fb7bfaSmrg Apple/NeXT runtime.
3748fb7bfaSmrg */
3848fb7bfaSmrg #include "objc.h"
3948fb7bfaSmrg #include "objc-decls.h"
404fee23f9Smrg
414fee23f9Smrg #ifdef __cplusplus
424fee23f9Smrg extern "C" {
434fee23f9Smrg #endif /* __cplusplus */
444fee23f9Smrg
4548fb7bfaSmrg /* An 'Ivar' represents an instance variable. It holds information
4648fb7bfaSmrg about the name, type and offset of the instance variable. */
4748fb7bfaSmrg typedef struct objc_ivar *Ivar;
484fee23f9Smrg
4948fb7bfaSmrg /* A 'Property' represents a property. It holds information about the
5048fb7bfaSmrg name of the property, and its attributes.
514fee23f9Smrg
5248fb7bfaSmrg Compatibility Note: the Apple/NeXT runtime defines this as
5348fb7bfaSmrg objc_property_t, so we define it that way as well, but obviously
5448fb7bfaSmrg Property is the right name. */
5548fb7bfaSmrg typedef struct objc_property *Property;
5648fb7bfaSmrg typedef struct objc_property *objc_property_t;
574fee23f9Smrg
5848fb7bfaSmrg /* A 'Method' represents a method. It holds information about the
5948fb7bfaSmrg name, types and the IMP of the method. */
6048fb7bfaSmrg typedef struct objc_method *Method;
614fee23f9Smrg
6248fb7bfaSmrg /* A 'Category' represents a category. It holds information about the
6348fb7bfaSmrg name of the category, the class it belongs to, and the methods,
6448fb7bfaSmrg protocols and such like provided by the category. */
6548fb7bfaSmrg typedef struct objc_category *Category;
664fee23f9Smrg
6748fb7bfaSmrg /* 'Protocol' is defined in objc/objc.h (which is included by this
6848fb7bfaSmrg file). */
694fee23f9Smrg
7048fb7bfaSmrg /* Method descriptor returned by introspective Object methods. At the
7148fb7bfaSmrg moment, this is really just the first part of the more complete
7248fb7bfaSmrg objc_method structure used internally by the runtime. (PS: In the
7348fb7bfaSmrg GNU Objective-C Runtime, selectors already include a type, so an
7448fb7bfaSmrg objc_method_description does not add much to a SEL. But in other
7548fb7bfaSmrg runtimes, that is not the case, which is why
7648fb7bfaSmrg objc_method_description exists). */
7748fb7bfaSmrg struct objc_method_description
7848fb7bfaSmrg {
7948fb7bfaSmrg SEL name; /* Selector (name and signature) */
8048fb7bfaSmrg char *types; /* Type encoding */
8148fb7bfaSmrg };
824fee23f9Smrg
8348fb7bfaSmrg /* The following are used in encode strings to describe the type of
8448fb7bfaSmrg Ivars and Methods. */
8548fb7bfaSmrg #define _C_ID '@'
8648fb7bfaSmrg #define _C_CLASS '#'
8748fb7bfaSmrg #define _C_SEL ':'
8848fb7bfaSmrg #define _C_CHR 'c'
8948fb7bfaSmrg #define _C_UCHR 'C'
9048fb7bfaSmrg #define _C_SHT 's'
9148fb7bfaSmrg #define _C_USHT 'S'
9248fb7bfaSmrg #define _C_INT 'i'
9348fb7bfaSmrg #define _C_UINT 'I'
9448fb7bfaSmrg #define _C_LNG 'l'
9548fb7bfaSmrg #define _C_ULNG 'L'
9648fb7bfaSmrg #define _C_LNG_LNG 'q'
9748fb7bfaSmrg #define _C_ULNG_LNG 'Q'
9848fb7bfaSmrg #define _C_FLT 'f'
9948fb7bfaSmrg #define _C_DBL 'd'
10048fb7bfaSmrg #define _C_LNG_DBL 'D'
10148fb7bfaSmrg #define _C_BFLD 'b'
10248fb7bfaSmrg #define _C_BOOL 'B'
10348fb7bfaSmrg #define _C_VOID 'v'
10448fb7bfaSmrg #define _C_UNDEF '?'
10548fb7bfaSmrg #define _C_PTR '^'
10648fb7bfaSmrg #define _C_CHARPTR '*'
10748fb7bfaSmrg #define _C_ARY_B '['
10848fb7bfaSmrg #define _C_ARY_E ']'
10948fb7bfaSmrg #define _C_UNION_B '('
11048fb7bfaSmrg #define _C_UNION_E ')'
11148fb7bfaSmrg #define _C_STRUCT_B '{'
11248fb7bfaSmrg #define _C_STRUCT_E '}'
11348fb7bfaSmrg #define _C_VECTOR '!'
11448fb7bfaSmrg #define _C_COMPLEX 'j'
1154fee23f9Smrg
11648fb7bfaSmrg /* _C_ATOM is never generated by the compiler. You can treat it as
11748fb7bfaSmrg equivalent to "*". */
11848fb7bfaSmrg #define _C_ATOM '%'
1194fee23f9Smrg
12048fb7bfaSmrg /* The following are used in encode strings to describe some
12148fb7bfaSmrg qualifiers of method and ivar types. */
12248fb7bfaSmrg #define _C_CONST 'r'
12348fb7bfaSmrg #define _C_IN 'n'
12448fb7bfaSmrg #define _C_INOUT 'N'
12548fb7bfaSmrg #define _C_OUT 'o'
12648fb7bfaSmrg #define _C_BYCOPY 'O'
12748fb7bfaSmrg #define _C_BYREF 'R'
12848fb7bfaSmrg #define _C_ONEWAY 'V'
12948fb7bfaSmrg #define _C_GCINVISIBLE '|'
13048fb7bfaSmrg
13148fb7bfaSmrg /* The same when used as flags. */
13248fb7bfaSmrg #define _F_CONST 0x01
13348fb7bfaSmrg #define _F_IN 0x01
13448fb7bfaSmrg #define _F_OUT 0x02
13548fb7bfaSmrg #define _F_INOUT 0x03
13648fb7bfaSmrg #define _F_BYCOPY 0x04
13748fb7bfaSmrg #define _F_BYREF 0x08
13848fb7bfaSmrg #define _F_ONEWAY 0x10
13948fb7bfaSmrg #define _F_GCINVISIBLE 0x20
14048fb7bfaSmrg
14148fb7bfaSmrg
14248fb7bfaSmrg /** Implementation: the following functions are defined inline. */
14348fb7bfaSmrg
14448fb7bfaSmrg /* Return the class of 'object', or Nil if the object is nil. If
14548fb7bfaSmrg 'object' is a class, the meta class is returned; if 'object' is a
14648fb7bfaSmrg meta class, the root meta class is returned (note that this is
14748fb7bfaSmrg different from the traditional GNU Objective-C Runtime API function
14848fb7bfaSmrg object_get_class(), which for a meta class would return the meta
14948fb7bfaSmrg class itself). This function is inline, so it is really fast and
15048fb7bfaSmrg should be used instead of accessing object->class_pointer
15148fb7bfaSmrg directly. */
15248fb7bfaSmrg static inline Class
object_getClass(id object)15348fb7bfaSmrg object_getClass (id object)
15448fb7bfaSmrg {
15548fb7bfaSmrg if (object != nil)
15648fb7bfaSmrg return object->class_pointer;
15748fb7bfaSmrg else
15848fb7bfaSmrg return Nil;
15948fb7bfaSmrg }
16048fb7bfaSmrg
16148fb7bfaSmrg
16248fb7bfaSmrg /** Implementation: the following functions are in selector.c. */
16348fb7bfaSmrg
16448fb7bfaSmrg /* Return the name of a given selector. If 'selector' is NULL, return
16548fb7bfaSmrg "<null selector>". */
16648fb7bfaSmrg objc_EXPORT const char *sel_getName (SEL selector);
16748fb7bfaSmrg
16848fb7bfaSmrg /* Return the type of a given selector. Return NULL if selector is
16948fb7bfaSmrg NULL.
17048fb7bfaSmrg
17148fb7bfaSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
17248fb7bfaSmrg so it does not have this function, which is specific to the GNU
17348fb7bfaSmrg Runtime. */
17448fb7bfaSmrg objc_EXPORT const char *sel_getTypeEncoding (SEL selector);
17548fb7bfaSmrg
17648fb7bfaSmrg /* This is the same as sel_registerName (). Please use
17748fb7bfaSmrg sel_registerName () instead. */
17848fb7bfaSmrg objc_EXPORT SEL sel_getUid (const char *name);
17948fb7bfaSmrg
18048fb7bfaSmrg /* Register a selector with a given name (but unspecified types). If
18148fb7bfaSmrg you know the types, it is better to call sel_registerTypedName().
18248fb7bfaSmrg If a selector with this name and no types already exists, it is
18348fb7bfaSmrg returned. Note that this function should really be called
18448fb7bfaSmrg 'objc_registerSelector'. Return NULL if 'name' is NULL. */
18548fb7bfaSmrg objc_EXPORT SEL sel_registerName (const char *name);
18648fb7bfaSmrg
18748fb7bfaSmrg /* Register a selector with a given name and types. If a selector
18848fb7bfaSmrg with this name and types already exists, it is returned. Note that
18948fb7bfaSmrg this function should really be called 'objc_registerTypedSelector',
19048fb7bfaSmrg and it's called 'sel_registerTypedName' only for consistency with
19148fb7bfaSmrg 'sel_registerName'. Return NULL if 'name' is NULL.
19248fb7bfaSmrg
19348fb7bfaSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
19448fb7bfaSmrg so it does not have this function, which is specific to the GNU
19548fb7bfaSmrg Runtime. */
19648fb7bfaSmrg objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type);
19748fb7bfaSmrg
19848fb7bfaSmrg /* Return YES if first_selector is the same as second_selector, and NO
19948fb7bfaSmrg if not. */
20048fb7bfaSmrg objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector);
20148fb7bfaSmrg
20248fb7bfaSmrg /* Return all the selectors with the supplied name. In the GNU
20348fb7bfaSmrg runtime, selectors are typed and there may be multiple selectors
20448fb7bfaSmrg with the same name but a different type. The return value of the
20548fb7bfaSmrg function is a pointer to an area, allocated with malloc(), that
20648fb7bfaSmrg contains all the selectors with the supplier name known to the
20748fb7bfaSmrg runtime. The list is terminated by NULL. Optionally, if you pass
20848fb7bfaSmrg a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int
20948fb7bfaSmrg that it points to will be filled with the number of selectors
21048fb7bfaSmrg returned.
21148fb7bfaSmrg
21248fb7bfaSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
21348fb7bfaSmrg so it does not have this function, which is specific to the GNU
21448fb7bfaSmrg Runtime. */
21548fb7bfaSmrg objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name,
21648fb7bfaSmrg unsigned int *numberOfReturnedSelectors);
21748fb7bfaSmrg
21848fb7bfaSmrg /* Return a selector with name 'name' and a non-zero type encoding, if
21948fb7bfaSmrg there is a single selector with a type, and with that name,
22048fb7bfaSmrg registered with the runtime. If there is no such selector, or if
22148fb7bfaSmrg there are multiple selectors with the same name but conflicting
22248fb7bfaSmrg types, NULL is returned. Return NULL if 'name' is NULL.
22348fb7bfaSmrg
22448fb7bfaSmrg This is useful if you have the name of the selector, and would
22548fb7bfaSmrg really like to get a selector for it that includes the type
22648fb7bfaSmrg encoding. Unfortunately, if the program contains multiple selector
227181254a7Smrg with the same name but different types, sel_getTypedSelector cannot
228181254a7Smrg possibly know which one you need, and so will return NULL.
22948fb7bfaSmrg
23048fb7bfaSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
23148fb7bfaSmrg so it does not have this function, which is specific to the GNU
23248fb7bfaSmrg Runtime. */
23348fb7bfaSmrg objc_EXPORT SEL sel_getTypedSelector (const char *name);
23448fb7bfaSmrg
23548fb7bfaSmrg
23648fb7bfaSmrg /** Implementation: the following functions are in objects.c. */
23748fb7bfaSmrg
23848fb7bfaSmrg /* Create an instance of class 'class_', adding extraBytes to the size
23948fb7bfaSmrg of the returned object. This method allocates the appropriate
24048fb7bfaSmrg amount of memory for the instance, initializes it to zero, then
24148fb7bfaSmrg calls all the C++ constructors on appropriate C++ instance
24248fb7bfaSmrg variables of the instance (if any) (TODO: The C++ constructors bit
24348fb7bfaSmrg is not implemented yet). */
24448fb7bfaSmrg objc_EXPORT id class_createInstance (Class class_, size_t extraBytes);
24548fb7bfaSmrg
24648fb7bfaSmrg /* Copy an object and return the copy. extraBytes should be identical
24748fb7bfaSmrg to the extraBytes parameter that was passed when creating the
24848fb7bfaSmrg original object. */
24948fb7bfaSmrg objc_EXPORT id object_copy (id object, size_t extraBytes);
25048fb7bfaSmrg
25148fb7bfaSmrg /* Dispose of an object. This method calls the appropriate C++
25248fb7bfaSmrg destructors on appropriate C++ instance variables of the instance
25348fb7bfaSmrg (if any) (TODO: This is not implemented yet), then frees the memory
25448fb7bfaSmrg for the instance. */
25548fb7bfaSmrg objc_EXPORT id object_dispose (id object);
25648fb7bfaSmrg
25748fb7bfaSmrg /* Return the name of the class of 'object'. If 'object' is 'nil',
25848fb7bfaSmrg returns "Nil". */
25948fb7bfaSmrg objc_EXPORT const char * object_getClassName (id object);
26048fb7bfaSmrg
26148fb7bfaSmrg /* Change the class of object to be class_. Return the previous class
26248fb7bfaSmrg of object. This is currently not really thread-safe. */
26348fb7bfaSmrg objc_EXPORT Class object_setClass (id object, Class class_);
26448fb7bfaSmrg
26548fb7bfaSmrg
26648fb7bfaSmrg /** Implementation: the following functions are in ivars.c. */
26748fb7bfaSmrg
26848fb7bfaSmrg /* Return an instance variable given the class and the instance
26948fb7bfaSmrg variable name. This is an expensive function to call, so try to
27048fb7bfaSmrg reuse the returned Ivar if you can. */
27148fb7bfaSmrg objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name);
27248fb7bfaSmrg
27348fb7bfaSmrg /* Return a class variable given the class and the class variable
27448fb7bfaSmrg name. This is an expensive function to call, so try to reuse the
27548fb7bfaSmrg returned Ivar if you can.
27648fb7bfaSmrg
27748fb7bfaSmrg This function always returns NULL since class variables are
27848fb7bfaSmrg currently unavailable in Objective-C. */
27948fb7bfaSmrg objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name);
28048fb7bfaSmrg
28148fb7bfaSmrg /* If the object was created in class_createInstance() with some
28248fb7bfaSmrg extraBytes, returns a pointer to them. If it was not, then the
28348fb7bfaSmrg returned pointer may make no sense. */
28448fb7bfaSmrg objc_EXPORT void * object_getIndexedIvars (id object);
28548fb7bfaSmrg
28648fb7bfaSmrg /* Get the value of an instance variable of type 'id'. The function
28748fb7bfaSmrg returns the instance variable. To get the value of the instance
28848fb7bfaSmrg variable, you should pass as 'returnValue' a pointer to an 'id';
28948fb7bfaSmrg the value will be copied there. Note that 'returnValue' is really
29048fb7bfaSmrg a 'void *', not a 'void **'. This function really works only with
29148fb7bfaSmrg instance variables of type 'id'; for other types of instance
29248fb7bfaSmrg variables, access directly the data at (char *)object +
29348fb7bfaSmrg ivar_getOffset (ivar). */
29448fb7bfaSmrg objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue);
29548fb7bfaSmrg
29648fb7bfaSmrg /* Set the value of an instance variable. The value to set is passed
29748fb7bfaSmrg in 'newValue' (which really is an 'id', not a 'void *'). The
29848fb7bfaSmrg function returns the instance variable. This function really works
29948fb7bfaSmrg only with instance variables of type 'id'; for other types of
30048fb7bfaSmrg instance variables, access directly the data at (char *)object +
30148fb7bfaSmrg ivar_getOffset (ivar). */
30248fb7bfaSmrg objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue);
30348fb7bfaSmrg
30448fb7bfaSmrg /* Get the value of an instance variable of type 'id' of the object
30548fb7bfaSmrg 'object'. This is faster than object_getInstanceVariable if you
30648fb7bfaSmrg already have the instance variable because it avoids the expensive
30748fb7bfaSmrg call to class_getInstanceVariable that is done by
30848fb7bfaSmrg object_getInstanceVariable. */
30948fb7bfaSmrg objc_EXPORT id object_getIvar (id object, Ivar variable);
31048fb7bfaSmrg
31148fb7bfaSmrg /* Set the value of an instance variable of type 'id' of the object
31248fb7bfaSmrg 'object'. This is faster than object_setInstanceVariable if you
31348fb7bfaSmrg already have the instance variable because it avoids the expensive
31448fb7bfaSmrg call to class_getInstanceVariable that is done by
31548fb7bfaSmrg object_setInstanceVariable. */
31648fb7bfaSmrg objc_EXPORT void object_setIvar (id object, Ivar variable, id value);
31748fb7bfaSmrg
31848fb7bfaSmrg /* Return the name of the instance variable. Return NULL if
31948fb7bfaSmrg 'variable' is NULL. */
32048fb7bfaSmrg objc_EXPORT const char * ivar_getName (Ivar variable);
32148fb7bfaSmrg
32248fb7bfaSmrg /* Return the offset of the instance variable from the start of the
32348fb7bfaSmrg object data. Return 0 if 'variable' is NULL. */
32448fb7bfaSmrg objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable);
32548fb7bfaSmrg
32648fb7bfaSmrg /* Return the type encoding of the variable. Return NULL if
32748fb7bfaSmrg 'variable' is NULL. */
32848fb7bfaSmrg objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable);
32948fb7bfaSmrg
33048fb7bfaSmrg /* Return all the instance variables of the class. The return value
33148fb7bfaSmrg of the function is a pointer to an area, allocated with malloc(),
33248fb7bfaSmrg that contains all the instance variables of the class. It does not
33348fb7bfaSmrg include instance variables of superclasses. The list is terminated
33448fb7bfaSmrg by NULL. Optionally, if you pass a non-NULL
33548fb7bfaSmrg 'numberOfReturnedIvars' pointer, the unsigned int that it points to
33648fb7bfaSmrg will be filled with the number of instance variables returned.
33748fb7bfaSmrg Return NULL for classes still in construction (ie, allocated using
33848fb7bfaSmrg objc_allocatedClassPair() but not yet registered with the runtime
33948fb7bfaSmrg using objc_registerClassPair()). */
34048fb7bfaSmrg objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars);
34148fb7bfaSmrg
34248fb7bfaSmrg /* Add an instance variable with name 'ivar_name' to class 'class_',
34348fb7bfaSmrg where 'class_' is a class in construction that has been created
34448fb7bfaSmrg using objc_allocateClassPair() and has not been registered with the
34548fb7bfaSmrg runtime using objc_registerClassPair() yet. You cannot add
34648fb7bfaSmrg instance variables to classes already registered with the runtime.
34748fb7bfaSmrg 'size' is the size of the instance variable, 'log_2_of_alignment'
34848fb7bfaSmrg the alignment as a power of 2 (so 0 means alignment to a 1 byte
34948fb7bfaSmrg boundary, 1 means alignment to a 2 byte boundary, 2 means alignment
35048fb7bfaSmrg to a 4 byte boundary, etc), and 'type' the type encoding of the
35148fb7bfaSmrg variable type. You can use sizeof(), log2(__alignof__()) and
35248fb7bfaSmrg @encode() to determine the right 'size', 'alignment' and 'type' for
35348fb7bfaSmrg your instance variable. For example, to add an instance variable
35448fb7bfaSmrg name "my_variable" and of type 'id', you can use:
35548fb7bfaSmrg
35648fb7bfaSmrg class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)),
35748fb7bfaSmrg @encode (id));
35848fb7bfaSmrg
35948fb7bfaSmrg Return YES if the variable was added, and NO if not. In
36048fb7bfaSmrg particular, return NO if 'class_' is Nil, or a meta-class or a
36148fb7bfaSmrg class not in construction. Return Nil also if 'ivar_name' or
36248fb7bfaSmrg 'type' is NULL, or 'size' is 0.
36348fb7bfaSmrg */
36448fb7bfaSmrg objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size,
36548fb7bfaSmrg unsigned char log_2_of_alignment, const char *type);
36648fb7bfaSmrg
36748fb7bfaSmrg /* Return the name of the property. Return NULL if 'property' is
36848fb7bfaSmrg NULL. */
36948fb7bfaSmrg objc_EXPORT const char * property_getName (Property property);
37048fb7bfaSmrg
37148fb7bfaSmrg /* Return the attributes of the property as a string. Return NULL if
37248fb7bfaSmrg 'property' is NULL. */
37348fb7bfaSmrg objc_EXPORT const char * property_getAttributes (Property property);
37448fb7bfaSmrg
37548fb7bfaSmrg /* Return the property with name 'propertyName' of the class 'class_'.
37648fb7bfaSmrg This function returns NULL if the required property cannot be
37748fb7bfaSmrg found. Return NULL if 'class_' or 'propertyName' is NULL.
37848fb7bfaSmrg
37948fb7bfaSmrg Note that the traditional ABI does not store the list of properties
38048fb7bfaSmrg of a class in a compiled module, so the traditional ABI will always
38148fb7bfaSmrg return NULL. */
38248fb7bfaSmrg objc_EXPORT Property class_getProperty (Class class_, const char *propertyName);
38348fb7bfaSmrg
38448fb7bfaSmrg /* Return all the properties of the class. The return value
38548fb7bfaSmrg of the function is a pointer to an area, allocated with malloc(),
38648fb7bfaSmrg that contains all the properties of the class. It does not
38748fb7bfaSmrg include properties of superclasses. The list is terminated
38848fb7bfaSmrg by NULL. Optionally, if you pass a non-NULL
38948fb7bfaSmrg 'numberOfReturnedIvars' pointer, the unsigned int that it points to
39048fb7bfaSmrg will be filled with the number of properties returned.
39148fb7bfaSmrg
39248fb7bfaSmrg Note that the traditional ABI does not store the list of properties
39348fb7bfaSmrg of a class in a compiled module, so the traditional ABI will always
39448fb7bfaSmrg return an empty list. */
39548fb7bfaSmrg objc_EXPORT Property * class_copyPropertyList
39648fb7bfaSmrg (Class class_, unsigned int *numberOfReturnedProperties);
39748fb7bfaSmrg
39848fb7bfaSmrg /* Return the ivar layout for class 'class_'.
39948fb7bfaSmrg
40048fb7bfaSmrg At the moment this function always returns NULL. */
40148fb7bfaSmrg objc_EXPORT const char * class_getIvarLayout (Class class_);
40248fb7bfaSmrg
40348fb7bfaSmrg /* Return the weak ivar layout for class 'class_'.
40448fb7bfaSmrg
40548fb7bfaSmrg At the moment this function always returns NULL. */
40648fb7bfaSmrg objc_EXPORT const char * class_getWeakIvarLayout (Class class_);
40748fb7bfaSmrg
40848fb7bfaSmrg /* Set the ivar layout for class 'class_'.
40948fb7bfaSmrg
41048fb7bfaSmrg At the moment, this function does nothing. */
41148fb7bfaSmrg objc_EXPORT void class_setIvarLayout (Class class_, const char *layout);
41248fb7bfaSmrg
41348fb7bfaSmrg /* Set the weak ivar layout for class 'class_'.
41448fb7bfaSmrg
41548fb7bfaSmrg At the moment, this function does nothing. With the GNU runtime,
41648fb7bfaSmrg you should use class_ivar_set_gcinvisible () to hide variables from
41748fb7bfaSmrg the Garbage Collector. */
41848fb7bfaSmrg objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout);
41948fb7bfaSmrg
42048fb7bfaSmrg
42148fb7bfaSmrg /** Implementation: the following functions are in class.c. */
42248fb7bfaSmrg
42348fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime does not have
42448fb7bfaSmrg objc_get_unknown_class_handler and
42548fb7bfaSmrg objc_setGetUnknownClassHandler(). They provide functionality that
42648fb7bfaSmrg the traditional GNU Objective-C Runtime API used to provide via the
42748fb7bfaSmrg _objc_lookup_class hook. */
42848fb7bfaSmrg
42948fb7bfaSmrg /* An 'objc_get_unknown_class_handler' function is used by
43048fb7bfaSmrg objc_getClass() to get a class that is currently unknown to the
43148fb7bfaSmrg compiler. You could use it for example to have the class loaded by
43248fb7bfaSmrg dynamically loading a library. 'class_name' is the name of the
43348fb7bfaSmrg class. The function should return the Class object if it manages to
43448fb7bfaSmrg load the class, and Nil if not. */
43548fb7bfaSmrg typedef Class (*objc_get_unknown_class_handler)(const char *class_name);
43648fb7bfaSmrg
43748fb7bfaSmrg /* Sets a new handler function for getting unknown classes (to be used
43848fb7bfaSmrg by objc_getClass () and related), and returns the previous one.
43948fb7bfaSmrg This function is not safe to call in a multi-threaded environment
44048fb7bfaSmrg because other threads may be trying to use the get unknown class
44148fb7bfaSmrg handler while you change it! */
44248fb7bfaSmrg objc_EXPORT
44348fb7bfaSmrg objc_get_unknown_class_handler
44448fb7bfaSmrg objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler);
44548fb7bfaSmrg
44648fb7bfaSmrg /* Return the class with name 'name', if it is already registered with
44748fb7bfaSmrg the runtime. If it is not registered, and
44848fb7bfaSmrg objc_setGetUnknownClassHandler() has been called to set a handler
44948fb7bfaSmrg for unknown classes, the handler is called to give it a chance to
45048fb7bfaSmrg load the class in some other way. If the class is not known to the
45148fb7bfaSmrg runtime and the handler is not set or returns Nil, objc_getClass()
45248fb7bfaSmrg returns Nil. */
45348fb7bfaSmrg objc_EXPORT Class objc_getClass (const char *name);
45448fb7bfaSmrg
45548fb7bfaSmrg /* Return the class with name 'name', if it is already registered with
45648fb7bfaSmrg the runtime. Return Nil if not. This function does not call the
45748fb7bfaSmrg objc_get_unknown_class_handler function if the class is not
45848fb7bfaSmrg found. */
45948fb7bfaSmrg objc_EXPORT Class objc_lookUpClass (const char *name);
46048fb7bfaSmrg
46148fb7bfaSmrg /* Return the meta class associated to the class with name 'name', if
46248fb7bfaSmrg it is already registered with the runtime. First, it finds the
46348fb7bfaSmrg class using objc_getClass(). Then, it returns the associated meta
46448fb7bfaSmrg class. If the class could not be found using objc_getClass(),
46548fb7bfaSmrg returns Nil. */
46648fb7bfaSmrg objc_EXPORT Class objc_getMetaClass (const char *name);
46748fb7bfaSmrg
46848fb7bfaSmrg /* This is identical to objc_getClass(), but if the class is not found,
46948fb7bfaSmrg it aborts the process instead of returning Nil. */
47048fb7bfaSmrg objc_EXPORT Class objc_getRequiredClass (const char *name);
47148fb7bfaSmrg
47248fb7bfaSmrg /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of
47348fb7bfaSmrg classes currently registered with the runtime. If 'returnValue' is
47448fb7bfaSmrg not NULL, it should be a (Class *) pointer to an area of memory
47548fb7bfaSmrg which can contain up to 'maxNumberOfClassesToReturn' Class records.
47648fb7bfaSmrg 'objc_getClassList' will fill the area pointed to by 'returnValue'
47748fb7bfaSmrg with all the Classes registered with the runtime (or up to
47848fb7bfaSmrg maxNumberOfClassesToReturn if there are more than
47948fb7bfaSmrg maxNumberOfClassesToReturn). The function return value is the
48048fb7bfaSmrg number of classes actually returned in 'returnValue'. */
48148fb7bfaSmrg objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn);
48248fb7bfaSmrg
48348fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime also has
48448fb7bfaSmrg
48548fb7bfaSmrg Class objc_getFutureClass (const char *name);
48648fb7bfaSmrg void objc_setFutureClass (Class class_, const char *name);
48748fb7bfaSmrg
48848fb7bfaSmrg the documentation is unclear on what they are supposed to do, and
48948fb7bfaSmrg the GNU Objective-C Runtime currently does not provide them. */
49048fb7bfaSmrg
49148fb7bfaSmrg /* Return the name of the class 'class_', or the string "nil" if the
49248fb7bfaSmrg class_ is Nil. */
49348fb7bfaSmrg objc_EXPORT const char * class_getName (Class class_);
49448fb7bfaSmrg
49548fb7bfaSmrg /* Return YES if 'class_' is a meta class, and NO if not. If 'class_'
49648fb7bfaSmrg is Nil, return NO. */
49748fb7bfaSmrg objc_EXPORT BOOL class_isMetaClass (Class class_);
49848fb7bfaSmrg
49948fb7bfaSmrg /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a
50048fb7bfaSmrg root class, return Nil. This function also works if 'class_' is a
50148fb7bfaSmrg class being constructed, that is, a class returned by
50248fb7bfaSmrg objc_allocateClassPair() but before it has been registered with the
50348fb7bfaSmrg runtime using objc_registerClassPair(). */
50448fb7bfaSmrg objc_EXPORT Class class_getSuperclass (Class class_);
50548fb7bfaSmrg
50648fb7bfaSmrg /* Return the 'version' number of the class, which is an integer that
50748fb7bfaSmrg can be used to track changes in the class API, methods and
50848fb7bfaSmrg variables. If class_ is Nil, return 0. If class_ is not Nil, the
50948fb7bfaSmrg version is 0 unless class_setVersion() has been called to set a
51048fb7bfaSmrg different one.
51148fb7bfaSmrg
51248fb7bfaSmrg Please note that internally the version is a long, but the API only
51348fb7bfaSmrg allows you to set and retrieve int values. */
51448fb7bfaSmrg objc_EXPORT int class_getVersion (Class class_);
51548fb7bfaSmrg
51648fb7bfaSmrg /* Set the 'version' number of the class, which is an integer that can
51748fb7bfaSmrg be used to track changes in the class API, methods and variables.
51848fb7bfaSmrg If 'class_' is Nil, does nothing.
51948fb7bfaSmrg
52048fb7bfaSmrg This is typically used internally by "Foundation" libraries such as
52148fb7bfaSmrg GNUstep Base to support serialization / deserialization of objects
52248fb7bfaSmrg that work across changes in the classes. If you are using such a
52348fb7bfaSmrg library, you probably want to use their versioning API, which may
52448fb7bfaSmrg be based on this one, but is integrated with the rest of the
52548fb7bfaSmrg library.
52648fb7bfaSmrg
52748fb7bfaSmrg Please note that internally the version is a long, but the API only
52848fb7bfaSmrg allows you to set and retrieve int values. */
52948fb7bfaSmrg objc_EXPORT void class_setVersion (Class class_, int version);
53048fb7bfaSmrg
53148fb7bfaSmrg /* Return the size in bytes (a byte is the size of a char) of an
53248fb7bfaSmrg instance of the class. If class_ is Nil, return 0; else it return
53348fb7bfaSmrg a non-zero number (since the 'isa' instance variable is required
53448fb7bfaSmrg for all classes). */
53548fb7bfaSmrg objc_EXPORT size_t class_getInstanceSize (Class class_);
53648fb7bfaSmrg
53748fb7bfaSmrg /* Change the implementation of the method. It also searches all
53848fb7bfaSmrg classes for any class implementing the method, and replaces the
53948fb7bfaSmrg existing implementation with the new one. For that to work,
54048fb7bfaSmrg 'method' must be a method returned by class_getInstanceMethod() or
54148fb7bfaSmrg class_getClassMethod() as the matching is done by comparing the
54248fb7bfaSmrg pointers; in that case, only the implementation in the class is
54348fb7bfaSmrg modified. Return the previous implementation that has been
54448fb7bfaSmrg replaced. If method or implementation is NULL, do nothing and
54548fb7bfaSmrg return NULL. */
54648fb7bfaSmrg objc_EXPORT IMP
54748fb7bfaSmrg method_setImplementation (Method method, IMP implementation);
54848fb7bfaSmrg
54948fb7bfaSmrg /* Swap the implementation of two methods in a single, atomic
55048fb7bfaSmrg operation. This is equivalent to getting the implementation of
55148fb7bfaSmrg each method and then calling method_setImplementation() on the
55248fb7bfaSmrg other one. For this to work, the two methods must have been
55348fb7bfaSmrg returned by class_getInstanceMethod() or class_getClassMethod().
55448fb7bfaSmrg If 'method_a' or 'method_b' is NULL, do nothing. */
55548fb7bfaSmrg objc_EXPORT void
55648fb7bfaSmrg method_exchangeImplementations (Method method_a, Method method_b);
55748fb7bfaSmrg
55848fb7bfaSmrg /* Create a new class/meta-class pair. This function is called to
55948fb7bfaSmrg create a new class at runtime. The class is created with
56048fb7bfaSmrg superclass 'superclass' (use 'Nil' to create a new root class) and
56148fb7bfaSmrg name 'class_name'. 'extraBytes' can be used to specify some extra
56248fb7bfaSmrg space for indexed variables to be added at the end of the class and
56348fb7bfaSmrg meta-class objects (it is recommended that you set extraBytes to
56448fb7bfaSmrg 0). Once you have created the class, it is not usable yet. You
56548fb7bfaSmrg need to add any instance variables (by using class_addIvar()), any
56648fb7bfaSmrg instance methods (by using class_addMethod()) and any class methods
56748fb7bfaSmrg (by using class_addMethod() on the meta-class, as in
56848fb7bfaSmrg class_addMethod (object_getClass (class), method)) that are
56948fb7bfaSmrg required, and then you need to call objc_registerClassPair() to
57048fb7bfaSmrg activate the class. If you need to create a hierarchy of classes,
57148fb7bfaSmrg you need to create and register them one at a time. You cannot
57248fb7bfaSmrg create a new class using another class in construction as
57348fb7bfaSmrg superclass. Return Nil if 'class-name' is NULL or if a class with
57448fb7bfaSmrg that name already exists or 'superclass' is a class still in
57548fb7bfaSmrg construction.
57648fb7bfaSmrg
57748fb7bfaSmrg Implementation Note: in the GNU runtime, allocating a class pair
57848fb7bfaSmrg only creates the structures for the class pair, but does not
57948fb7bfaSmrg register anything with the runtime. The class is registered with
58048fb7bfaSmrg the runtime only when objc_registerClassPair() is called. In
58148fb7bfaSmrg particular, if a class is in construction, objc_getClass() will not
58248fb7bfaSmrg find it, the superclass will not know about it,
58348fb7bfaSmrg class_getSuperclass() will return Nil and another thread may
58448fb7bfaSmrg allocate a class pair with the same name; the conflict will only be
58548fb7bfaSmrg detected when the classes are registered with the runtime.
58648fb7bfaSmrg */
58748fb7bfaSmrg objc_EXPORT Class
58848fb7bfaSmrg objc_allocateClassPair (Class super_class, const char *class_name,
58948fb7bfaSmrg size_t extraBytes);
59048fb7bfaSmrg
59148fb7bfaSmrg /* Register a class pair that was created with
59248fb7bfaSmrg objc_allocateClassPair(). After you register a class, you can no
59348fb7bfaSmrg longer make changes to its instance variables, but you can start
59448fb7bfaSmrg creating instances of it. Do nothing if 'class_' is NULL or if it
59548fb7bfaSmrg is not a class allocated by objc_allocateClassPair() and still in
59648fb7bfaSmrg construction. */
59748fb7bfaSmrg objc_EXPORT void
59848fb7bfaSmrg objc_registerClassPair (Class class_);
59948fb7bfaSmrg
60048fb7bfaSmrg /* Dispose of a class pair created using objc_allocateClassPair().
60148fb7bfaSmrg Call this function if you started creating a new class with
60248fb7bfaSmrg objc_allocateClassPair() but then want to abort the process. You
60348fb7bfaSmrg should not access 'class_' after calling this method. Note that if
60448fb7bfaSmrg 'class_' has already been registered with the runtime via
60548fb7bfaSmrg objc_registerClassPair(), this function does nothing; you can only
60648fb7bfaSmrg dispose of class pairs that are still being constructed. Do
60748fb7bfaSmrg nothing if class is 'Nil' or if 'class_' is not a class being
60848fb7bfaSmrg constructed. */
60948fb7bfaSmrg objc_EXPORT void
61048fb7bfaSmrg objc_disposeClassPair (Class class_);
61148fb7bfaSmrg
61248fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime has the function
61348fb7bfaSmrg objc_duplicateClass () but it's undocumented. The GNU runtime does
61448fb7bfaSmrg not have it. */
61548fb7bfaSmrg
61648fb7bfaSmrg
61748fb7bfaSmrg /** Implementation: the following functions are in sendmsg.c. */
61848fb7bfaSmrg
61948fb7bfaSmrg /* Return the instance method with selector 'selector' of class
62048fb7bfaSmrg 'class_', or NULL if the class (or one of its superclasses) does
62148fb7bfaSmrg not implement the method. Return NULL if class_ is Nil or selector
62248fb7bfaSmrg is NULL. Calling this function may trigger a call to
62348fb7bfaSmrg +resolveInstanceMethod:, but does not return a forwarding
62448fb7bfaSmrg function. */
62548fb7bfaSmrg objc_EXPORT Method class_getInstanceMethod (Class class_, SEL selector);
62648fb7bfaSmrg
62748fb7bfaSmrg /* Return the class method with selector 'selector' of class 'class_',
62848fb7bfaSmrg or NULL if the class (or one of its superclasses) does not
62948fb7bfaSmrg implement the method. Return NULL if class_ is Nil or selector is
63048fb7bfaSmrg NULL. Calling this function may trigger a call to
63148fb7bfaSmrg +resolveClassMethod:, but does not return a forwarding
63248fb7bfaSmrg function. */
63348fb7bfaSmrg objc_EXPORT Method class_getClassMethod (Class class_, SEL selector);
63448fb7bfaSmrg
63548fb7bfaSmrg /* Return the IMP (pointer to the function implementing a method) for
63648fb7bfaSmrg the instance method with selector 'selector' in class 'class_'.
63748fb7bfaSmrg This is the same routine that is used while messaging, and should
63848fb7bfaSmrg be very fast. Note that you most likely would need to cast the
63948fb7bfaSmrg return function pointer to a function pointer with the appropriate
64048fb7bfaSmrg arguments and return type before calling it. To get a class
64148fb7bfaSmrg method, you can pass the meta-class as the class_ argument (ie, use
64248fb7bfaSmrg class_getMethodImplementation (object_getClass (class_),
64348fb7bfaSmrg selector)). Return NULL if class_ is Nil or selector is NULL.
64448fb7bfaSmrg This function first looks for an existing method; if it is not
64548fb7bfaSmrg found, it calls +resolveClassMethod: or +resolveInstanceMethod:
64648fb7bfaSmrg (depending on whether a class or instance method is being looked
64748fb7bfaSmrg up) if it is implemented. If the method returns YES, then it tries
64848fb7bfaSmrg the look up again (the assumption being that +resolveClassMethod:
64948fb7bfaSmrg or resolveInstanceMethod: will add the method using
65048fb7bfaSmrg class_addMethod()). If it is still not found, it returns a
65148fb7bfaSmrg forwarding function. */
65248fb7bfaSmrg objc_EXPORT IMP class_getMethodImplementation (Class class_, SEL selector);
65348fb7bfaSmrg
65448fb7bfaSmrg /* Compatibility Note: the Apple/NeXT runtime has the function
65548fb7bfaSmrg class_getMethodImplementation_stret () which currently does not
65648fb7bfaSmrg exist on the GNU runtime because the messaging implementation is
65748fb7bfaSmrg different. */
65848fb7bfaSmrg
65948fb7bfaSmrg /* Return YES if class 'class_' has an instance method implementing
66048fb7bfaSmrg selector 'selector', and NO if not. Return NO if class_ is Nil or
66148fb7bfaSmrg selector is NULL. If you need to check a class method, use the
66248fb7bfaSmrg meta-class as the class_ argument (ie, use class_respondsToSelector
66348fb7bfaSmrg (object_getClass (class_), selector)). */
66448fb7bfaSmrg objc_EXPORT BOOL class_respondsToSelector (Class class_, SEL selector);
66548fb7bfaSmrg
66648fb7bfaSmrg /* Add a method to a class. Use this function to add a new method to
66748fb7bfaSmrg a class (potentially overriding a method with the same selector in
66848fb7bfaSmrg the superclass); if you want to modify an existing method, use
66948fb7bfaSmrg method_setImplementation() instead (or class_replaceMethod ()).
67048fb7bfaSmrg This method adds an instance method to 'class_'; to add a class
67148fb7bfaSmrg method, get the meta class first, then add the method to the meta
67248fb7bfaSmrg class, that is, use
67348fb7bfaSmrg
67448fb7bfaSmrg class_addMethod (object_getClass (class_), selector,
67548fb7bfaSmrg implementation, type);
67648fb7bfaSmrg
67748fb7bfaSmrg Return YES if the method was added, and NO if not. Do nothing if
67848fb7bfaSmrg one of the arguments is NULL. */
67948fb7bfaSmrg objc_EXPORT BOOL class_addMethod (Class class_, SEL selector, IMP implementation,
68048fb7bfaSmrg const char *method_types);
68148fb7bfaSmrg
68248fb7bfaSmrg /* Replace a method in a class. If the class already have a method
68348fb7bfaSmrg with this 'selector', find it and use method_setImplementation() to
68448fb7bfaSmrg replace the implementation with 'implementation' (method_types is
68548fb7bfaSmrg ignored in that case). If the class does not already have a method
68648fb7bfaSmrg with this 'selector', call 'class_addMethod() to add it.
68748fb7bfaSmrg
68848fb7bfaSmrg Return the previous implementation of the method, or NULL if none
68948fb7bfaSmrg was found. Return NULL if any of the arguments is NULL. */
69048fb7bfaSmrg objc_EXPORT IMP class_replaceMethod (Class class_, SEL selector, IMP implementation,
69148fb7bfaSmrg const char *method_types);
69248fb7bfaSmrg
69348fb7bfaSmrg
69448fb7bfaSmrg /** Implementation: the following functions are in methods.c. */
69548fb7bfaSmrg
69648fb7bfaSmrg /* Return the selector for method 'method'. Return NULL if 'method'
69748fb7bfaSmrg is NULL.
69848fb7bfaSmrg
69948fb7bfaSmrg This function is misnamed; it should be called
70048fb7bfaSmrg 'method_getSelector'. To get the actual name, get the selector,
70148fb7bfaSmrg then the name from the selector (ie, use sel_getName
70248fb7bfaSmrg (method_getName (method))). */
70348fb7bfaSmrg objc_EXPORT SEL method_getName (Method method);
70448fb7bfaSmrg
70548fb7bfaSmrg /* Return the IMP of the method. Return NULL if 'method' is NULL. */
70648fb7bfaSmrg objc_EXPORT IMP method_getImplementation (Method method);
70748fb7bfaSmrg
70848fb7bfaSmrg /* Return the type encoding of the method. Return NULL if 'method' is
70948fb7bfaSmrg NULL. */
71048fb7bfaSmrg objc_EXPORT const char * method_getTypeEncoding (Method method);
71148fb7bfaSmrg
71248fb7bfaSmrg /* Return a method description for the method. Return NULL if
71348fb7bfaSmrg 'method' is NULL. */
71448fb7bfaSmrg objc_EXPORT struct objc_method_description * method_getDescription (Method method);
71548fb7bfaSmrg
71648fb7bfaSmrg /* Return all the instance methods of the class. The return value of
71748fb7bfaSmrg the function is a pointer to an area, allocated with malloc(), that
71848fb7bfaSmrg contains all the instance methods of the class. It does not
71948fb7bfaSmrg include instance methods of superclasses. The list is terminated
72048fb7bfaSmrg by NULL. Optionally, if you pass a non-NULL
72148fb7bfaSmrg 'numberOfReturnedMethods' pointer, the unsigned int that it points
72248fb7bfaSmrg to will be filled with the number of instance methods returned. To
72348fb7bfaSmrg get the list of class methods, pass the meta-class in the 'class_'
72448fb7bfaSmrg argument, (ie, use class_copyMethodList (object_getClass (class_),
72548fb7bfaSmrg &numberOfReturnedMethods)). */
72648fb7bfaSmrg objc_EXPORT Method * class_copyMethodList (Class class_, unsigned int *numberOfReturnedMethods);
72748fb7bfaSmrg
72848fb7bfaSmrg
72948fb7bfaSmrg /** Implementation: the following functions are in encoding.c. */
73048fb7bfaSmrg
73148fb7bfaSmrg /* Return the number of arguments that the method 'method' expects.
73248fb7bfaSmrg Note that all methods need two implicit arguments ('self' for the
73348fb7bfaSmrg receiver, and '_cmd' for the selector). Return 0 if 'method' is
73448fb7bfaSmrg NULL. */
73548fb7bfaSmrg objc_EXPORT unsigned int method_getNumberOfArguments (Method method);
73648fb7bfaSmrg
73748fb7bfaSmrg /* Return the string encoding for the return type of method 'method'.
73848fb7bfaSmrg The string is a standard zero-terminated string in an area of
73948fb7bfaSmrg memory allocated with malloc(); you should free it with free() when
74048fb7bfaSmrg you finish using it. Return an empty string if method is NULL. */
74148fb7bfaSmrg objc_EXPORT char * method_copyReturnType (Method method);
74248fb7bfaSmrg
74348fb7bfaSmrg /* Return the string encoding for the argument type of method
74448fb7bfaSmrg 'method', argument number 'argumentNumber' ('argumentNumber' is 0
74548fb7bfaSmrg for self, 1 for _cmd, and 2 or more for the additional arguments if
74648fb7bfaSmrg any). The string is a standard zero-terminated string in an area
74748fb7bfaSmrg of memory allocated with malloc(); you should free it with free()
74848fb7bfaSmrg when you finish using it. Return an empty string if method is NULL
74948fb7bfaSmrg or if 'argumentNumber' refers to a non-existing argument. */
75048fb7bfaSmrg objc_EXPORT char * method_copyArgumentType (Method method, unsigned int argumentNumber);
75148fb7bfaSmrg
75248fb7bfaSmrg /* Return the string encoding for the return type of method 'method'.
75348fb7bfaSmrg The string is returned by copying it into the supplied
75448fb7bfaSmrg 'returnValue' string, which is of size 'returnValueSize'. No more
75548fb7bfaSmrg than 'returnValueSize' characters are copied; if the encoding is
75648fb7bfaSmrg smaller than 'returnValueSize', the rest of 'returnValue' is filled
75748fb7bfaSmrg with zeros. If it is bigger, it is truncated (and would not be
75848fb7bfaSmrg zero-terminated). You should supply a big enough
75948fb7bfaSmrg 'returnValueSize'. If the method is NULL, returnValue is set to a
76048fb7bfaSmrg string of zeros. */
76148fb7bfaSmrg objc_EXPORT void method_getReturnType (Method method, char *returnValue,
76248fb7bfaSmrg size_t returnValueSize);
76348fb7bfaSmrg
76448fb7bfaSmrg /* Return the string encoding for the argument type of method
76548fb7bfaSmrg 'method', argument number 'argumentNumber' ('argumentNumber' is 0
76648fb7bfaSmrg for self, 1 for _cmd, and 2 or more for the additional arguments if
76748fb7bfaSmrg any). The string is returned by copying it into the supplied
76848fb7bfaSmrg 'returnValue' string, which is of size 'returnValueSize'. No more
76948fb7bfaSmrg than 'returnValueSize' characters are copied; if the encoding is
77048fb7bfaSmrg smaller than 'returnValueSize', the rest of 'returnValue' is filled
77148fb7bfaSmrg with zeros. If it is bigger, it is truncated (and would not be
77248fb7bfaSmrg zero-terminated). You should supply a big enough
77348fb7bfaSmrg 'returnValueSize'. If the method is NULL, returnValue is set to a
77448fb7bfaSmrg string of zeros. */
77548fb7bfaSmrg objc_EXPORT void method_getArgumentType (Method method, unsigned int argumentNumber,
77648fb7bfaSmrg char *returnValue, size_t returnValueSize);
77748fb7bfaSmrg
77848fb7bfaSmrg
77948fb7bfaSmrg /** Implementation: the following functions are in protocols.c. */
78048fb7bfaSmrg
78148fb7bfaSmrg /* Return the protocol with name 'name', or nil if it the protocol is
78248fb7bfaSmrg not known to the runtime. */
78348fb7bfaSmrg objc_EXPORT Protocol *objc_getProtocol (const char *name);
78448fb7bfaSmrg
78548fb7bfaSmrg /* Return all the protocols known to the runtime. The return value of
78648fb7bfaSmrg the function is a pointer to an area, allocated with malloc(), that
78748fb7bfaSmrg contains all the protocols known to the runtime; the list is
78848fb7bfaSmrg terminated by NULL. You should free this area using free() once
78948fb7bfaSmrg you no longer need it. Optionally, if you pass a non-NULL
79048fb7bfaSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
79148fb7bfaSmrg points to will be filled with the number of protocols returned. If
79248fb7bfaSmrg there are no protocols known to the runtime, NULL is returned. */
79348fb7bfaSmrg objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProtocols);
79448fb7bfaSmrg
79548fb7bfaSmrg /* Add a protocol to a class, and return YES if it was done
7964d5abbe8Smrg successfully, and NO if not. At the moment, NO should only happen
79748fb7bfaSmrg if class_ or protocol are nil, if the protocol is not a Protocol
79848fb7bfaSmrg object or if the class already conforms to the protocol. */
79948fb7bfaSmrg objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol);
80048fb7bfaSmrg
80148fb7bfaSmrg /* Return YES if the class 'class_' conforms to Protocol 'protocol',
80248fb7bfaSmrg and NO if not. This function does not check superclasses; if you
80348fb7bfaSmrg want to check for superclasses (in the way that [NSObject
80448fb7bfaSmrg +conformsToProtocol:] does) you need to iterate over the class
80548fb7bfaSmrg hierarchy using class_getSuperclass(), and call
80648fb7bfaSmrg class_conformsToProtocol() for each of them. */
80748fb7bfaSmrg objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol);
80848fb7bfaSmrg
80948fb7bfaSmrg /* Return all the protocols that the class conforms to. The return
81048fb7bfaSmrg value of the function is a pointer to an area, allocated with
81148fb7bfaSmrg malloc(), that contains all the protocols formally adopted by the
81248fb7bfaSmrg class. It does not include protocols adopted by superclasses. The
81348fb7bfaSmrg list is terminated by NULL. Optionally, if you pass a non-NULL
81448fb7bfaSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
81548fb7bfaSmrg points to will be filled with the number of protocols returned.
81648fb7bfaSmrg This function does not return protocols that superclasses conform
81748fb7bfaSmrg to. */
81848fb7bfaSmrg objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols);
81948fb7bfaSmrg
82048fb7bfaSmrg /* Return YES if protocol 'protocol' conforms to protocol
82148fb7bfaSmrg 'anotherProtocol', and NO if not. Note that if one of the two
82248fb7bfaSmrg protocols is nil, it returns NO. */
82348fb7bfaSmrg objc_EXPORT BOOL protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol);
82448fb7bfaSmrg
82548fb7bfaSmrg /* Return YES if protocol 'protocol' is the same as protocol
82648fb7bfaSmrg 'anotherProtocol', and 'NO' if not. Note that it returns YES if
82748fb7bfaSmrg the two protocols are both nil. */
82848fb7bfaSmrg objc_EXPORT BOOL protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol);
82948fb7bfaSmrg
83048fb7bfaSmrg /* Return the name of protocol 'protocol'. If 'protocol' is nil or is
83148fb7bfaSmrg not a Protocol, return NULL. */
83248fb7bfaSmrg objc_EXPORT const char *protocol_getName (Protocol *protocol);
83348fb7bfaSmrg
83448fb7bfaSmrg /* Return the method description for the method with selector
83548fb7bfaSmrg 'selector' in protocol 'protocol'; if 'requiredMethod' is YES, the
83648fb7bfaSmrg function searches the list of required methods; if NO, the list of
83748fb7bfaSmrg optional methods. If 'instanceMethod' is YES, the function search
83848fb7bfaSmrg for an instance method; if NO, for a class method. If there is no
83948fb7bfaSmrg matching method, an objc_method_description structure with both
84048fb7bfaSmrg name and types set to NULL is returned. This function will only
84148fb7bfaSmrg find methods that are directly declared in the protocol itself, not
84248fb7bfaSmrg in other protocols that this protocol adopts.
84348fb7bfaSmrg
84448fb7bfaSmrg Note that the traditional ABI does not store the list of optional
84548fb7bfaSmrg methods of a protocol in a compiled module, so the traditional ABI
84648fb7bfaSmrg will always return (NULL, NULL) when requiredMethod == NO. */
84748fb7bfaSmrg objc_EXPORT struct objc_method_description protocol_getMethodDescription (Protocol *protocol,
84848fb7bfaSmrg SEL selector,
84948fb7bfaSmrg BOOL requiredMethod,
85048fb7bfaSmrg BOOL instanceMethod);
85148fb7bfaSmrg
85248fb7bfaSmrg /* Return the method descriptions of all the methods of the protocol.
85348fb7bfaSmrg The return value of the function is a pointer to an area, allocated
85448fb7bfaSmrg with malloc(), that contains all the method descriptions of the
85548fb7bfaSmrg methods of the protocol. It does not recursively include methods
85648fb7bfaSmrg of the protocols adopted by this protocol. The list is terminated
85748fb7bfaSmrg by a NULL objc_method_description (one with both fields set to
85848fb7bfaSmrg NULL). Optionally, if you pass a non-NULL
85948fb7bfaSmrg 'numberOfReturnedMethods' pointer, the unsigned int that it points
86048fb7bfaSmrg to will be filled with the number of properties returned.
86148fb7bfaSmrg
86248fb7bfaSmrg Note that the traditional ABI does not store the list of optional
86348fb7bfaSmrg methods of a protocol in a compiled module, so the traditional ABI
86448fb7bfaSmrg will always return an empty list if requiredMethod is set to
86548fb7bfaSmrg NO. */
86648fb7bfaSmrg objc_EXPORT struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *protocol,
86748fb7bfaSmrg BOOL requiredMethod,
86848fb7bfaSmrg BOOL instanceMethod,
86948fb7bfaSmrg unsigned int *numberOfReturnedMethods);
87048fb7bfaSmrg
87148fb7bfaSmrg /* Return the property with name 'propertyName' of the protocol
87248fb7bfaSmrg 'protocol'. If 'requiredProperty' is YES, the function searches
87348fb7bfaSmrg the list of required properties; if NO, the list of optional
87448fb7bfaSmrg properties. If 'instanceProperty' is YES, the function searches
87548fb7bfaSmrg the list of instance properties; if NO, the list of class
87648fb7bfaSmrg properties. At the moment, optional properties and class
87748fb7bfaSmrg properties are not part of the Objective-C language, so both
87848fb7bfaSmrg 'requiredProperty' and 'instanceProperty' should be set to YES.
87948fb7bfaSmrg This function returns NULL if the required property cannot be
88048fb7bfaSmrg found.
88148fb7bfaSmrg
88248fb7bfaSmrg Note that the traditional ABI does not store the list of properties
88348fb7bfaSmrg of a protocol in a compiled module, so the traditional ABI will
88448fb7bfaSmrg always return NULL. */
88548fb7bfaSmrg objc_EXPORT Property protocol_getProperty (Protocol *protocol, const char *propertyName,
88648fb7bfaSmrg BOOL requiredProperty, BOOL instanceProperty);
88748fb7bfaSmrg
88848fb7bfaSmrg /* Return all the properties of the protocol. The return value of the
88948fb7bfaSmrg function is a pointer to an area, allocated with malloc(), that
89048fb7bfaSmrg contains all the properties of the protocol. It does not
89148fb7bfaSmrg recursively include properties of the protocols adopted by this
89248fb7bfaSmrg protocol. The list is terminated by NULL. Optionally, if you pass
89348fb7bfaSmrg a non-NULL 'numberOfReturnedProperties' pointer, the unsigned int
89448fb7bfaSmrg that it points to will be filled with the number of properties
89548fb7bfaSmrg returned.
89648fb7bfaSmrg
89748fb7bfaSmrg Note that the traditional ABI does not store the list of properties
89848fb7bfaSmrg of a protocol in a compiled module, so the traditional ABI will
89948fb7bfaSmrg always return NULL and store 0 in numberOfReturnedProperties. */
90048fb7bfaSmrg objc_EXPORT Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfReturnedProperties);
90148fb7bfaSmrg
90248fb7bfaSmrg /* Return all the protocols that the protocol conforms to. The return
90348fb7bfaSmrg value of the function is a pointer to an area, allocated with
90448fb7bfaSmrg malloc(), that contains all the protocols formally adopted by the
90548fb7bfaSmrg protocol. It does not recursively include protocols adopted by the
90648fb7bfaSmrg protocols adopted by this protocol. The list is terminated by
90748fb7bfaSmrg NULL. Optionally, if you pass a non-NULL
90848fb7bfaSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
90948fb7bfaSmrg points to will be filled with the number of protocols returned. */
91048fb7bfaSmrg objc_EXPORT Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOfReturnedProtocols);
91148fb7bfaSmrg
91248fb7bfaSmrg
91348fb7bfaSmrg /** Implementation: the following hook is in init.c. */
91448fb7bfaSmrg
91548fb7bfaSmrg /* This is a hook which is called by __objc_exec_class every time a
91648fb7bfaSmrg class or a category is loaded into the runtime. This may e.g. help
91748fb7bfaSmrg a dynamic loader determine the classes that have been loaded when
91848fb7bfaSmrg an object file is dynamically linked in. */
91948fb7bfaSmrg objc_EXPORT void (*_objc_load_callback)(Class _class, struct objc_category *category);
92048fb7bfaSmrg
92148fb7bfaSmrg
92248fb7bfaSmrg /** Implementation: the following functions are in objc-foreach.c. */
92348fb7bfaSmrg
92448fb7bfaSmrg /* 'objc_enumerationMutation()' is called when a collection is
92548fb7bfaSmrg mutated while being "fast enumerated". That is a hard error, and
92648fb7bfaSmrg objc_enumerationMutation is called to deal with it. 'collection'
92748fb7bfaSmrg is the collection object that was mutated during an enumeration.
92848fb7bfaSmrg
92948fb7bfaSmrg objc_enumerationMutation() will invoke the mutation handler if any
93048fb7bfaSmrg is set. Then, it will abort the program.
93148fb7bfaSmrg
93248fb7bfaSmrg Compatibility note: the Apple runtime will not abort the program
93348fb7bfaSmrg after calling the mutation handler. */
93448fb7bfaSmrg objc_EXPORT void objc_enumerationMutation (id collection);
93548fb7bfaSmrg
93648fb7bfaSmrg /* 'objc_set_enumeration_mutation_handler' can be used to set a
93748fb7bfaSmrg function that will be called (instead of aborting) when a fast
93848fb7bfaSmrg enumeration is mutated during enumeration. The handler will be
93948fb7bfaSmrg called with the 'collection' being mutated as the only argument and
94048fb7bfaSmrg it should not return; it should either exit the program, or could
94148fb7bfaSmrg throw an exception. The recommended implementation is to throw an
94248fb7bfaSmrg exception - the user can then use exception handlers to deal with
94348fb7bfaSmrg it.
94448fb7bfaSmrg
94548fb7bfaSmrg This function is not thread safe (other threads may be trying to
94648fb7bfaSmrg invoke the enumeration mutation handler while you are changing it!)
94748fb7bfaSmrg and should be called during during the program initialization
94848fb7bfaSmrg before threads are started. It is mostly reserved for "Foundation"
94948fb7bfaSmrg libraries; in the case of GNUstep, GNUstep Base may be using this
95048fb7bfaSmrg function to improve the standard enumeration mutation handling.
95148fb7bfaSmrg You probably shouldn't use this function unless you are writing
95248fb7bfaSmrg your own Foundation library. */
95348fb7bfaSmrg objc_EXPORT void objc_setEnumerationMutationHandler (void (*handler)(id));
95448fb7bfaSmrg
95548fb7bfaSmrg /* This structure (used during fast enumeration) is automatically
95648fb7bfaSmrg defined by the compiler (it is as if this definition was always
95748fb7bfaSmrg included in all Objective-C files). Note that it is usually
95848fb7bfaSmrg defined again with the name of NSFastEnumeration by "Foundation"
95948fb7bfaSmrg libraries such as GNUstep Base. And if NSFastEnumeration is
96048fb7bfaSmrg defined, the compiler will use it instead of
96148fb7bfaSmrg __objcFastEnumerationState when doing fast enumeration. */
96248fb7bfaSmrg /*
96348fb7bfaSmrg struct __objcFastEnumerationState
96448fb7bfaSmrg {
96548fb7bfaSmrg unsigned long state;
96648fb7bfaSmrg id *itemsPtr;
96748fb7bfaSmrg unsigned long *mutationsPtr;
96848fb7bfaSmrg unsigned long extra[5];
96948fb7bfaSmrg };
97048fb7bfaSmrg */
97148fb7bfaSmrg
97248fb7bfaSmrg
97348fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime has the functions
97448fb7bfaSmrg objc_copyImageNames (), class_getImageName () and
97548fb7bfaSmrg objc_copyClassNamesForImage () but they are undocumented. The GNU
97648fb7bfaSmrg runtime does not have them at the moment. */
97748fb7bfaSmrg
97848fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime has the functions
97948fb7bfaSmrg objc_setAssociatedObject (), objc_getAssociatedObject (),
98048fb7bfaSmrg objc_removeAssociatedObjects () and the objc_AssociationPolicy type
98148fb7bfaSmrg and related enum. The GNU runtime does not have them yet.
98248fb7bfaSmrg TODO: Implement them. */
98348fb7bfaSmrg
98448fb7bfaSmrg /* Compatibility Note: The Apple/NeXT runtime has the function
98548fb7bfaSmrg objc_setForwardHandler (). The GNU runtime does not have it
98648fb7bfaSmrg because messaging (and, in particular, forwarding) works in a
98748fb7bfaSmrg different (incompatible) way with the GNU runtime. If you need to
98848fb7bfaSmrg customize message forwarding at the Objective-C runtime level (that
98948fb7bfaSmrg is, if you are implementing your own "Foundation" library such as
99048fb7bfaSmrg GNUstep Base on top of the Objective-C runtime), in objc/message.h
99148fb7bfaSmrg there are hooks (that work in the framework of the GNU runtime) to
99248fb7bfaSmrg do so. */
99348fb7bfaSmrg
99448fb7bfaSmrg
99548fb7bfaSmrg /** Implementation: the following functions are in memory.c. */
99648fb7bfaSmrg
99748fb7bfaSmrg /* Traditional GNU Objective-C Runtime functions that are used for
99848fb7bfaSmrg memory allocation and disposal. These functions are used in the
99948fb7bfaSmrg same way as you use malloc, realloc, calloc and free and make sure
100048fb7bfaSmrg that memory allocation works properly with the garbage
100148fb7bfaSmrg collector.
100248fb7bfaSmrg
100348fb7bfaSmrg Compatibility Note: these functions are not available with the
100448fb7bfaSmrg Apple/NeXT runtime. */
100548fb7bfaSmrg
100648fb7bfaSmrg objc_EXPORT void *objc_malloc(size_t size);
100748fb7bfaSmrg
100848fb7bfaSmrg /* FIXME: Shouldn't the following be called objc_malloc_atomic ? The
100948fb7bfaSmrg GC function is GC_malloc_atomic() which makes sense.
101048fb7bfaSmrg */
101148fb7bfaSmrg objc_EXPORT void *objc_atomic_malloc(size_t size);
101248fb7bfaSmrg
101348fb7bfaSmrg objc_EXPORT void *objc_realloc(void *mem, size_t size);
101448fb7bfaSmrg
101548fb7bfaSmrg objc_EXPORT void *objc_calloc(size_t nelem, size_t size);
101648fb7bfaSmrg
101748fb7bfaSmrg objc_EXPORT void objc_free(void *mem);
101848fb7bfaSmrg
101948fb7bfaSmrg
102048fb7bfaSmrg /** Implementation: the following functions are in gc.c. */
102148fb7bfaSmrg
102248fb7bfaSmrg /* The GNU Objective-C Runtime has a different implementation of
102348fb7bfaSmrg garbage collection.
102448fb7bfaSmrg
102548fb7bfaSmrg Compatibility Note: these functions are not available with the
102648fb7bfaSmrg Apple/NeXT runtime. */
102748fb7bfaSmrg
102848fb7bfaSmrg /* Mark the instance variable as inaccessible to the garbage
102948fb7bfaSmrg collector. */
103048fb7bfaSmrg objc_EXPORT void class_ivar_set_gcinvisible (Class _class,
103148fb7bfaSmrg const char* ivarname,
103248fb7bfaSmrg BOOL gcInvisible);
103348fb7bfaSmrg
103448fb7bfaSmrg
103548fb7bfaSmrg /** Implementation: the following functions are in encoding.c. */
103648fb7bfaSmrg
103748fb7bfaSmrg /* Traditional GNU Objective-C Runtime functions that are currently
103848fb7bfaSmrg used to implement method forwarding.
103948fb7bfaSmrg
104048fb7bfaSmrg Compatibility Note: these functions are not available with the
104148fb7bfaSmrg Apple/NeXT runtime. */
104248fb7bfaSmrg
104348fb7bfaSmrg /* Return the size of a variable which has the specified 'type'
104448fb7bfaSmrg encoding. */
104548fb7bfaSmrg objc_EXPORT int objc_sizeof_type (const char *type);
104648fb7bfaSmrg
104748fb7bfaSmrg /* Return the align of a variable which has the specified 'type'
104848fb7bfaSmrg encoding. */
104948fb7bfaSmrg objc_EXPORT int objc_alignof_type (const char *type);
105048fb7bfaSmrg
105148fb7bfaSmrg /* Return the aligned size of a variable which has the specified
105248fb7bfaSmrg 'type' encoding. The aligned size is the size rounded up to the
105348fb7bfaSmrg nearest alignment. */
105448fb7bfaSmrg objc_EXPORT int objc_aligned_size (const char *type);
105548fb7bfaSmrg
105648fb7bfaSmrg /* Return the promoted size of a variable which has the specified
105748fb7bfaSmrg 'type' encoding. This is the size rounded up to the nearest
105848fb7bfaSmrg integral of the wordsize, taken to be the size of a void *. */
105948fb7bfaSmrg objc_EXPORT int objc_promoted_size (const char *type);
106048fb7bfaSmrg
106148fb7bfaSmrg
106248fb7bfaSmrg /* The following functions are used when parsing the type encoding of
106348fb7bfaSmrg methods, to skip over parts that are ignored. They take as
106448fb7bfaSmrg argument a pointer to a location inside the type encoding of a
106548fb7bfaSmrg method (which is a string) and return a new pointer, pointing to a
106648fb7bfaSmrg new location inside the string after having skipped the unwanted
106748fb7bfaSmrg information. */
106848fb7bfaSmrg
106948fb7bfaSmrg /* Skip some type qualifiers (_C_CONST, _C_IN, etc). These may
107048fb7bfaSmrg eventually precede typespecs occurring in method prototype
107148fb7bfaSmrg encodings. */
107248fb7bfaSmrg objc_EXPORT const char *objc_skip_type_qualifiers (const char *type);
107348fb7bfaSmrg
107448fb7bfaSmrg /* Skip one typespec element (_C_CLASS, _C_SEL, etc). If the typespec
107548fb7bfaSmrg is prepended by type qualifiers, these are skipped as well. */
107648fb7bfaSmrg objc_EXPORT const char *objc_skip_typespec (const char *type);
107748fb7bfaSmrg
107848fb7bfaSmrg /* Skip an offset. */
107948fb7bfaSmrg objc_EXPORT const char *objc_skip_offset (const char *type);
108048fb7bfaSmrg
108148fb7bfaSmrg /* Skip an argument specification (ie, skipping a typespec, which may
108248fb7bfaSmrg include qualifiers, and an offset too). */
108348fb7bfaSmrg objc_EXPORT const char *objc_skip_argspec (const char *type);
108448fb7bfaSmrg
108548fb7bfaSmrg /* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type'
108648fb7bfaSmrg (stopping at the first non-type qualifier found) and return an
108748fb7bfaSmrg unsigned int which is the logical OR of all the corresponding flags
108848fb7bfaSmrg (_F_CONST, _F_IN etc). */
108948fb7bfaSmrg objc_EXPORT unsigned objc_get_type_qualifiers (const char *type);
109048fb7bfaSmrg
109148fb7bfaSmrg
109248fb7bfaSmrg /* Note that the following functions work for very simple structures,
109348fb7bfaSmrg but get easily confused by more complicated ones (for example,
109448fb7bfaSmrg containing vectors). A better solution is required. These
109548fb7bfaSmrg functions are likely to change in the next GCC release. */
109648fb7bfaSmrg
109748fb7bfaSmrg /* The following three functions can be used to determine how a
109848fb7bfaSmrg structure is laid out by the compiler. For example:
109948fb7bfaSmrg
110048fb7bfaSmrg struct objc_struct_layout layout;
110148fb7bfaSmrg int i;
110248fb7bfaSmrg
110348fb7bfaSmrg objc_layout_structure (type, &layout);
110448fb7bfaSmrg while (objc_layout_structure_next_member (&layout))
110548fb7bfaSmrg {
110648fb7bfaSmrg int position, align;
110748fb7bfaSmrg const char *type;
110848fb7bfaSmrg
110948fb7bfaSmrg objc_layout_structure_get_info (&layout, &position, &align, &type);
111048fb7bfaSmrg printf ("element %d has offset %d, alignment %d\n",
111148fb7bfaSmrg i++, position, align);
111248fb7bfaSmrg }
111348fb7bfaSmrg
111448fb7bfaSmrg These functions are used by objc_sizeof_type and objc_alignof_type
111548fb7bfaSmrg functions to compute the size and alignment of structures. The
111648fb7bfaSmrg previous method of computing the size and alignment of a structure
11174d5abbe8Smrg was not working on some architectures, particularly on AIX, and in
111848fb7bfaSmrg the presence of bitfields inside the structure. */
111948fb7bfaSmrg struct objc_struct_layout
112048fb7bfaSmrg {
112148fb7bfaSmrg const char *original_type;
112248fb7bfaSmrg const char *type;
112348fb7bfaSmrg const char *prev_type;
112448fb7bfaSmrg unsigned int record_size;
112548fb7bfaSmrg unsigned int record_align;
112648fb7bfaSmrg };
112748fb7bfaSmrg
112848fb7bfaSmrg objc_EXPORT void objc_layout_structure (const char *type,
112948fb7bfaSmrg struct objc_struct_layout *layout);
113048fb7bfaSmrg objc_EXPORT BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);
113148fb7bfaSmrg objc_EXPORT void objc_layout_finish_structure (struct objc_struct_layout *layout,
113248fb7bfaSmrg unsigned int *size,
113348fb7bfaSmrg unsigned int *align);
113448fb7bfaSmrg objc_EXPORT void objc_layout_structure_get_info (struct objc_struct_layout *layout,
113548fb7bfaSmrg unsigned int *offset,
113648fb7bfaSmrg unsigned int *align,
113748fb7bfaSmrg const char **type);
11384fee23f9Smrg
11394fee23f9Smrg #ifdef __cplusplus
11404fee23f9Smrg }
11414fee23f9Smrg #endif /* __cplusplus */
11424fee23f9Smrg
114348fb7bfaSmrg #endif
1144