136ac495dSmrg /* GNU Objective-C Runtime API - Modern API
2*8feb0f0bSmrg Copyright (C) 2010-2020 Free Software Foundation, Inc.
336ac495dSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
436ac495dSmrg
536ac495dSmrg This file is part of GCC.
636ac495dSmrg
736ac495dSmrg GCC is free software; you can redistribute it and/or modify it
836ac495dSmrg under the terms of the GNU General Public License as published by the
936ac495dSmrg Free Software Foundation; either version 3, or (at your option) any
1036ac495dSmrg later version.
1136ac495dSmrg
1236ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT
1336ac495dSmrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1436ac495dSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
1536ac495dSmrg License for more details.
1636ac495dSmrg
1736ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
1836ac495dSmrg permissions described in the GCC Runtime Library Exception, version
1936ac495dSmrg 3.1, as published by the Free Software Foundation.
2036ac495dSmrg
2136ac495dSmrg You should have received a copy of the GNU General Public License and
2236ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
2336ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2436ac495dSmrg <http://www.gnu.org/licenses/>. */
2536ac495dSmrg
2636ac495dSmrg #ifndef __objc_runtime_INCLUDE_GNU
2736ac495dSmrg #define __objc_runtime_INCLUDE_GNU
2836ac495dSmrg
2936ac495dSmrg /*
3036ac495dSmrg This file declares the "modern" GNU Objective-C Runtime API.
3136ac495dSmrg
3236ac495dSmrg This API replaced the "traditional" GNU Objective-C Runtime API
3336ac495dSmrg (which used to be declared in objc/objc-api.h) which is the one
3436ac495dSmrg supported by older versions of the GNU Objective-C Runtime. The
3536ac495dSmrg "modern" API is very similar to the API used by the modern
3636ac495dSmrg Apple/NeXT runtime.
3736ac495dSmrg */
3836ac495dSmrg #include "objc.h"
3936ac495dSmrg #include "objc-decls.h"
4036ac495dSmrg
4136ac495dSmrg #ifdef __cplusplus
4236ac495dSmrg extern "C" {
4336ac495dSmrg #endif /* __cplusplus */
4436ac495dSmrg
4536ac495dSmrg /* An 'Ivar' represents an instance variable. It holds information
4636ac495dSmrg about the name, type and offset of the instance variable. */
4736ac495dSmrg typedef struct objc_ivar *Ivar;
4836ac495dSmrg
4936ac495dSmrg /* A 'Property' represents a property. It holds information about the
5036ac495dSmrg name of the property, and its attributes.
5136ac495dSmrg
5236ac495dSmrg Compatibility Note: the Apple/NeXT runtime defines this as
5336ac495dSmrg objc_property_t, so we define it that way as well, but obviously
5436ac495dSmrg Property is the right name. */
5536ac495dSmrg typedef struct objc_property *Property;
5636ac495dSmrg typedef struct objc_property *objc_property_t;
5736ac495dSmrg
5836ac495dSmrg /* A 'Method' represents a method. It holds information about the
5936ac495dSmrg name, types and the IMP of the method. */
6036ac495dSmrg typedef struct objc_method *Method;
6136ac495dSmrg
6236ac495dSmrg /* A 'Category' represents a category. It holds information about the
6336ac495dSmrg name of the category, the class it belongs to, and the methods,
6436ac495dSmrg protocols and such like provided by the category. */
6536ac495dSmrg typedef struct objc_category *Category;
6636ac495dSmrg
6736ac495dSmrg /* 'Protocol' is defined in objc/objc.h (which is included by this
6836ac495dSmrg file). */
6936ac495dSmrg
7036ac495dSmrg /* Method descriptor returned by introspective Object methods. At the
7136ac495dSmrg moment, this is really just the first part of the more complete
7236ac495dSmrg objc_method structure used internally by the runtime. (PS: In the
7336ac495dSmrg GNU Objective-C Runtime, selectors already include a type, so an
7436ac495dSmrg objc_method_description does not add much to a SEL. But in other
7536ac495dSmrg runtimes, that is not the case, which is why
7636ac495dSmrg objc_method_description exists). */
7736ac495dSmrg struct objc_method_description
7836ac495dSmrg {
7936ac495dSmrg SEL name; /* Selector (name and signature) */
8036ac495dSmrg char *types; /* Type encoding */
8136ac495dSmrg };
8236ac495dSmrg
8336ac495dSmrg /* The following are used in encode strings to describe the type of
8436ac495dSmrg Ivars and Methods. */
8536ac495dSmrg #define _C_ID '@'
8636ac495dSmrg #define _C_CLASS '#'
8736ac495dSmrg #define _C_SEL ':'
8836ac495dSmrg #define _C_CHR 'c'
8936ac495dSmrg #define _C_UCHR 'C'
9036ac495dSmrg #define _C_SHT 's'
9136ac495dSmrg #define _C_USHT 'S'
9236ac495dSmrg #define _C_INT 'i'
9336ac495dSmrg #define _C_UINT 'I'
9436ac495dSmrg #define _C_LNG 'l'
9536ac495dSmrg #define _C_ULNG 'L'
9636ac495dSmrg #define _C_LNG_LNG 'q'
9736ac495dSmrg #define _C_ULNG_LNG 'Q'
9836ac495dSmrg #define _C_FLT 'f'
9936ac495dSmrg #define _C_DBL 'd'
10036ac495dSmrg #define _C_LNG_DBL 'D'
10136ac495dSmrg #define _C_BFLD 'b'
10236ac495dSmrg #define _C_BOOL 'B'
10336ac495dSmrg #define _C_VOID 'v'
10436ac495dSmrg #define _C_UNDEF '?'
10536ac495dSmrg #define _C_PTR '^'
10636ac495dSmrg #define _C_CHARPTR '*'
10736ac495dSmrg #define _C_ARY_B '['
10836ac495dSmrg #define _C_ARY_E ']'
10936ac495dSmrg #define _C_UNION_B '('
11036ac495dSmrg #define _C_UNION_E ')'
11136ac495dSmrg #define _C_STRUCT_B '{'
11236ac495dSmrg #define _C_STRUCT_E '}'
11336ac495dSmrg #define _C_VECTOR '!'
11436ac495dSmrg #define _C_COMPLEX 'j'
11536ac495dSmrg
11636ac495dSmrg /* _C_ATOM is never generated by the compiler. You can treat it as
11736ac495dSmrg equivalent to "*". */
11836ac495dSmrg #define _C_ATOM '%'
11936ac495dSmrg
12036ac495dSmrg /* The following are used in encode strings to describe some
12136ac495dSmrg qualifiers of method and ivar types. */
12236ac495dSmrg #define _C_CONST 'r'
12336ac495dSmrg #define _C_IN 'n'
12436ac495dSmrg #define _C_INOUT 'N'
12536ac495dSmrg #define _C_OUT 'o'
12636ac495dSmrg #define _C_BYCOPY 'O'
12736ac495dSmrg #define _C_BYREF 'R'
12836ac495dSmrg #define _C_ONEWAY 'V'
12936ac495dSmrg #define _C_GCINVISIBLE '|'
13036ac495dSmrg
13136ac495dSmrg /* The same when used as flags. */
13236ac495dSmrg #define _F_CONST 0x01
13336ac495dSmrg #define _F_IN 0x01
13436ac495dSmrg #define _F_OUT 0x02
13536ac495dSmrg #define _F_INOUT 0x03
13636ac495dSmrg #define _F_BYCOPY 0x04
13736ac495dSmrg #define _F_BYREF 0x08
13836ac495dSmrg #define _F_ONEWAY 0x10
13936ac495dSmrg #define _F_GCINVISIBLE 0x20
14036ac495dSmrg
14136ac495dSmrg
14236ac495dSmrg /** Implementation: the following functions are defined inline. */
14336ac495dSmrg
14436ac495dSmrg /* Return the class of 'object', or Nil if the object is nil. If
14536ac495dSmrg 'object' is a class, the meta class is returned; if 'object' is a
14636ac495dSmrg meta class, the root meta class is returned (note that this is
14736ac495dSmrg different from the traditional GNU Objective-C Runtime API function
14836ac495dSmrg object_get_class(), which for a meta class would return the meta
14936ac495dSmrg class itself). This function is inline, so it is really fast and
15036ac495dSmrg should be used instead of accessing object->class_pointer
15136ac495dSmrg directly. */
15236ac495dSmrg static inline Class
object_getClass(id object)15336ac495dSmrg object_getClass (id object)
15436ac495dSmrg {
15536ac495dSmrg if (object != nil)
15636ac495dSmrg return object->class_pointer;
15736ac495dSmrg else
15836ac495dSmrg return Nil;
15936ac495dSmrg }
16036ac495dSmrg
16136ac495dSmrg
16236ac495dSmrg /** Implementation: the following functions are in selector.c. */
16336ac495dSmrg
16436ac495dSmrg /* Return the name of a given selector. If 'selector' is NULL, return
16536ac495dSmrg "<null selector>". */
16636ac495dSmrg objc_EXPORT const char *sel_getName (SEL selector);
16736ac495dSmrg
16836ac495dSmrg /* Return the type of a given selector. Return NULL if selector is
16936ac495dSmrg NULL.
17036ac495dSmrg
17136ac495dSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
17236ac495dSmrg so it does not have this function, which is specific to the GNU
17336ac495dSmrg Runtime. */
17436ac495dSmrg objc_EXPORT const char *sel_getTypeEncoding (SEL selector);
17536ac495dSmrg
17636ac495dSmrg /* This is the same as sel_registerName (). Please use
17736ac495dSmrg sel_registerName () instead. */
17836ac495dSmrg objc_EXPORT SEL sel_getUid (const char *name);
17936ac495dSmrg
18036ac495dSmrg /* Register a selector with a given name (but unspecified types). If
18136ac495dSmrg you know the types, it is better to call sel_registerTypedName().
18236ac495dSmrg If a selector with this name and no types already exists, it is
18336ac495dSmrg returned. Note that this function should really be called
18436ac495dSmrg 'objc_registerSelector'. Return NULL if 'name' is NULL. */
18536ac495dSmrg objc_EXPORT SEL sel_registerName (const char *name);
18636ac495dSmrg
18736ac495dSmrg /* Register a selector with a given name and types. If a selector
18836ac495dSmrg with this name and types already exists, it is returned. Note that
18936ac495dSmrg this function should really be called 'objc_registerTypedSelector',
19036ac495dSmrg and it's called 'sel_registerTypedName' only for consistency with
19136ac495dSmrg 'sel_registerName'. Return NULL if 'name' is NULL.
19236ac495dSmrg
19336ac495dSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
19436ac495dSmrg so it does not have this function, which is specific to the GNU
19536ac495dSmrg Runtime. */
19636ac495dSmrg objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type);
19736ac495dSmrg
19836ac495dSmrg /* Return YES if first_selector is the same as second_selector, and NO
19936ac495dSmrg if not. */
20036ac495dSmrg objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector);
20136ac495dSmrg
20236ac495dSmrg /* Return all the selectors with the supplied name. In the GNU
20336ac495dSmrg runtime, selectors are typed and there may be multiple selectors
20436ac495dSmrg with the same name but a different type. The return value of the
20536ac495dSmrg function is a pointer to an area, allocated with malloc(), that
20636ac495dSmrg contains all the selectors with the supplier name known to the
20736ac495dSmrg runtime. The list is terminated by NULL. Optionally, if you pass
20836ac495dSmrg a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int
20936ac495dSmrg that it points to will be filled with the number of selectors
21036ac495dSmrg returned.
21136ac495dSmrg
21236ac495dSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
21336ac495dSmrg so it does not have this function, which is specific to the GNU
21436ac495dSmrg Runtime. */
21536ac495dSmrg objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name,
21636ac495dSmrg unsigned int *numberOfReturnedSelectors);
21736ac495dSmrg
21836ac495dSmrg /* Return a selector with name 'name' and a non-zero type encoding, if
21936ac495dSmrg there is a single selector with a type, and with that name,
22036ac495dSmrg registered with the runtime. If there is no such selector, or if
22136ac495dSmrg there are multiple selectors with the same name but conflicting
22236ac495dSmrg types, NULL is returned. Return NULL if 'name' is NULL.
22336ac495dSmrg
22436ac495dSmrg This is useful if you have the name of the selector, and would
22536ac495dSmrg really like to get a selector for it that includes the type
22636ac495dSmrg encoding. Unfortunately, if the program contains multiple selector
227c0a68be4Smrg with the same name but different types, sel_getTypedSelector cannot
228c0a68be4Smrg possibly know which one you need, and so will return NULL.
22936ac495dSmrg
23036ac495dSmrg Compatibility Note: the Apple/NeXT runtime has untyped selectors,
23136ac495dSmrg so it does not have this function, which is specific to the GNU
23236ac495dSmrg Runtime. */
23336ac495dSmrg objc_EXPORT SEL sel_getTypedSelector (const char *name);
23436ac495dSmrg
23536ac495dSmrg
23636ac495dSmrg /** Implementation: the following functions are in objects.c. */
23736ac495dSmrg
23836ac495dSmrg /* Create an instance of class 'class_', adding extraBytes to the size
23936ac495dSmrg of the returned object. This method allocates the appropriate
24036ac495dSmrg amount of memory for the instance, initializes it to zero, then
24136ac495dSmrg calls all the C++ constructors on appropriate C++ instance
24236ac495dSmrg variables of the instance (if any) (TODO: The C++ constructors bit
24336ac495dSmrg is not implemented yet). */
24436ac495dSmrg objc_EXPORT id class_createInstance (Class class_, size_t extraBytes);
24536ac495dSmrg
24636ac495dSmrg /* Copy an object and return the copy. extraBytes should be identical
24736ac495dSmrg to the extraBytes parameter that was passed when creating the
24836ac495dSmrg original object. */
24936ac495dSmrg objc_EXPORT id object_copy (id object, size_t extraBytes);
25036ac495dSmrg
25136ac495dSmrg /* Dispose of an object. This method calls the appropriate C++
25236ac495dSmrg destructors on appropriate C++ instance variables of the instance
25336ac495dSmrg (if any) (TODO: This is not implemented yet), then frees the memory
25436ac495dSmrg for the instance. */
25536ac495dSmrg objc_EXPORT id object_dispose (id object);
25636ac495dSmrg
25736ac495dSmrg /* Return the name of the class of 'object'. If 'object' is 'nil',
25836ac495dSmrg returns "Nil". */
25936ac495dSmrg objc_EXPORT const char * object_getClassName (id object);
26036ac495dSmrg
26136ac495dSmrg /* Change the class of object to be class_. Return the previous class
26236ac495dSmrg of object. This is currently not really thread-safe. */
26336ac495dSmrg objc_EXPORT Class object_setClass (id object, Class class_);
26436ac495dSmrg
26536ac495dSmrg
26636ac495dSmrg /** Implementation: the following functions are in ivars.c. */
26736ac495dSmrg
26836ac495dSmrg /* Return an instance variable given the class and the instance
26936ac495dSmrg variable name. This is an expensive function to call, so try to
27036ac495dSmrg reuse the returned Ivar if you can. */
27136ac495dSmrg objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name);
27236ac495dSmrg
27336ac495dSmrg /* Return a class variable given the class and the class variable
27436ac495dSmrg name. This is an expensive function to call, so try to reuse the
27536ac495dSmrg returned Ivar if you can.
27636ac495dSmrg
27736ac495dSmrg This function always returns NULL since class variables are
27836ac495dSmrg currently unavailable in Objective-C. */
27936ac495dSmrg objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name);
28036ac495dSmrg
28136ac495dSmrg /* If the object was created in class_createInstance() with some
28236ac495dSmrg extraBytes, returns a pointer to them. If it was not, then the
28336ac495dSmrg returned pointer may make no sense. */
28436ac495dSmrg objc_EXPORT void * object_getIndexedIvars (id object);
28536ac495dSmrg
28636ac495dSmrg /* Get the value of an instance variable of type 'id'. The function
28736ac495dSmrg returns the instance variable. To get the value of the instance
28836ac495dSmrg variable, you should pass as 'returnValue' a pointer to an 'id';
28936ac495dSmrg the value will be copied there. Note that 'returnValue' is really
29036ac495dSmrg a 'void *', not a 'void **'. This function really works only with
29136ac495dSmrg instance variables of type 'id'; for other types of instance
29236ac495dSmrg variables, access directly the data at (char *)object +
29336ac495dSmrg ivar_getOffset (ivar). */
29436ac495dSmrg objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue);
29536ac495dSmrg
29636ac495dSmrg /* Set the value of an instance variable. The value to set is passed
29736ac495dSmrg in 'newValue' (which really is an 'id', not a 'void *'). The
29836ac495dSmrg function returns the instance variable. This function really works
29936ac495dSmrg only with instance variables of type 'id'; for other types of
30036ac495dSmrg instance variables, access directly the data at (char *)object +
30136ac495dSmrg ivar_getOffset (ivar). */
30236ac495dSmrg objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue);
30336ac495dSmrg
30436ac495dSmrg /* Get the value of an instance variable of type 'id' of the object
30536ac495dSmrg 'object'. This is faster than object_getInstanceVariable if you
30636ac495dSmrg already have the instance variable because it avoids the expensive
30736ac495dSmrg call to class_getInstanceVariable that is done by
30836ac495dSmrg object_getInstanceVariable. */
30936ac495dSmrg objc_EXPORT id object_getIvar (id object, Ivar variable);
31036ac495dSmrg
31136ac495dSmrg /* Set the value of an instance variable of type 'id' of the object
31236ac495dSmrg 'object'. This is faster than object_setInstanceVariable if you
31336ac495dSmrg already have the instance variable because it avoids the expensive
31436ac495dSmrg call to class_getInstanceVariable that is done by
31536ac495dSmrg object_setInstanceVariable. */
31636ac495dSmrg objc_EXPORT void object_setIvar (id object, Ivar variable, id value);
31736ac495dSmrg
31836ac495dSmrg /* Return the name of the instance variable. Return NULL if
31936ac495dSmrg 'variable' is NULL. */
32036ac495dSmrg objc_EXPORT const char * ivar_getName (Ivar variable);
32136ac495dSmrg
32236ac495dSmrg /* Return the offset of the instance variable from the start of the
32336ac495dSmrg object data. Return 0 if 'variable' is NULL. */
32436ac495dSmrg objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable);
32536ac495dSmrg
32636ac495dSmrg /* Return the type encoding of the variable. Return NULL if
32736ac495dSmrg 'variable' is NULL. */
32836ac495dSmrg objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable);
32936ac495dSmrg
33036ac495dSmrg /* Return all the instance variables of the class. The return value
33136ac495dSmrg of the function is a pointer to an area, allocated with malloc(),
33236ac495dSmrg that contains all the instance variables of the class. It does not
33336ac495dSmrg include instance variables of superclasses. The list is terminated
33436ac495dSmrg by NULL. Optionally, if you pass a non-NULL
33536ac495dSmrg 'numberOfReturnedIvars' pointer, the unsigned int that it points to
33636ac495dSmrg will be filled with the number of instance variables returned.
33736ac495dSmrg Return NULL for classes still in construction (ie, allocated using
33836ac495dSmrg objc_allocatedClassPair() but not yet registered with the runtime
33936ac495dSmrg using objc_registerClassPair()). */
34036ac495dSmrg objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars);
34136ac495dSmrg
34236ac495dSmrg /* Add an instance variable with name 'ivar_name' to class 'class_',
34336ac495dSmrg where 'class_' is a class in construction that has been created
34436ac495dSmrg using objc_allocateClassPair() and has not been registered with the
34536ac495dSmrg runtime using objc_registerClassPair() yet. You cannot add
34636ac495dSmrg instance variables to classes already registered with the runtime.
34736ac495dSmrg 'size' is the size of the instance variable, 'log_2_of_alignment'
34836ac495dSmrg the alignment as a power of 2 (so 0 means alignment to a 1 byte
34936ac495dSmrg boundary, 1 means alignment to a 2 byte boundary, 2 means alignment
35036ac495dSmrg to a 4 byte boundary, etc), and 'type' the type encoding of the
35136ac495dSmrg variable type. You can use sizeof(), log2(__alignof__()) and
35236ac495dSmrg @encode() to determine the right 'size', 'alignment' and 'type' for
35336ac495dSmrg your instance variable. For example, to add an instance variable
35436ac495dSmrg name "my_variable" and of type 'id', you can use:
35536ac495dSmrg
35636ac495dSmrg class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)),
35736ac495dSmrg @encode (id));
35836ac495dSmrg
35936ac495dSmrg Return YES if the variable was added, and NO if not. In
36036ac495dSmrg particular, return NO if 'class_' is Nil, or a meta-class or a
36136ac495dSmrg class not in construction. Return Nil also if 'ivar_name' or
36236ac495dSmrg 'type' is NULL, or 'size' is 0.
36336ac495dSmrg */
36436ac495dSmrg objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size,
36536ac495dSmrg unsigned char log_2_of_alignment, const char *type);
36636ac495dSmrg
36736ac495dSmrg /* Return the name of the property. Return NULL if 'property' is
36836ac495dSmrg NULL. */
36936ac495dSmrg objc_EXPORT const char * property_getName (Property property);
37036ac495dSmrg
37136ac495dSmrg /* Return the attributes of the property as a string. Return NULL if
37236ac495dSmrg 'property' is NULL. */
37336ac495dSmrg objc_EXPORT const char * property_getAttributes (Property property);
37436ac495dSmrg
37536ac495dSmrg /* Return the property with name 'propertyName' of the class 'class_'.
37636ac495dSmrg This function returns NULL if the required property cannot be
37736ac495dSmrg found. Return NULL if 'class_' or 'propertyName' is NULL.
37836ac495dSmrg
37936ac495dSmrg Note that the traditional ABI does not store the list of properties
38036ac495dSmrg of a class in a compiled module, so the traditional ABI will always
38136ac495dSmrg return NULL. */
38236ac495dSmrg objc_EXPORT Property class_getProperty (Class class_, const char *propertyName);
38336ac495dSmrg
38436ac495dSmrg /* Return all the properties of the class. The return value
38536ac495dSmrg of the function is a pointer to an area, allocated with malloc(),
38636ac495dSmrg that contains all the properties of the class. It does not
38736ac495dSmrg include properties of superclasses. The list is terminated
38836ac495dSmrg by NULL. Optionally, if you pass a non-NULL
38936ac495dSmrg 'numberOfReturnedIvars' pointer, the unsigned int that it points to
39036ac495dSmrg will be filled with the number of properties returned.
39136ac495dSmrg
39236ac495dSmrg Note that the traditional ABI does not store the list of properties
39336ac495dSmrg of a class in a compiled module, so the traditional ABI will always
39436ac495dSmrg return an empty list. */
39536ac495dSmrg objc_EXPORT Property * class_copyPropertyList
39636ac495dSmrg (Class class_, unsigned int *numberOfReturnedProperties);
39736ac495dSmrg
39836ac495dSmrg /* Return the ivar layout for class 'class_'.
39936ac495dSmrg
40036ac495dSmrg At the moment this function always returns NULL. */
40136ac495dSmrg objc_EXPORT const char * class_getIvarLayout (Class class_);
40236ac495dSmrg
40336ac495dSmrg /* Return the weak ivar layout for class 'class_'.
40436ac495dSmrg
40536ac495dSmrg At the moment this function always returns NULL. */
40636ac495dSmrg objc_EXPORT const char * class_getWeakIvarLayout (Class class_);
40736ac495dSmrg
40836ac495dSmrg /* Set the ivar layout for class 'class_'.
40936ac495dSmrg
41036ac495dSmrg At the moment, this function does nothing. */
41136ac495dSmrg objc_EXPORT void class_setIvarLayout (Class class_, const char *layout);
41236ac495dSmrg
41336ac495dSmrg /* Set the weak ivar layout for class 'class_'.
41436ac495dSmrg
41536ac495dSmrg At the moment, this function does nothing. With the GNU runtime,
41636ac495dSmrg you should use class_ivar_set_gcinvisible () to hide variables from
41736ac495dSmrg the Garbage Collector. */
41836ac495dSmrg objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout);
41936ac495dSmrg
42036ac495dSmrg
42136ac495dSmrg /** Implementation: the following functions are in class.c. */
42236ac495dSmrg
42336ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime does not have
42436ac495dSmrg objc_get_unknown_class_handler and
42536ac495dSmrg objc_setGetUnknownClassHandler(). They provide functionality that
42636ac495dSmrg the traditional GNU Objective-C Runtime API used to provide via the
42736ac495dSmrg _objc_lookup_class hook. */
42836ac495dSmrg
42936ac495dSmrg /* An 'objc_get_unknown_class_handler' function is used by
43036ac495dSmrg objc_getClass() to get a class that is currently unknown to the
43136ac495dSmrg compiler. You could use it for example to have the class loaded by
43236ac495dSmrg dynamically loading a library. 'class_name' is the name of the
43336ac495dSmrg class. The function should return the Class object if it manages to
43436ac495dSmrg load the class, and Nil if not. */
43536ac495dSmrg typedef Class (*objc_get_unknown_class_handler)(const char *class_name);
43636ac495dSmrg
43736ac495dSmrg /* Sets a new handler function for getting unknown classes (to be used
43836ac495dSmrg by objc_getClass () and related), and returns the previous one.
43936ac495dSmrg This function is not safe to call in a multi-threaded environment
44036ac495dSmrg because other threads may be trying to use the get unknown class
44136ac495dSmrg handler while you change it! */
44236ac495dSmrg objc_EXPORT
44336ac495dSmrg objc_get_unknown_class_handler
44436ac495dSmrg objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler);
44536ac495dSmrg
44636ac495dSmrg /* Return the class with name 'name', if it is already registered with
44736ac495dSmrg the runtime. If it is not registered, and
44836ac495dSmrg objc_setGetUnknownClassHandler() has been called to set a handler
44936ac495dSmrg for unknown classes, the handler is called to give it a chance to
45036ac495dSmrg load the class in some other way. If the class is not known to the
45136ac495dSmrg runtime and the handler is not set or returns Nil, objc_getClass()
45236ac495dSmrg returns Nil. */
45336ac495dSmrg objc_EXPORT Class objc_getClass (const char *name);
45436ac495dSmrg
45536ac495dSmrg /* Return the class with name 'name', if it is already registered with
45636ac495dSmrg the runtime. Return Nil if not. This function does not call the
45736ac495dSmrg objc_get_unknown_class_handler function if the class is not
45836ac495dSmrg found. */
45936ac495dSmrg objc_EXPORT Class objc_lookUpClass (const char *name);
46036ac495dSmrg
46136ac495dSmrg /* Return the meta class associated to the class with name 'name', if
46236ac495dSmrg it is already registered with the runtime. First, it finds the
46336ac495dSmrg class using objc_getClass(). Then, it returns the associated meta
46436ac495dSmrg class. If the class could not be found using objc_getClass(),
46536ac495dSmrg returns Nil. */
46636ac495dSmrg objc_EXPORT Class objc_getMetaClass (const char *name);
46736ac495dSmrg
46836ac495dSmrg /* This is identical to objc_getClass(), but if the class is not found,
46936ac495dSmrg it aborts the process instead of returning Nil. */
47036ac495dSmrg objc_EXPORT Class objc_getRequiredClass (const char *name);
47136ac495dSmrg
47236ac495dSmrg /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of
47336ac495dSmrg classes currently registered with the runtime. If 'returnValue' is
47436ac495dSmrg not NULL, it should be a (Class *) pointer to an area of memory
47536ac495dSmrg which can contain up to 'maxNumberOfClassesToReturn' Class records.
47636ac495dSmrg 'objc_getClassList' will fill the area pointed to by 'returnValue'
47736ac495dSmrg with all the Classes registered with the runtime (or up to
47836ac495dSmrg maxNumberOfClassesToReturn if there are more than
47936ac495dSmrg maxNumberOfClassesToReturn). The function return value is the
48036ac495dSmrg number of classes actually returned in 'returnValue'. */
48136ac495dSmrg objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn);
48236ac495dSmrg
48336ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime also has
48436ac495dSmrg
48536ac495dSmrg Class objc_getFutureClass (const char *name);
48636ac495dSmrg void objc_setFutureClass (Class class_, const char *name);
48736ac495dSmrg
48836ac495dSmrg the documentation is unclear on what they are supposed to do, and
48936ac495dSmrg the GNU Objective-C Runtime currently does not provide them. */
49036ac495dSmrg
49136ac495dSmrg /* Return the name of the class 'class_', or the string "nil" if the
49236ac495dSmrg class_ is Nil. */
49336ac495dSmrg objc_EXPORT const char * class_getName (Class class_);
49436ac495dSmrg
49536ac495dSmrg /* Return YES if 'class_' is a meta class, and NO if not. If 'class_'
49636ac495dSmrg is Nil, return NO. */
49736ac495dSmrg objc_EXPORT BOOL class_isMetaClass (Class class_);
49836ac495dSmrg
49936ac495dSmrg /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a
50036ac495dSmrg root class, return Nil. This function also works if 'class_' is a
50136ac495dSmrg class being constructed, that is, a class returned by
50236ac495dSmrg objc_allocateClassPair() but before it has been registered with the
50336ac495dSmrg runtime using objc_registerClassPair(). */
50436ac495dSmrg objc_EXPORT Class class_getSuperclass (Class class_);
50536ac495dSmrg
50636ac495dSmrg /* Return the 'version' number of the class, which is an integer that
50736ac495dSmrg can be used to track changes in the class API, methods and
50836ac495dSmrg variables. If class_ is Nil, return 0. If class_ is not Nil, the
50936ac495dSmrg version is 0 unless class_setVersion() has been called to set a
51036ac495dSmrg different one.
51136ac495dSmrg
51236ac495dSmrg Please note that internally the version is a long, but the API only
51336ac495dSmrg allows you to set and retrieve int values. */
51436ac495dSmrg objc_EXPORT int class_getVersion (Class class_);
51536ac495dSmrg
51636ac495dSmrg /* Set the 'version' number of the class, which is an integer that can
51736ac495dSmrg be used to track changes in the class API, methods and variables.
51836ac495dSmrg If 'class_' is Nil, does nothing.
51936ac495dSmrg
52036ac495dSmrg This is typically used internally by "Foundation" libraries such as
52136ac495dSmrg GNUstep Base to support serialization / deserialization of objects
52236ac495dSmrg that work across changes in the classes. If you are using such a
52336ac495dSmrg library, you probably want to use their versioning API, which may
52436ac495dSmrg be based on this one, but is integrated with the rest of the
52536ac495dSmrg library.
52636ac495dSmrg
52736ac495dSmrg Please note that internally the version is a long, but the API only
52836ac495dSmrg allows you to set and retrieve int values. */
52936ac495dSmrg objc_EXPORT void class_setVersion (Class class_, int version);
53036ac495dSmrg
53136ac495dSmrg /* Return the size in bytes (a byte is the size of a char) of an
53236ac495dSmrg instance of the class. If class_ is Nil, return 0; else it return
53336ac495dSmrg a non-zero number (since the 'isa' instance variable is required
53436ac495dSmrg for all classes). */
53536ac495dSmrg objc_EXPORT size_t class_getInstanceSize (Class class_);
53636ac495dSmrg
53736ac495dSmrg /* Change the implementation of the method. It also searches all
53836ac495dSmrg classes for any class implementing the method, and replaces the
53936ac495dSmrg existing implementation with the new one. For that to work,
54036ac495dSmrg 'method' must be a method returned by class_getInstanceMethod() or
54136ac495dSmrg class_getClassMethod() as the matching is done by comparing the
54236ac495dSmrg pointers; in that case, only the implementation in the class is
54336ac495dSmrg modified. Return the previous implementation that has been
54436ac495dSmrg replaced. If method or implementation is NULL, do nothing and
54536ac495dSmrg return NULL. */
54636ac495dSmrg objc_EXPORT IMP
54736ac495dSmrg method_setImplementation (Method method, IMP implementation);
54836ac495dSmrg
54936ac495dSmrg /* Swap the implementation of two methods in a single, atomic
55036ac495dSmrg operation. This is equivalent to getting the implementation of
55136ac495dSmrg each method and then calling method_setImplementation() on the
55236ac495dSmrg other one. For this to work, the two methods must have been
55336ac495dSmrg returned by class_getInstanceMethod() or class_getClassMethod().
55436ac495dSmrg If 'method_a' or 'method_b' is NULL, do nothing. */
55536ac495dSmrg objc_EXPORT void
55636ac495dSmrg method_exchangeImplementations (Method method_a, Method method_b);
55736ac495dSmrg
55836ac495dSmrg /* Create a new class/meta-class pair. This function is called to
55936ac495dSmrg create a new class at runtime. The class is created with
56036ac495dSmrg superclass 'superclass' (use 'Nil' to create a new root class) and
56136ac495dSmrg name 'class_name'. 'extraBytes' can be used to specify some extra
56236ac495dSmrg space for indexed variables to be added at the end of the class and
56336ac495dSmrg meta-class objects (it is recommended that you set extraBytes to
56436ac495dSmrg 0). Once you have created the class, it is not usable yet. You
56536ac495dSmrg need to add any instance variables (by using class_addIvar()), any
56636ac495dSmrg instance methods (by using class_addMethod()) and any class methods
56736ac495dSmrg (by using class_addMethod() on the meta-class, as in
56836ac495dSmrg class_addMethod (object_getClass (class), method)) that are
56936ac495dSmrg required, and then you need to call objc_registerClassPair() to
57036ac495dSmrg activate the class. If you need to create a hierarchy of classes,
57136ac495dSmrg you need to create and register them one at a time. You cannot
57236ac495dSmrg create a new class using another class in construction as
57336ac495dSmrg superclass. Return Nil if 'class-name' is NULL or if a class with
57436ac495dSmrg that name already exists or 'superclass' is a class still in
57536ac495dSmrg construction.
57636ac495dSmrg
57736ac495dSmrg Implementation Note: in the GNU runtime, allocating a class pair
57836ac495dSmrg only creates the structures for the class pair, but does not
57936ac495dSmrg register anything with the runtime. The class is registered with
58036ac495dSmrg the runtime only when objc_registerClassPair() is called. In
58136ac495dSmrg particular, if a class is in construction, objc_getClass() will not
58236ac495dSmrg find it, the superclass will not know about it,
58336ac495dSmrg class_getSuperclass() will return Nil and another thread may
58436ac495dSmrg allocate a class pair with the same name; the conflict will only be
58536ac495dSmrg detected when the classes are registered with the runtime.
58636ac495dSmrg */
58736ac495dSmrg objc_EXPORT Class
58836ac495dSmrg objc_allocateClassPair (Class super_class, const char *class_name,
58936ac495dSmrg size_t extraBytes);
59036ac495dSmrg
59136ac495dSmrg /* Register a class pair that was created with
59236ac495dSmrg objc_allocateClassPair(). After you register a class, you can no
59336ac495dSmrg longer make changes to its instance variables, but you can start
59436ac495dSmrg creating instances of it. Do nothing if 'class_' is NULL or if it
59536ac495dSmrg is not a class allocated by objc_allocateClassPair() and still in
59636ac495dSmrg construction. */
59736ac495dSmrg objc_EXPORT void
59836ac495dSmrg objc_registerClassPair (Class class_);
59936ac495dSmrg
60036ac495dSmrg /* Dispose of a class pair created using objc_allocateClassPair().
60136ac495dSmrg Call this function if you started creating a new class with
60236ac495dSmrg objc_allocateClassPair() but then want to abort the process. You
60336ac495dSmrg should not access 'class_' after calling this method. Note that if
60436ac495dSmrg 'class_' has already been registered with the runtime via
60536ac495dSmrg objc_registerClassPair(), this function does nothing; you can only
60636ac495dSmrg dispose of class pairs that are still being constructed. Do
60736ac495dSmrg nothing if class is 'Nil' or if 'class_' is not a class being
60836ac495dSmrg constructed. */
60936ac495dSmrg objc_EXPORT void
61036ac495dSmrg objc_disposeClassPair (Class class_);
61136ac495dSmrg
61236ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime has the function
61336ac495dSmrg objc_duplicateClass () but it's undocumented. The GNU runtime does
61436ac495dSmrg not have it. */
61536ac495dSmrg
61636ac495dSmrg
61736ac495dSmrg /** Implementation: the following functions are in sendmsg.c. */
61836ac495dSmrg
61936ac495dSmrg /* Return the instance method with selector 'selector' of class
62036ac495dSmrg 'class_', or NULL if the class (or one of its superclasses) does
62136ac495dSmrg not implement the method. Return NULL if class_ is Nil or selector
62236ac495dSmrg is NULL. Calling this function may trigger a call to
62336ac495dSmrg +resolveInstanceMethod:, but does not return a forwarding
62436ac495dSmrg function. */
62536ac495dSmrg objc_EXPORT Method class_getInstanceMethod (Class class_, SEL selector);
62636ac495dSmrg
62736ac495dSmrg /* Return the class method with selector 'selector' of class 'class_',
62836ac495dSmrg or NULL if the class (or one of its superclasses) does not
62936ac495dSmrg implement the method. Return NULL if class_ is Nil or selector is
63036ac495dSmrg NULL. Calling this function may trigger a call to
63136ac495dSmrg +resolveClassMethod:, but does not return a forwarding
63236ac495dSmrg function. */
63336ac495dSmrg objc_EXPORT Method class_getClassMethod (Class class_, SEL selector);
63436ac495dSmrg
63536ac495dSmrg /* Return the IMP (pointer to the function implementing a method) for
63636ac495dSmrg the instance method with selector 'selector' in class 'class_'.
63736ac495dSmrg This is the same routine that is used while messaging, and should
63836ac495dSmrg be very fast. Note that you most likely would need to cast the
63936ac495dSmrg return function pointer to a function pointer with the appropriate
64036ac495dSmrg arguments and return type before calling it. To get a class
64136ac495dSmrg method, you can pass the meta-class as the class_ argument (ie, use
64236ac495dSmrg class_getMethodImplementation (object_getClass (class_),
64336ac495dSmrg selector)). Return NULL if class_ is Nil or selector is NULL.
64436ac495dSmrg This function first looks for an existing method; if it is not
64536ac495dSmrg found, it calls +resolveClassMethod: or +resolveInstanceMethod:
64636ac495dSmrg (depending on whether a class or instance method is being looked
64736ac495dSmrg up) if it is implemented. If the method returns YES, then it tries
64836ac495dSmrg the look up again (the assumption being that +resolveClassMethod:
64936ac495dSmrg or resolveInstanceMethod: will add the method using
65036ac495dSmrg class_addMethod()). If it is still not found, it returns a
65136ac495dSmrg forwarding function. */
65236ac495dSmrg objc_EXPORT IMP class_getMethodImplementation (Class class_, SEL selector);
65336ac495dSmrg
65436ac495dSmrg /* Compatibility Note: the Apple/NeXT runtime has the function
65536ac495dSmrg class_getMethodImplementation_stret () which currently does not
65636ac495dSmrg exist on the GNU runtime because the messaging implementation is
65736ac495dSmrg different. */
65836ac495dSmrg
65936ac495dSmrg /* Return YES if class 'class_' has an instance method implementing
66036ac495dSmrg selector 'selector', and NO if not. Return NO if class_ is Nil or
66136ac495dSmrg selector is NULL. If you need to check a class method, use the
66236ac495dSmrg meta-class as the class_ argument (ie, use class_respondsToSelector
66336ac495dSmrg (object_getClass (class_), selector)). */
66436ac495dSmrg objc_EXPORT BOOL class_respondsToSelector (Class class_, SEL selector);
66536ac495dSmrg
66636ac495dSmrg /* Add a method to a class. Use this function to add a new method to
66736ac495dSmrg a class (potentially overriding a method with the same selector in
66836ac495dSmrg the superclass); if you want to modify an existing method, use
66936ac495dSmrg method_setImplementation() instead (or class_replaceMethod ()).
67036ac495dSmrg This method adds an instance method to 'class_'; to add a class
67136ac495dSmrg method, get the meta class first, then add the method to the meta
67236ac495dSmrg class, that is, use
67336ac495dSmrg
67436ac495dSmrg class_addMethod (object_getClass (class_), selector,
67536ac495dSmrg implementation, type);
67636ac495dSmrg
67736ac495dSmrg Return YES if the method was added, and NO if not. Do nothing if
67836ac495dSmrg one of the arguments is NULL. */
67936ac495dSmrg objc_EXPORT BOOL class_addMethod (Class class_, SEL selector, IMP implementation,
68036ac495dSmrg const char *method_types);
68136ac495dSmrg
68236ac495dSmrg /* Replace a method in a class. If the class already have a method
68336ac495dSmrg with this 'selector', find it and use method_setImplementation() to
68436ac495dSmrg replace the implementation with 'implementation' (method_types is
68536ac495dSmrg ignored in that case). If the class does not already have a method
68636ac495dSmrg with this 'selector', call 'class_addMethod() to add it.
68736ac495dSmrg
68836ac495dSmrg Return the previous implementation of the method, or NULL if none
68936ac495dSmrg was found. Return NULL if any of the arguments is NULL. */
69036ac495dSmrg objc_EXPORT IMP class_replaceMethod (Class class_, SEL selector, IMP implementation,
69136ac495dSmrg const char *method_types);
69236ac495dSmrg
69336ac495dSmrg
69436ac495dSmrg /** Implementation: the following functions are in methods.c. */
69536ac495dSmrg
69636ac495dSmrg /* Return the selector for method 'method'. Return NULL if 'method'
69736ac495dSmrg is NULL.
69836ac495dSmrg
69936ac495dSmrg This function is misnamed; it should be called
70036ac495dSmrg 'method_getSelector'. To get the actual name, get the selector,
70136ac495dSmrg then the name from the selector (ie, use sel_getName
70236ac495dSmrg (method_getName (method))). */
70336ac495dSmrg objc_EXPORT SEL method_getName (Method method);
70436ac495dSmrg
70536ac495dSmrg /* Return the IMP of the method. Return NULL if 'method' is NULL. */
70636ac495dSmrg objc_EXPORT IMP method_getImplementation (Method method);
70736ac495dSmrg
70836ac495dSmrg /* Return the type encoding of the method. Return NULL if 'method' is
70936ac495dSmrg NULL. */
71036ac495dSmrg objc_EXPORT const char * method_getTypeEncoding (Method method);
71136ac495dSmrg
71236ac495dSmrg /* Return a method description for the method. Return NULL if
71336ac495dSmrg 'method' is NULL. */
71436ac495dSmrg objc_EXPORT struct objc_method_description * method_getDescription (Method method);
71536ac495dSmrg
71636ac495dSmrg /* Return all the instance methods of the class. The return value of
71736ac495dSmrg the function is a pointer to an area, allocated with malloc(), that
71836ac495dSmrg contains all the instance methods of the class. It does not
71936ac495dSmrg include instance methods of superclasses. The list is terminated
72036ac495dSmrg by NULL. Optionally, if you pass a non-NULL
72136ac495dSmrg 'numberOfReturnedMethods' pointer, the unsigned int that it points
72236ac495dSmrg to will be filled with the number of instance methods returned. To
72336ac495dSmrg get the list of class methods, pass the meta-class in the 'class_'
72436ac495dSmrg argument, (ie, use class_copyMethodList (object_getClass (class_),
72536ac495dSmrg &numberOfReturnedMethods)). */
72636ac495dSmrg objc_EXPORT Method * class_copyMethodList (Class class_, unsigned int *numberOfReturnedMethods);
72736ac495dSmrg
72836ac495dSmrg
72936ac495dSmrg /** Implementation: the following functions are in encoding.c. */
73036ac495dSmrg
73136ac495dSmrg /* Return the number of arguments that the method 'method' expects.
73236ac495dSmrg Note that all methods need two implicit arguments ('self' for the
73336ac495dSmrg receiver, and '_cmd' for the selector). Return 0 if 'method' is
73436ac495dSmrg NULL. */
73536ac495dSmrg objc_EXPORT unsigned int method_getNumberOfArguments (Method method);
73636ac495dSmrg
73736ac495dSmrg /* Return the string encoding for the return type of method 'method'.
73836ac495dSmrg The string is a standard zero-terminated string in an area of
73936ac495dSmrg memory allocated with malloc(); you should free it with free() when
74036ac495dSmrg you finish using it. Return an empty string if method is NULL. */
74136ac495dSmrg objc_EXPORT char * method_copyReturnType (Method method);
74236ac495dSmrg
74336ac495dSmrg /* Return the string encoding for the argument type of method
74436ac495dSmrg 'method', argument number 'argumentNumber' ('argumentNumber' is 0
74536ac495dSmrg for self, 1 for _cmd, and 2 or more for the additional arguments if
74636ac495dSmrg any). The string is a standard zero-terminated string in an area
74736ac495dSmrg of memory allocated with malloc(); you should free it with free()
74836ac495dSmrg when you finish using it. Return an empty string if method is NULL
74936ac495dSmrg or if 'argumentNumber' refers to a non-existing argument. */
75036ac495dSmrg objc_EXPORT char * method_copyArgumentType (Method method, unsigned int argumentNumber);
75136ac495dSmrg
75236ac495dSmrg /* Return the string encoding for the return type of method 'method'.
75336ac495dSmrg The string is returned by copying it into the supplied
75436ac495dSmrg 'returnValue' string, which is of size 'returnValueSize'. No more
75536ac495dSmrg than 'returnValueSize' characters are copied; if the encoding is
75636ac495dSmrg smaller than 'returnValueSize', the rest of 'returnValue' is filled
75736ac495dSmrg with zeros. If it is bigger, it is truncated (and would not be
75836ac495dSmrg zero-terminated). You should supply a big enough
75936ac495dSmrg 'returnValueSize'. If the method is NULL, returnValue is set to a
76036ac495dSmrg string of zeros. */
76136ac495dSmrg objc_EXPORT void method_getReturnType (Method method, char *returnValue,
76236ac495dSmrg size_t returnValueSize);
76336ac495dSmrg
76436ac495dSmrg /* Return the string encoding for the argument type of method
76536ac495dSmrg 'method', argument number 'argumentNumber' ('argumentNumber' is 0
76636ac495dSmrg for self, 1 for _cmd, and 2 or more for the additional arguments if
76736ac495dSmrg any). The string is returned by copying it into the supplied
76836ac495dSmrg 'returnValue' string, which is of size 'returnValueSize'. No more
76936ac495dSmrg than 'returnValueSize' characters are copied; if the encoding is
77036ac495dSmrg smaller than 'returnValueSize', the rest of 'returnValue' is filled
77136ac495dSmrg with zeros. If it is bigger, it is truncated (and would not be
77236ac495dSmrg zero-terminated). You should supply a big enough
77336ac495dSmrg 'returnValueSize'. If the method is NULL, returnValue is set to a
77436ac495dSmrg string of zeros. */
77536ac495dSmrg objc_EXPORT void method_getArgumentType (Method method, unsigned int argumentNumber,
77636ac495dSmrg char *returnValue, size_t returnValueSize);
77736ac495dSmrg
77836ac495dSmrg
77936ac495dSmrg /** Implementation: the following functions are in protocols.c. */
78036ac495dSmrg
78136ac495dSmrg /* Return the protocol with name 'name', or nil if it the protocol is
78236ac495dSmrg not known to the runtime. */
78336ac495dSmrg objc_EXPORT Protocol *objc_getProtocol (const char *name);
78436ac495dSmrg
78536ac495dSmrg /* Return all the protocols known to the runtime. The return value of
78636ac495dSmrg the function is a pointer to an area, allocated with malloc(), that
78736ac495dSmrg contains all the protocols known to the runtime; the list is
78836ac495dSmrg terminated by NULL. You should free this area using free() once
78936ac495dSmrg you no longer need it. Optionally, if you pass a non-NULL
79036ac495dSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
79136ac495dSmrg points to will be filled with the number of protocols returned. If
79236ac495dSmrg there are no protocols known to the runtime, NULL is returned. */
79336ac495dSmrg objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProtocols);
79436ac495dSmrg
79536ac495dSmrg /* Add a protocol to a class, and return YES if it was done
79636ac495dSmrg successfully, and NO if not. At the moment, NO should only happen
79736ac495dSmrg if class_ or protocol are nil, if the protocol is not a Protocol
79836ac495dSmrg object or if the class already conforms to the protocol. */
79936ac495dSmrg objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol);
80036ac495dSmrg
80136ac495dSmrg /* Return YES if the class 'class_' conforms to Protocol 'protocol',
80236ac495dSmrg and NO if not. This function does not check superclasses; if you
80336ac495dSmrg want to check for superclasses (in the way that [NSObject
80436ac495dSmrg +conformsToProtocol:] does) you need to iterate over the class
80536ac495dSmrg hierarchy using class_getSuperclass(), and call
80636ac495dSmrg class_conformsToProtocol() for each of them. */
80736ac495dSmrg objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol);
80836ac495dSmrg
80936ac495dSmrg /* Return all the protocols that the class conforms to. The return
81036ac495dSmrg value of the function is a pointer to an area, allocated with
81136ac495dSmrg malloc(), that contains all the protocols formally adopted by the
81236ac495dSmrg class. It does not include protocols adopted by superclasses. The
81336ac495dSmrg list is terminated by NULL. Optionally, if you pass a non-NULL
81436ac495dSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
81536ac495dSmrg points to will be filled with the number of protocols returned.
81636ac495dSmrg This function does not return protocols that superclasses conform
81736ac495dSmrg to. */
81836ac495dSmrg objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols);
81936ac495dSmrg
82036ac495dSmrg /* Return YES if protocol 'protocol' conforms to protocol
82136ac495dSmrg 'anotherProtocol', and NO if not. Note that if one of the two
82236ac495dSmrg protocols is nil, it returns NO. */
82336ac495dSmrg objc_EXPORT BOOL protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol);
82436ac495dSmrg
82536ac495dSmrg /* Return YES if protocol 'protocol' is the same as protocol
82636ac495dSmrg 'anotherProtocol', and 'NO' if not. Note that it returns YES if
82736ac495dSmrg the two protocols are both nil. */
82836ac495dSmrg objc_EXPORT BOOL protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol);
82936ac495dSmrg
83036ac495dSmrg /* Return the name of protocol 'protocol'. If 'protocol' is nil or is
83136ac495dSmrg not a Protocol, return NULL. */
83236ac495dSmrg objc_EXPORT const char *protocol_getName (Protocol *protocol);
83336ac495dSmrg
83436ac495dSmrg /* Return the method description for the method with selector
83536ac495dSmrg 'selector' in protocol 'protocol'; if 'requiredMethod' is YES, the
83636ac495dSmrg function searches the list of required methods; if NO, the list of
83736ac495dSmrg optional methods. If 'instanceMethod' is YES, the function search
83836ac495dSmrg for an instance method; if NO, for a class method. If there is no
83936ac495dSmrg matching method, an objc_method_description structure with both
84036ac495dSmrg name and types set to NULL is returned. This function will only
84136ac495dSmrg find methods that are directly declared in the protocol itself, not
84236ac495dSmrg in other protocols that this protocol adopts.
84336ac495dSmrg
84436ac495dSmrg Note that the traditional ABI does not store the list of optional
84536ac495dSmrg methods of a protocol in a compiled module, so the traditional ABI
84636ac495dSmrg will always return (NULL, NULL) when requiredMethod == NO. */
84736ac495dSmrg objc_EXPORT struct objc_method_description protocol_getMethodDescription (Protocol *protocol,
84836ac495dSmrg SEL selector,
84936ac495dSmrg BOOL requiredMethod,
85036ac495dSmrg BOOL instanceMethod);
85136ac495dSmrg
85236ac495dSmrg /* Return the method descriptions of all the methods of the protocol.
85336ac495dSmrg The return value of the function is a pointer to an area, allocated
85436ac495dSmrg with malloc(), that contains all the method descriptions of the
85536ac495dSmrg methods of the protocol. It does not recursively include methods
85636ac495dSmrg of the protocols adopted by this protocol. The list is terminated
85736ac495dSmrg by a NULL objc_method_description (one with both fields set to
85836ac495dSmrg NULL). Optionally, if you pass a non-NULL
85936ac495dSmrg 'numberOfReturnedMethods' pointer, the unsigned int that it points
86036ac495dSmrg to will be filled with the number of properties returned.
86136ac495dSmrg
86236ac495dSmrg Note that the traditional ABI does not store the list of optional
86336ac495dSmrg methods of a protocol in a compiled module, so the traditional ABI
86436ac495dSmrg will always return an empty list if requiredMethod is set to
86536ac495dSmrg NO. */
86636ac495dSmrg objc_EXPORT struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *protocol,
86736ac495dSmrg BOOL requiredMethod,
86836ac495dSmrg BOOL instanceMethod,
86936ac495dSmrg unsigned int *numberOfReturnedMethods);
87036ac495dSmrg
87136ac495dSmrg /* Return the property with name 'propertyName' of the protocol
87236ac495dSmrg 'protocol'. If 'requiredProperty' is YES, the function searches
87336ac495dSmrg the list of required properties; if NO, the list of optional
87436ac495dSmrg properties. If 'instanceProperty' is YES, the function searches
87536ac495dSmrg the list of instance properties; if NO, the list of class
87636ac495dSmrg properties. At the moment, optional properties and class
87736ac495dSmrg properties are not part of the Objective-C language, so both
87836ac495dSmrg 'requiredProperty' and 'instanceProperty' should be set to YES.
87936ac495dSmrg This function returns NULL if the required property cannot be
88036ac495dSmrg found.
88136ac495dSmrg
88236ac495dSmrg Note that the traditional ABI does not store the list of properties
88336ac495dSmrg of a protocol in a compiled module, so the traditional ABI will
88436ac495dSmrg always return NULL. */
88536ac495dSmrg objc_EXPORT Property protocol_getProperty (Protocol *protocol, const char *propertyName,
88636ac495dSmrg BOOL requiredProperty, BOOL instanceProperty);
88736ac495dSmrg
88836ac495dSmrg /* Return all the properties of the protocol. The return value of the
88936ac495dSmrg function is a pointer to an area, allocated with malloc(), that
89036ac495dSmrg contains all the properties of the protocol. It does not
89136ac495dSmrg recursively include properties of the protocols adopted by this
89236ac495dSmrg protocol. The list is terminated by NULL. Optionally, if you pass
89336ac495dSmrg a non-NULL 'numberOfReturnedProperties' pointer, the unsigned int
89436ac495dSmrg that it points to will be filled with the number of properties
89536ac495dSmrg returned.
89636ac495dSmrg
89736ac495dSmrg Note that the traditional ABI does not store the list of properties
89836ac495dSmrg of a protocol in a compiled module, so the traditional ABI will
89936ac495dSmrg always return NULL and store 0 in numberOfReturnedProperties. */
90036ac495dSmrg objc_EXPORT Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfReturnedProperties);
90136ac495dSmrg
90236ac495dSmrg /* Return all the protocols that the protocol conforms to. The return
90336ac495dSmrg value of the function is a pointer to an area, allocated with
90436ac495dSmrg malloc(), that contains all the protocols formally adopted by the
90536ac495dSmrg protocol. It does not recursively include protocols adopted by the
90636ac495dSmrg protocols adopted by this protocol. The list is terminated by
90736ac495dSmrg NULL. Optionally, if you pass a non-NULL
90836ac495dSmrg 'numberOfReturnedProtocols' pointer, the unsigned int that it
90936ac495dSmrg points to will be filled with the number of protocols returned. */
91036ac495dSmrg objc_EXPORT Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOfReturnedProtocols);
91136ac495dSmrg
91236ac495dSmrg
91336ac495dSmrg /** Implementation: the following hook is in init.c. */
91436ac495dSmrg
91536ac495dSmrg /* This is a hook which is called by __objc_exec_class every time a
91636ac495dSmrg class or a category is loaded into the runtime. This may e.g. help
91736ac495dSmrg a dynamic loader determine the classes that have been loaded when
91836ac495dSmrg an object file is dynamically linked in. */
91936ac495dSmrg objc_EXPORT void (*_objc_load_callback)(Class _class, struct objc_category *category);
92036ac495dSmrg
92136ac495dSmrg
92236ac495dSmrg /** Implementation: the following functions are in objc-foreach.c. */
92336ac495dSmrg
92436ac495dSmrg /* 'objc_enumerationMutation()' is called when a collection is
92536ac495dSmrg mutated while being "fast enumerated". That is a hard error, and
92636ac495dSmrg objc_enumerationMutation is called to deal with it. 'collection'
92736ac495dSmrg is the collection object that was mutated during an enumeration.
92836ac495dSmrg
92936ac495dSmrg objc_enumerationMutation() will invoke the mutation handler if any
93036ac495dSmrg is set. Then, it will abort the program.
93136ac495dSmrg
93236ac495dSmrg Compatibility note: the Apple runtime will not abort the program
93336ac495dSmrg after calling the mutation handler. */
93436ac495dSmrg objc_EXPORT void objc_enumerationMutation (id collection);
93536ac495dSmrg
93636ac495dSmrg /* 'objc_set_enumeration_mutation_handler' can be used to set a
93736ac495dSmrg function that will be called (instead of aborting) when a fast
93836ac495dSmrg enumeration is mutated during enumeration. The handler will be
93936ac495dSmrg called with the 'collection' being mutated as the only argument and
94036ac495dSmrg it should not return; it should either exit the program, or could
94136ac495dSmrg throw an exception. The recommended implementation is to throw an
94236ac495dSmrg exception - the user can then use exception handlers to deal with
94336ac495dSmrg it.
94436ac495dSmrg
94536ac495dSmrg This function is not thread safe (other threads may be trying to
94636ac495dSmrg invoke the enumeration mutation handler while you are changing it!)
94736ac495dSmrg and should be called during during the program initialization
94836ac495dSmrg before threads are started. It is mostly reserved for "Foundation"
94936ac495dSmrg libraries; in the case of GNUstep, GNUstep Base may be using this
95036ac495dSmrg function to improve the standard enumeration mutation handling.
95136ac495dSmrg You probably shouldn't use this function unless you are writing
95236ac495dSmrg your own Foundation library. */
95336ac495dSmrg objc_EXPORT void objc_setEnumerationMutationHandler (void (*handler)(id));
95436ac495dSmrg
95536ac495dSmrg /* This structure (used during fast enumeration) is automatically
95636ac495dSmrg defined by the compiler (it is as if this definition was always
95736ac495dSmrg included in all Objective-C files). Note that it is usually
95836ac495dSmrg defined again with the name of NSFastEnumeration by "Foundation"
95936ac495dSmrg libraries such as GNUstep Base. And if NSFastEnumeration is
96036ac495dSmrg defined, the compiler will use it instead of
96136ac495dSmrg __objcFastEnumerationState when doing fast enumeration. */
96236ac495dSmrg /*
96336ac495dSmrg struct __objcFastEnumerationState
96436ac495dSmrg {
96536ac495dSmrg unsigned long state;
96636ac495dSmrg id *itemsPtr;
96736ac495dSmrg unsigned long *mutationsPtr;
96836ac495dSmrg unsigned long extra[5];
96936ac495dSmrg };
97036ac495dSmrg */
97136ac495dSmrg
97236ac495dSmrg
97336ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime has the functions
97436ac495dSmrg objc_copyImageNames (), class_getImageName () and
97536ac495dSmrg objc_copyClassNamesForImage () but they are undocumented. The GNU
97636ac495dSmrg runtime does not have them at the moment. */
97736ac495dSmrg
97836ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime has the functions
97936ac495dSmrg objc_setAssociatedObject (), objc_getAssociatedObject (),
98036ac495dSmrg objc_removeAssociatedObjects () and the objc_AssociationPolicy type
98136ac495dSmrg and related enum. The GNU runtime does not have them yet.
98236ac495dSmrg TODO: Implement them. */
98336ac495dSmrg
98436ac495dSmrg /* Compatibility Note: The Apple/NeXT runtime has the function
98536ac495dSmrg objc_setForwardHandler (). The GNU runtime does not have it
98636ac495dSmrg because messaging (and, in particular, forwarding) works in a
98736ac495dSmrg different (incompatible) way with the GNU runtime. If you need to
98836ac495dSmrg customize message forwarding at the Objective-C runtime level (that
98936ac495dSmrg is, if you are implementing your own "Foundation" library such as
99036ac495dSmrg GNUstep Base on top of the Objective-C runtime), in objc/message.h
99136ac495dSmrg there are hooks (that work in the framework of the GNU runtime) to
99236ac495dSmrg do so. */
99336ac495dSmrg
99436ac495dSmrg
99536ac495dSmrg /** Implementation: the following functions are in memory.c. */
99636ac495dSmrg
99736ac495dSmrg /* Traditional GNU Objective-C Runtime functions that are used for
99836ac495dSmrg memory allocation and disposal. These functions are used in the
99936ac495dSmrg same way as you use malloc, realloc, calloc and free and make sure
100036ac495dSmrg that memory allocation works properly with the garbage
100136ac495dSmrg collector.
100236ac495dSmrg
100336ac495dSmrg Compatibility Note: these functions are not available with the
100436ac495dSmrg Apple/NeXT runtime. */
100536ac495dSmrg
100636ac495dSmrg objc_EXPORT void *objc_malloc(size_t size);
100736ac495dSmrg
100836ac495dSmrg /* FIXME: Shouldn't the following be called objc_malloc_atomic ? The
100936ac495dSmrg GC function is GC_malloc_atomic() which makes sense.
101036ac495dSmrg */
101136ac495dSmrg objc_EXPORT void *objc_atomic_malloc(size_t size);
101236ac495dSmrg
101336ac495dSmrg objc_EXPORT void *objc_realloc(void *mem, size_t size);
101436ac495dSmrg
101536ac495dSmrg objc_EXPORT void *objc_calloc(size_t nelem, size_t size);
101636ac495dSmrg
101736ac495dSmrg objc_EXPORT void objc_free(void *mem);
101836ac495dSmrg
101936ac495dSmrg
102036ac495dSmrg /** Implementation: the following functions are in gc.c. */
102136ac495dSmrg
102236ac495dSmrg /* The GNU Objective-C Runtime has a different implementation of
102336ac495dSmrg garbage collection.
102436ac495dSmrg
102536ac495dSmrg Compatibility Note: these functions are not available with the
102636ac495dSmrg Apple/NeXT runtime. */
102736ac495dSmrg
102836ac495dSmrg /* Mark the instance variable as inaccessible to the garbage
102936ac495dSmrg collector. */
103036ac495dSmrg objc_EXPORT void class_ivar_set_gcinvisible (Class _class,
103136ac495dSmrg const char* ivarname,
103236ac495dSmrg BOOL gcInvisible);
103336ac495dSmrg
103436ac495dSmrg
103536ac495dSmrg /** Implementation: the following functions are in encoding.c. */
103636ac495dSmrg
103736ac495dSmrg /* Traditional GNU Objective-C Runtime functions that are currently
103836ac495dSmrg used to implement method forwarding.
103936ac495dSmrg
104036ac495dSmrg Compatibility Note: these functions are not available with the
104136ac495dSmrg Apple/NeXT runtime. */
104236ac495dSmrg
104336ac495dSmrg /* Return the size of a variable which has the specified 'type'
104436ac495dSmrg encoding. */
104536ac495dSmrg objc_EXPORT int objc_sizeof_type (const char *type);
104636ac495dSmrg
104736ac495dSmrg /* Return the align of a variable which has the specified 'type'
104836ac495dSmrg encoding. */
104936ac495dSmrg objc_EXPORT int objc_alignof_type (const char *type);
105036ac495dSmrg
105136ac495dSmrg /* Return the aligned size of a variable which has the specified
105236ac495dSmrg 'type' encoding. The aligned size is the size rounded up to the
105336ac495dSmrg nearest alignment. */
105436ac495dSmrg objc_EXPORT int objc_aligned_size (const char *type);
105536ac495dSmrg
105636ac495dSmrg /* Return the promoted size of a variable which has the specified
105736ac495dSmrg 'type' encoding. This is the size rounded up to the nearest
105836ac495dSmrg integral of the wordsize, taken to be the size of a void *. */
105936ac495dSmrg objc_EXPORT int objc_promoted_size (const char *type);
106036ac495dSmrg
106136ac495dSmrg
106236ac495dSmrg /* The following functions are used when parsing the type encoding of
106336ac495dSmrg methods, to skip over parts that are ignored. They take as
106436ac495dSmrg argument a pointer to a location inside the type encoding of a
106536ac495dSmrg method (which is a string) and return a new pointer, pointing to a
106636ac495dSmrg new location inside the string after having skipped the unwanted
106736ac495dSmrg information. */
106836ac495dSmrg
106936ac495dSmrg /* Skip some type qualifiers (_C_CONST, _C_IN, etc). These may
107036ac495dSmrg eventually precede typespecs occurring in method prototype
107136ac495dSmrg encodings. */
107236ac495dSmrg objc_EXPORT const char *objc_skip_type_qualifiers (const char *type);
107336ac495dSmrg
107436ac495dSmrg /* Skip one typespec element (_C_CLASS, _C_SEL, etc). If the typespec
107536ac495dSmrg is prepended by type qualifiers, these are skipped as well. */
107636ac495dSmrg objc_EXPORT const char *objc_skip_typespec (const char *type);
107736ac495dSmrg
107836ac495dSmrg /* Skip an offset. */
107936ac495dSmrg objc_EXPORT const char *objc_skip_offset (const char *type);
108036ac495dSmrg
108136ac495dSmrg /* Skip an argument specification (ie, skipping a typespec, which may
108236ac495dSmrg include qualifiers, and an offset too). */
108336ac495dSmrg objc_EXPORT const char *objc_skip_argspec (const char *type);
108436ac495dSmrg
108536ac495dSmrg /* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type'
108636ac495dSmrg (stopping at the first non-type qualifier found) and return an
108736ac495dSmrg unsigned int which is the logical OR of all the corresponding flags
108836ac495dSmrg (_F_CONST, _F_IN etc). */
108936ac495dSmrg objc_EXPORT unsigned objc_get_type_qualifiers (const char *type);
109036ac495dSmrg
109136ac495dSmrg
109236ac495dSmrg /* Note that the following functions work for very simple structures,
109336ac495dSmrg but get easily confused by more complicated ones (for example,
109436ac495dSmrg containing vectors). A better solution is required. These
109536ac495dSmrg functions are likely to change in the next GCC release. */
109636ac495dSmrg
109736ac495dSmrg /* The following three functions can be used to determine how a
109836ac495dSmrg structure is laid out by the compiler. For example:
109936ac495dSmrg
110036ac495dSmrg struct objc_struct_layout layout;
110136ac495dSmrg int i;
110236ac495dSmrg
110336ac495dSmrg objc_layout_structure (type, &layout);
110436ac495dSmrg while (objc_layout_structure_next_member (&layout))
110536ac495dSmrg {
110636ac495dSmrg int position, align;
110736ac495dSmrg const char *type;
110836ac495dSmrg
110936ac495dSmrg objc_layout_structure_get_info (&layout, &position, &align, &type);
111036ac495dSmrg printf ("element %d has offset %d, alignment %d\n",
111136ac495dSmrg i++, position, align);
111236ac495dSmrg }
111336ac495dSmrg
111436ac495dSmrg These functions are used by objc_sizeof_type and objc_alignof_type
111536ac495dSmrg functions to compute the size and alignment of structures. The
111636ac495dSmrg previous method of computing the size and alignment of a structure
111736ac495dSmrg was not working on some architectures, particularly on AIX, and in
111836ac495dSmrg the presence of bitfields inside the structure. */
111936ac495dSmrg struct objc_struct_layout
112036ac495dSmrg {
112136ac495dSmrg const char *original_type;
112236ac495dSmrg const char *type;
112336ac495dSmrg const char *prev_type;
112436ac495dSmrg unsigned int record_size;
112536ac495dSmrg unsigned int record_align;
112636ac495dSmrg };
112736ac495dSmrg
112836ac495dSmrg objc_EXPORT void objc_layout_structure (const char *type,
112936ac495dSmrg struct objc_struct_layout *layout);
113036ac495dSmrg objc_EXPORT BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);
113136ac495dSmrg objc_EXPORT void objc_layout_finish_structure (struct objc_struct_layout *layout,
113236ac495dSmrg unsigned int *size,
113336ac495dSmrg unsigned int *align);
113436ac495dSmrg objc_EXPORT void objc_layout_structure_get_info (struct objc_struct_layout *layout,
113536ac495dSmrg unsigned int *offset,
113636ac495dSmrg unsigned int *align,
113736ac495dSmrg const char **type);
113836ac495dSmrg
113936ac495dSmrg #ifdef __cplusplus
114036ac495dSmrg }
114136ac495dSmrg #endif /* __cplusplus */
114236ac495dSmrg
114336ac495dSmrg #endif
1144