/* GNU Objective-C Runtime API - Modern API Copyright (C) 2010-2026 Free Software Foundation, Inc. Contributed by Nicola Pero <nicola.pero@meta-innovation.com> This file is part of GCC. GCC is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 3, or (at your option) anylater version. GCC is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the GNU General PublicLicense for more details. Under Section 7 of GPL version 3, you are granted additionalpermissions described in the GCC Runtime Library Exception, version3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License anda copy of the GCC Runtime Library Exception along with this program;see the files COPYING3 and COPYING.RUNTIME respectively. If not, see<http://www.gnu.org/licenses/>. */ #ifndef __objc_runtime_INCLUDE_GNU#define __objc_runtime_INCLUDE_GNU /* This file declares the "modern" GNU Objective-C Runtime API. This API replaced the "traditional" GNU Objective-C Runtime API (which used to be declared in objc/objc-api.h) which is the one supported by older versions of the GNU Objective-C Runtime. The "modern" API is very similar to the API used by the modern Apple/NeXT runtime.*/#include "objc.h"#include "objc-decls.h" #ifdef __cplusplusextern "C" {#endif /* __cplusplus */ /* An 'Ivar' represents an instance variable. It holds information about the name, type and offset of the instance variable. */typedef struct objc_ivar *Ivar; /* A 'Property' represents a property. It holds information about the name of the property, and its attributes. Compatibility Note: the Apple/NeXT runtime defines this as objc_property_t, so we define it that way as well, but obviously Property is the right name. */typedef struct objc_property *Property;typedef struct objc_property *objc_property_t; /* A 'Method' represents a method. It holds information about the name, types and the IMP of the method. */typedef struct objc_method *Method; /* A 'Category' represents a category. It holds information about the name of the category, the class it belongs to, and the methods, protocols and such like provided by the category. */typedef struct objc_category *Category; /* 'Protocol' is defined in objc/objc.h (which is included by this file). */ /* Method descriptor returned by introspective Object methods. At the moment, this is really just the first part of the more complete objc_method structure used internally by the runtime. (PS: In the GNU Objective-C Runtime, selectors already include a type, so an objc_method_description does not add much to a SEL. But in other runtimes, that is not the case, which is why objc_method_description exists). */struct objc_method_description{ SEL name; /* Selector (name and signature) */ char *types; /* Type encoding */}; /* The following are used in encode strings to describe the type of Ivars and Methods. */#define _C_ID '@'#define _C_CLASS '#'#define _C_SEL ':'#define _C_CHR 'c'#define _C_UCHR 'C'#define _C_SHT 's'#define _C_USHT 'S'#define _C_INT 'i'#define _C_UINT 'I'#define _C_LNG 'l'#define _C_ULNG 'L'#define _C_LNG_LNG 'q'#define _C_ULNG_LNG 'Q'#define _C_FLT 'f'#define _C_DBL 'd'#define _C_LNG_DBL 'D'#define _C_BFLD 'b'#define _C_BOOL 'B'#define _C_VOID 'v'#define _C_UNDEF '?'#define _C_PTR '^'#define _C_CHARPTR '*'#define _C_ARY_B '['#define _C_ARY_E ']'#define _C_UNION_B '('#define _C_UNION_E ')'#define _C_STRUCT_B '{'#define _C_STRUCT_E '}'#define _C_VECTOR '!'#define _C_COMPLEX 'j' /* _C_ATOM is never generated by the compiler. You can treat it as equivalent to "*". */#define _C_ATOM '%' /* The following are used in encode strings to describe some qualifiers of method and ivar types. */#define _C_CONST 'r'#define _C_IN 'n'#define _C_INOUT 'N'#define _C_OUT 'o'#define _C_BYCOPY 'O'#define _C_BYREF 'R'#define _C_ONEWAY 'V'#define _C_GCINVISIBLE '|' /* The same when used as flags. */#define _F_CONST 0x01#define _F_IN 0x01#define _F_OUT 0x02#define _F_INOUT 0x03#define _F_BYCOPY 0x04#define _F_BYREF 0x08#define _F_ONEWAY 0x10#define _F_GCINVISIBLE 0x20 /** Implementation: the following functions are defined inline. */ /* Return the class of 'object', or Nil if the object is nil. If 'object' is a class, the meta class is returned; if 'object' is a meta class, the root meta class is returned (note that this is different from the traditional GNU Objective-C Runtime API function object_get_class(), which for a meta class would return the meta class itself). This function is inline, so it is really fast and should be used instead of accessing object->class_pointer directly. */static inline Classobject_getClass (id object){ if (object != nil) return object->class_pointer; else return Nil;} /** Implementation: the following functions are in selector.c. */ /* Return the name of a given selector. If 'selector' is NULL, return "<null selector>". */objc_EXPORT const char *sel_getName (SEL selector); /* Return the type of a given selector. Return NULL if selector is NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */objc_EXPORT const char *sel_getTypeEncoding (SEL selector); /* This is the same as sel_registerName (). Please use sel_registerName () instead. */objc_EXPORT SEL sel_getUid (const char *name); /* Register a selector with a given name (but unspecified types). If you know the types, it is better to call sel_registerTypedName(). If a selector with this name and no types already exists, it is returned. Note that this function should really be called 'objc_registerSelector'. Return NULL if 'name' is NULL. */objc_EXPORT SEL sel_registerName (const char *name); /* Register a selector with a given name and types. If a selector with this name and types already exists, it is returned. Note that this function should really be called 'objc_registerTypedSelector', and it's called 'sel_registerTypedName' only for consistency with 'sel_registerName'. Return NULL if 'name' is NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type); /* Return YES if first_selector is the same as second_selector, and NO if not. */objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector); /* Return all the selectors with the supplied name. In the GNU runtime, selectors are typed and there may be multiple selectors with the same name but a different type. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the selectors with the supplier name known to the runtime. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int that it points to will be filled with the number of selectors returned. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name, unsigned int *numberOfReturnedSelectors); /* Return a selector with name 'name' and a non-zero type encoding, if there is a single selector with a type, and with that name, registered with the runtime. If there is no such selector, or if there are multiple selectors with the same name but conflicting types, NULL is returned. Return NULL if 'name' is NULL. This is useful if you have the name of the selector, and would really like to get a selector for it that includes the type encoding. Unfortunately, if the program contains multiple selector with the same name but different types, sel_getTypedSelector cannot possibly know which one you need, and so will return NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */objc_EXPORT SEL sel_getTypedSelector (const char *name); /** Implementation: the following functions are in objects.c. */ /* Create an instance of class 'class_', adding extraBytes to the size of the returned object. This method allocates the appropriate amount of memory for the instance, initializes it to zero, then calls all the C++ constructors on appropriate C++ instance variables of the instance (if any) (TODO: The C++ constructors bit is not implemented yet). */objc_EXPORT id class_createInstance (Class class_, size_t extraBytes); /* Copy an object and return the copy. extraBytes should be identical to the extraBytes parameter that was passed when creating the original object. */objc_EXPORT id object_copy (id object, size_t extraBytes); /* Dispose of an object. This method calls the appropriate C++ destructors on appropriate C++ instance variables of the instance (if any) (TODO: This is not implemented yet), then frees the memory for the instance. */objc_EXPORT id object_dispose (id object); /* Return the name of the class of 'object'. If 'object' is 'nil', returns "Nil". */objc_EXPORT const char * object_getClassName (id object); /* Change the class of object to be class_. Return the previous class of object. This is currently not really thread-safe. */objc_EXPORT Class object_setClass (id object, Class class_); /** Implementation: the following functions are in ivars.c. */ /* Return an instance variable given the class and the instance variable name. This is an expensive function to call, so try to reuse the returned Ivar if you can. */objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name); /* Return a class variable given the class and the class variable name. This is an expensive function to call, so try to reuse the returned Ivar if you can. This function always returns NULL since class variables are currently unavailable in Objective-C. */objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name); /* If the object was created in class_createInstance() with some extraBytes, returns a pointer to them. If it was not, then the returned pointer may make no sense. */objc_EXPORT void * object_getIndexedIvars (id object); /* Get the value of an instance variable of type 'id'. The function returns the instance variable. To get the value of the instance variable, you should pass as 'returnValue' a pointer to an 'id'; the value will be copied there. Note that 'returnValue' is really a 'void *', not a 'void **'. This function really works only with instance variables of type 'id'; for other types of instance variables, access directly the data at (char *)object + ivar_getOffset (ivar). */objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue); /* Set the value of an instance variable. The value to set is passed in 'newValue' (which really is an 'id', not a 'void *'). The function returns the instance variable. This function really works only with instance variables of type 'id'; for other types of instance variables, access directly the data at (char *)object + ivar_getOffset (ivar). */objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue); /* Get the value of an instance variable of type 'id' of the object 'object'. This is faster than object_getInstanceVariable if you already have the instance variable because it avoids the expensive call to class_getInstanceVariable that is done by object_getInstanceVariable. */objc_EXPORT id object_getIvar (id object, Ivar variable); /* Set the value of an instance variable of type 'id' of the object 'object'. This is faster than object_setInstanceVariable if you already have the instance variable because it avoids the expensive call to class_getInstanceVariable that is done by object_setInstanceVariable. */objc_EXPORT void object_setIvar (id object, Ivar variable, id value); /* Return the name of the instance variable. Return NULL if 'variable' is NULL. */objc_EXPORT const char * ivar_getName (Ivar variable); /* Return the offset of the instance variable from the start of the object data. Return 0 if 'variable' is NULL. */objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable); /* Return the type encoding of the variable. Return NULL if 'variable' is NULL. */objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable); /* Return all the instance variables of the class. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the instance variables of the class. It does not include instance variables of superclasses. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedIvars' pointer, the unsigned int that it points to will be filled with the number of instance variables returned. Return NULL for classes still in construction (ie, allocated using objc_allocatedClassPair() but not yet registered with the runtime using objc_registerClassPair()). */objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars); /* Add an instance variable with name 'ivar_name' to class 'class_', where 'class_' is a class in construction that has been created using objc_allocateClassPair() and has not been registered with the runtime using objc_registerClassPair() yet. You cannot add instance variables to classes already registered with the runtime. 'size' is the size of the instance variable, 'log_2_of_alignment' the alignment as a power of 2 (so 0 means alignment to a 1 byte boundary, 1 means alignment to a 2 byte boundary, 2 means alignment to a 4 byte boundary, etc), and 'type' the type encoding of the variable type. You can use sizeof(), log2(__alignof__()) and @encode() to determine the right 'size', 'alignment' and 'type' for your instance variable. For example, to add an instance variable name "my_variable" and of type 'id', you can use: class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)), @encode (id)); Return YES if the variable was added, and NO if not. In particular, return NO if 'class_' is Nil, or a meta-class or a class not in construction. Return Nil also if 'ivar_name' or 'type' is NULL, or 'size' is 0. */objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size, unsigned char log_2_of_alignment, const char *type); /* Return the name of the property. Return NULL if 'property' is NULL. */objc_EXPORT const char * property_getName (Property property); /* Return the attributes of the property as a string. Return NULL if 'property' is NULL. */objc_EXPORT const char * property_getAttributes (Property property); /* Return the property with name 'propertyName' of the class 'class_'. This function returns NULL if the required property cannot be found. Return NULL if 'class_' or 'propertyName' is NULL. Note that the traditional ABI does not store the list of properties of a class in a compiled module, so the traditional ABI will always return NULL. */objc_EXPORT Property class_getProperty (Class class_, const char *propertyName); /* Return all the properties of the class. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the properties of the class. It does not include properties of superclasses. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedIvars' pointer, the unsigned int that it points to will be filled with the number of properties returned. Note that the traditional ABI does not store the list of properties of a class in a compiled module, so the traditional ABI will always return an empty list. */objc_EXPORT Property * class_copyPropertyList (Class class_, unsigned int *numberOfReturnedProperties); /* Return the ivar layout for class 'class_'. At the moment this function always returns NULL. */objc_EXPORT const char * class_getIvarLayout (Class class_); /* Return the weak ivar layout for class 'class_'. At the moment this function always returns NULL. */objc_EXPORT const char * class_getWeakIvarLayout (Class class_); /* Set the ivar layout for class 'class_'. At the moment, this function does nothing. */objc_EXPORT void class_setIvarLayout (Class class_, const char *layout); /* Set the weak ivar layout for class 'class_'. At the moment, this function does nothing. With the GNU runtime, you should use class_ivar_set_gcinvisible () to hide variables from the Garbage Collector. */objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout); /** Implementation: the following functions are in class.c. */ /* Compatibility Note: The Apple/NeXT runtime does not have objc_get_unknown_class_handler and objc_setGetUnknownClassHandler(). They provide functionality that the traditional GNU Objective-C Runtime API used to provide via the _objc_lookup_class hook. */ /* An 'objc_get_unknown_class_handler' function is used by objc_getClass() to get a class that is currently unknown to the compiler. You could use it for example to have the class loaded by dynamically loading a library. 'class_name' is the name of the class. The function should return the Class object if it manages to load the class, and Nil if not. */typedef Class (*objc_get_unknown_class_handler)(const char *class_name); /* Sets a new handler function for getting unknown classes (to be used by objc_getClass () and related), and returns the previous one. This function is not safe to call in a multi-threaded environment because other threads may be trying to use the get unknown class handler while you change it! */objc_EXPORT objc_get_unknown_class_handlerobjc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler); /* Return the class with name 'name', if it is already registered with the runtime. If it is not registered, and objc_setGetUnknownClassHandler() has been called to set a handler for unknown classes, the handler is called to give it a chance to load the class in some other way. If the class is not known to the runtime and the handler is not set or returns Nil, objc_getClass() returns Nil. */objc_EXPORT Class objc_getClass (const char *name); /* Return the class with name 'name', if it is already registered with the runtime. Return Nil if not. This function does not call the objc_get_unknown_class_handler function if the class is not found. */objc_EXPORT Class objc_lookUpClass (const char *name); /* Return the meta class associated to the class with name 'name', if it is already registered with the runtime. First, it finds the class using objc_getClass(). Then, it returns the associated meta class. If the class could not be found using objc_getClass(), returns Nil. */objc_EXPORT Class objc_getMetaClass (const char *name); /* This is identical to objc_getClass(), but if the class is not found, it aborts the process instead of returning Nil. */objc_EXPORT Class objc_getRequiredClass (const char *name); /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of classes currently registered with the runtime. If 'returnValue' is not NULL, it should be a (Class *) pointer to an area of memory which can contain up to 'maxNumberOfClassesToReturn' Class records. 'objc_getClassList' will fill the area pointed to by 'returnValue' with all the Classes registered with the runtime (or up to maxNumberOfClassesToReturn if there are more than maxNumberOfClassesToReturn). The function return value is the number of classes actually returned in 'returnValue'. */objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn); /* Compatibility Note: The Apple/NeXT runtime also has Class objc_getFutureClass (const char *name); void objc_setFutureClass (Class class_, const char *name); the documentation is unclear on what they are supposed to do, and the GNU Objective-C Runtime currently does not provide them. */ /* Return the name of the class 'class_', or the string "nil" if the class_ is Nil. */objc_EXPORT const char * class_getName (Class class_); /* Return YES if 'class_' is a meta class, and NO if not. If 'class_' is Nil, return NO. */objc_EXPORT BOOL class_isMetaClass (Class class_); /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a root class, return Nil. This function also works if 'class_' is aLines 1–500 of 1143. Load more
/* GNU Objective-C Runtime API - Modern API Copyright (C) 2010-2026 Free Software Foundation, Inc. Contributed by Nicola Pero <nicola.pero@meta-innovation.com> This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ #ifndef __objc_runtime_INCLUDE_GNU #define __objc_runtime_INCLUDE_GNU /* This file declares the "modern" GNU Objective-C Runtime API. This API replaced the "traditional" GNU Objective-C Runtime API (which used to be declared in objc/objc-api.h) which is the one supported by older versions of the GNU Objective-C Runtime. The "modern" API is very similar to the API used by the modern Apple/NeXT runtime. */ #include "objc.h" #include "objc-decls.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* An 'Ivar' represents an instance variable. It holds information about the name, type and offset of the instance variable. */ typedef struct objc_ivar *Ivar; /* A 'Property' represents a property. It holds information about the name of the property, and its attributes. Compatibility Note: the Apple/NeXT runtime defines this as objc_property_t, so we define it that way as well, but obviously Property is the right name. */ typedef struct objc_property *Property; typedef struct objc_property *objc_property_t; /* A 'Method' represents a method. It holds information about the name, types and the IMP of the method. */ typedef struct objc_method *Method; /* A 'Category' represents a category. It holds information about the name of the category, the class it belongs to, and the methods, protocols and such like provided by the category. */ typedef struct objc_category *Category; /* 'Protocol' is defined in objc/objc.h (which is included by this file). */ /* Method descriptor returned by introspective Object methods. At the moment, this is really just the first part of the more complete objc_method structure used internally by the runtime. (PS: In the GNU Objective-C Runtime, selectors already include a type, so an objc_method_description does not add much to a SEL. But in other runtimes, that is not the case, which is why objc_method_description exists). */ struct objc_method_description { SEL name; /* Selector (name and signature) */ char *types; /* Type encoding */ }; /* The following are used in encode strings to describe the type of Ivars and Methods. */ #define _C_ID '@' #define _C_CLASS '#' #define _C_SEL ':' #define _C_CHR 'c' #define _C_UCHR 'C' #define _C_SHT 's' #define _C_USHT 'S' #define _C_INT 'i' #define _C_UINT 'I' #define _C_LNG 'l' #define _C_ULNG 'L' #define _C_LNG_LNG 'q' #define _C_ULNG_LNG 'Q' #define _C_FLT 'f' #define _C_DBL 'd' #define _C_LNG_DBL 'D' #define _C_BFLD 'b' #define _C_BOOL 'B' #define _C_VOID 'v' #define _C_UNDEF '?' #define _C_PTR '^' #define _C_CHARPTR '*' #define _C_ARY_B '[' #define _C_ARY_E ']' #define _C_UNION_B '(' #define _C_UNION_E ')' #define _C_STRUCT_B '{' #define _C_STRUCT_E '}' #define _C_VECTOR '!' #define _C_COMPLEX 'j' /* _C_ATOM is never generated by the compiler. You can treat it as equivalent to "*". */ #define _C_ATOM '%' /* The following are used in encode strings to describe some qualifiers of method and ivar types. */ #define _C_CONST 'r' #define _C_IN 'n' #define _C_INOUT 'N' #define _C_OUT 'o' #define _C_BYCOPY 'O' #define _C_BYREF 'R' #define _C_ONEWAY 'V' #define _C_GCINVISIBLE '|' /* The same when used as flags. */ #define _F_CONST 0x01 #define _F_IN 0x01 #define _F_OUT 0x02 #define _F_INOUT 0x03 #define _F_BYCOPY 0x04 #define _F_BYREF 0x08 #define _F_ONEWAY 0x10 #define _F_GCINVISIBLE 0x20 /** Implementation: the following functions are defined inline. */ /* Return the class of 'object', or Nil if the object is nil. If 'object' is a class, the meta class is returned; if 'object' is a meta class, the root meta class is returned (note that this is different from the traditional GNU Objective-C Runtime API function object_get_class(), which for a meta class would return the meta class itself). This function is inline, so it is really fast and should be used instead of accessing object->class_pointer directly. */ static inline Class object_getClass (id object) { if (object != nil) return object->class_pointer; else return Nil; } /** Implementation: the following functions are in selector.c. */ /* Return the name of a given selector. If 'selector' is NULL, return "<null selector>". */ objc_EXPORT const char *sel_getName (SEL selector); /* Return the type of a given selector. Return NULL if selector is NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */ objc_EXPORT const char *sel_getTypeEncoding (SEL selector); /* This is the same as sel_registerName (). Please use sel_registerName () instead. */ objc_EXPORT SEL sel_getUid (const char *name); /* Register a selector with a given name (but unspecified types). If you know the types, it is better to call sel_registerTypedName(). If a selector with this name and no types already exists, it is returned. Note that this function should really be called 'objc_registerSelector'. Return NULL if 'name' is NULL. */ objc_EXPORT SEL sel_registerName (const char *name); /* Register a selector with a given name and types. If a selector with this name and types already exists, it is returned. Note that this function should really be called 'objc_registerTypedSelector', and it's called 'sel_registerTypedName' only for consistency with 'sel_registerName'. Return NULL if 'name' is NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */ objc_EXPORT SEL sel_registerTypedName (const char *name, const char *type); /* Return YES if first_selector is the same as second_selector, and NO if not. */ objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector); /* Return all the selectors with the supplied name. In the GNU runtime, selectors are typed and there may be multiple selectors with the same name but a different type. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the selectors with the supplier name known to the runtime. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedSelectors' pointer, the unsigned int that it points to will be filled with the number of selectors returned. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */ objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name, unsigned int *numberOfReturnedSelectors); /* Return a selector with name 'name' and a non-zero type encoding, if there is a single selector with a type, and with that name, registered with the runtime. If there is no such selector, or if there are multiple selectors with the same name but conflicting types, NULL is returned. Return NULL if 'name' is NULL. This is useful if you have the name of the selector, and would really like to get a selector for it that includes the type encoding. Unfortunately, if the program contains multiple selector with the same name but different types, sel_getTypedSelector cannot possibly know which one you need, and so will return NULL. Compatibility Note: the Apple/NeXT runtime has untyped selectors, so it does not have this function, which is specific to the GNU Runtime. */ objc_EXPORT SEL sel_getTypedSelector (const char *name); /** Implementation: the following functions are in objects.c. */ /* Create an instance of class 'class_', adding extraBytes to the size of the returned object. This method allocates the appropriate amount of memory for the instance, initializes it to zero, then calls all the C++ constructors on appropriate C++ instance variables of the instance (if any) (TODO: The C++ constructors bit is not implemented yet). */ objc_EXPORT id class_createInstance (Class class_, size_t extraBytes); /* Copy an object and return the copy. extraBytes should be identical to the extraBytes parameter that was passed when creating the original object. */ objc_EXPORT id object_copy (id object, size_t extraBytes); /* Dispose of an object. This method calls the appropriate C++ destructors on appropriate C++ instance variables of the instance (if any) (TODO: This is not implemented yet), then frees the memory for the instance. */ objc_EXPORT id object_dispose (id object); /* Return the name of the class of 'object'. If 'object' is 'nil', returns "Nil". */ objc_EXPORT const char * object_getClassName (id object); /* Change the class of object to be class_. Return the previous class of object. This is currently not really thread-safe. */ objc_EXPORT Class object_setClass (id object, Class class_); /** Implementation: the following functions are in ivars.c. */ /* Return an instance variable given the class and the instance variable name. This is an expensive function to call, so try to reuse the returned Ivar if you can. */ objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name); /* Return a class variable given the class and the class variable name. This is an expensive function to call, so try to reuse the returned Ivar if you can. This function always returns NULL since class variables are currently unavailable in Objective-C. */ objc_EXPORT Ivar class_getClassVariable (Class class_, const char *name); /* If the object was created in class_createInstance() with some extraBytes, returns a pointer to them. If it was not, then the returned pointer may make no sense. */ objc_EXPORT void * object_getIndexedIvars (id object); /* Get the value of an instance variable of type 'id'. The function returns the instance variable. To get the value of the instance variable, you should pass as 'returnValue' a pointer to an 'id'; the value will be copied there. Note that 'returnValue' is really a 'void *', not a 'void **'. This function really works only with instance variables of type 'id'; for other types of instance variables, access directly the data at (char *)object + ivar_getOffset (ivar). */ objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue); /* Set the value of an instance variable. The value to set is passed in 'newValue' (which really is an 'id', not a 'void *'). The function returns the instance variable. This function really works only with instance variables of type 'id'; for other types of instance variables, access directly the data at (char *)object + ivar_getOffset (ivar). */ objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue); /* Get the value of an instance variable of type 'id' of the object 'object'. This is faster than object_getInstanceVariable if you already have the instance variable because it avoids the expensive call to class_getInstanceVariable that is done by object_getInstanceVariable. */ objc_EXPORT id object_getIvar (id object, Ivar variable); /* Set the value of an instance variable of type 'id' of the object 'object'. This is faster than object_setInstanceVariable if you already have the instance variable because it avoids the expensive call to class_getInstanceVariable that is done by object_setInstanceVariable. */ objc_EXPORT void object_setIvar (id object, Ivar variable, id value); /* Return the name of the instance variable. Return NULL if 'variable' is NULL. */ objc_EXPORT const char * ivar_getName (Ivar variable); /* Return the offset of the instance variable from the start of the object data. Return 0 if 'variable' is NULL. */ objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable); /* Return the type encoding of the variable. Return NULL if 'variable' is NULL. */ objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable); /* Return all the instance variables of the class. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the instance variables of the class. It does not include instance variables of superclasses. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedIvars' pointer, the unsigned int that it points to will be filled with the number of instance variables returned. Return NULL for classes still in construction (ie, allocated using objc_allocatedClassPair() but not yet registered with the runtime using objc_registerClassPair()). */ objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfReturnedIvars); /* Add an instance variable with name 'ivar_name' to class 'class_', where 'class_' is a class in construction that has been created using objc_allocateClassPair() and has not been registered with the runtime using objc_registerClassPair() yet. You cannot add instance variables to classes already registered with the runtime. 'size' is the size of the instance variable, 'log_2_of_alignment' the alignment as a power of 2 (so 0 means alignment to a 1 byte boundary, 1 means alignment to a 2 byte boundary, 2 means alignment to a 4 byte boundary, etc), and 'type' the type encoding of the variable type. You can use sizeof(), log2(__alignof__()) and @encode() to determine the right 'size', 'alignment' and 'type' for your instance variable. For example, to add an instance variable name "my_variable" and of type 'id', you can use: class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)), @encode (id)); Return YES if the variable was added, and NO if not. In particular, return NO if 'class_' is Nil, or a meta-class or a class not in construction. Return Nil also if 'ivar_name' or 'type' is NULL, or 'size' is 0. */ objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size, unsigned char log_2_of_alignment, const char *type); /* Return the name of the property. Return NULL if 'property' is NULL. */ objc_EXPORT const char * property_getName (Property property); /* Return the attributes of the property as a string. Return NULL if 'property' is NULL. */ objc_EXPORT const char * property_getAttributes (Property property); /* Return the property with name 'propertyName' of the class 'class_'. This function returns NULL if the required property cannot be found. Return NULL if 'class_' or 'propertyName' is NULL. Note that the traditional ABI does not store the list of properties of a class in a compiled module, so the traditional ABI will always return NULL. */ objc_EXPORT Property class_getProperty (Class class_, const char *propertyName); /* Return all the properties of the class. The return value of the function is a pointer to an area, allocated with malloc(), that contains all the properties of the class. It does not include properties of superclasses. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedIvars' pointer, the unsigned int that it points to will be filled with the number of properties returned. Note that the traditional ABI does not store the list of properties of a class in a compiled module, so the traditional ABI will always return an empty list. */ objc_EXPORT Property * class_copyPropertyList (Class class_, unsigned int *numberOfReturnedProperties); /* Return the ivar layout for class 'class_'. At the moment this function always returns NULL. */ objc_EXPORT const char * class_getIvarLayout (Class class_); /* Return the weak ivar layout for class 'class_'. At the moment this function always returns NULL. */ objc_EXPORT const char * class_getWeakIvarLayout (Class class_); /* Set the ivar layout for class 'class_'. At the moment, this function does nothing. */ objc_EXPORT void class_setIvarLayout (Class class_, const char *layout); /* Set the weak ivar layout for class 'class_'. At the moment, this function does nothing. With the GNU runtime, you should use class_ivar_set_gcinvisible () to hide variables from the Garbage Collector. */ objc_EXPORT void class_setWeakIvarLayout (Class class_, const char *layout); /** Implementation: the following functions are in class.c. */ /* Compatibility Note: The Apple/NeXT runtime does not have objc_get_unknown_class_handler and objc_setGetUnknownClassHandler(). They provide functionality that the traditional GNU Objective-C Runtime API used to provide via the _objc_lookup_class hook. */ /* An 'objc_get_unknown_class_handler' function is used by objc_getClass() to get a class that is currently unknown to the compiler. You could use it for example to have the class loaded by dynamically loading a library. 'class_name' is the name of the class. The function should return the Class object if it manages to load the class, and Nil if not. */ typedef Class (*objc_get_unknown_class_handler)(const char *class_name); /* Sets a new handler function for getting unknown classes (to be used by objc_getClass () and related), and returns the previous one. This function is not safe to call in a multi-threaded environment because other threads may be trying to use the get unknown class handler while you change it! */ objc_EXPORT objc_get_unknown_class_handler objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler); /* Return the class with name 'name', if it is already registered with the runtime. If it is not registered, and objc_setGetUnknownClassHandler() has been called to set a handler for unknown classes, the handler is called to give it a chance to load the class in some other way. If the class is not known to the runtime and the handler is not set or returns Nil, objc_getClass() returns Nil. */ objc_EXPORT Class objc_getClass (const char *name); /* Return the class with name 'name', if it is already registered with the runtime. Return Nil if not. This function does not call the objc_get_unknown_class_handler function if the class is not found. */ objc_EXPORT Class objc_lookUpClass (const char *name); /* Return the meta class associated to the class with name 'name', if it is already registered with the runtime. First, it finds the class using objc_getClass(). Then, it returns the associated meta class. If the class could not be found using objc_getClass(), returns Nil. */ objc_EXPORT Class objc_getMetaClass (const char *name); /* This is identical to objc_getClass(), but if the class is not found, it aborts the process instead of returning Nil. */ objc_EXPORT Class objc_getRequiredClass (const char *name); /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of classes currently registered with the runtime. If 'returnValue' is not NULL, it should be a (Class *) pointer to an area of memory which can contain up to 'maxNumberOfClassesToReturn' Class records. 'objc_getClassList' will fill the area pointed to by 'returnValue' with all the Classes registered with the runtime (or up to maxNumberOfClassesToReturn if there are more than maxNumberOfClassesToReturn). The function return value is the number of classes actually returned in 'returnValue'. */ objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn); /* Compatibility Note: The Apple/NeXT runtime also has Class objc_getFutureClass (const char *name); void objc_setFutureClass (Class class_, const char *name); the documentation is unclear on what they are supposed to do, and the GNU Objective-C Runtime currently does not provide them. */ /* Return the name of the class 'class_', or the string "nil" if the class_ is Nil. */ objc_EXPORT const char * class_getName (Class class_); /* Return YES if 'class_' is a meta class, and NO if not. If 'class_' is Nil, return NO. */ objc_EXPORT BOOL class_isMetaClass (Class class_); /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a root class, return Nil. This function also works if 'class_' is a