ObjFW
Classes | Macros | Typedefs | Functions
ObjFWRT.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for ObjFWRT.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  objc_super
 A struct representing a call to super. More...
 

Macros

#define Nil   (Class _Null_unspecified)0
 A value representing no class.
 
#define nil   (id _Null_unspecified)0
 A value representing no object.
 
#define YES   true
 An Objective-C boolean representing true. More...
 
#define NO   false
 An Objective-C boolean representing false. More...
 

Typedefs

typedef struct objc_class * Class
 A pointer to a class.
 
typedef struct objc_object * id
 A pointer to any object.
 
typedef const struct objc_selector * SEL
 A selector. More...
 
typedef const struct objc_method * Method
 A method. More...
 
typedef const struct objc_protocol * Protocol
 A protocol.
 
typedef const struct objc_ivar * Ivar
 An instance variable.
 
typedef const struct objc_property * objc_property_t
 A property.
 
typedef bool BOOL
 An Objective-C boolean. Either YES or NO. More...
 
typedef id _Nullable(* IMP) (id _Nonnull object, SEL _Nonnull selector,...)
 A method implemenation. More...
 
typedef void(* objc_uncaught_exception_handler_t) (id _Nullable exception)
 A handler for uncaught exceptions. More...
 
typedef void(* objc_enumeration_mutation_handler_t) (id _Nonnull object)
 A handler for mutation during enumeration. More...
 

Functions

SEL _Nonnull sel_registerName (const char *_Nonnull name)
 Registers a selector with the specified name with the runtime. More...
 
const char *_Nonnull sel_getName (SEL _Nonnull selector)
 Returns the name of the specified selector. More...
 
bool sel_isEqual (SEL _Nonnull selector1, SEL _Nonnull selector2)
 Checks two selectors for equality. More...
 
Class _Nonnull objc_allocateClassPair (Class _Nullable superclass, const char *_Nonnull name, size_t extraBytes)
 Allocates a new class and its metaclass. More...
 
void objc_registerClassPair (Class _Nonnull class_)
 Registers an already allocated class pair. More...
 
unsigned int objc_getClassList (Class _Nonnull *_Nullable buffer, unsigned int count)
 Gets the list of all classes known to the runtime. More...
 
Class _Nonnull *_Nonnull objc_copyClassList (unsigned int *_Nullable length)
 Copies the list of all classes known to the runtime. More...
 
bool class_isMetaClass (Class _Nullable class_)
 Returns whether the specified class is a metaclass. More...
 
const char *_Nullable class_getName (Class _Nullable class_)
 Returns the name of the specified class. More...
 
Class _Nullable class_getSuperclass (Class _Nullable class_)
 Returns the superclass of the specified class. More...
 
unsigned long class_getInstanceSize (Class _Nullable class_)
 Returns the instance size of the specified class. More...
 
bool class_respondsToSelector (Class _Nullable class_, SEL _Nonnull selector)
 Returns whether the specified class responds to the specified selector. More...
 
bool class_conformsToProtocol (Class _Nullable class_, Protocol *_Nonnull protocol)
 Returns whether the specified class conforms to the specified protocol. More...
 
IMP _Nullable class_getMethodImplementation (Class _Nullable class_, SEL _Nonnull selector)
 Returns the class's method implementation for the specified selector. More...
 
IMP _Nullable class_getMethodImplementation_stret (Class _Nullable class_, SEL _Nonnull selector)
 Returns the class's method implementation for the specified selector. More...
 
Method _Nullable class_getInstanceMethod (Class _Nullable class_, SEL _Nonnull selector)
 Returns the class's instance method for the specified selector. More...
 
bool class_addMethod (Class _Nonnull class_, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding)
 Adds the specified method to the class. More...
 
IMP _Nullable class_replaceMethod (Class _Nonnull class_, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding)
 Replaces or adds the specified method of the class. More...
 
Class _Nullable object_getClass (id _Nullable object)
 Returns the object's class. More...
 
Class _Nullable object_setClass (id _Nullable object, Class _Nonnull class_)
 Sets the object's class. More...
 
const char *_Nullable object_getClassName (id _Nullable object)
 Returns the object's class name. More...
 
const char *_Nonnull protocol_getName (Protocol *_Nonnull protocol)
 Returns the name of the specified protocol. More...
 
bool protocol_isEqual (Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)
 Returns whether two protocols are equal. More...
 
bool protocol_conformsToProtocol (Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)
 Returns whether the first protocol conforms to the second protocol. More...
 
Method _Nullable *_Nullable class_copyMethodList (Class _Nullable class_, unsigned int *_Nullable outCount)
 Copies the method list of the specified class. More...
 
SEL _Nonnull method_getName (Method _Nonnull method)
 Returns the name of the specified method. More...
 
const char *_Nullable method_getTypeEncoding (Method _Nonnull method)
 Returns the type encoding of the specified method. More...
 
Ivar _Nullable *_Nullable class_copyIvarList (Class _Nullable class_, unsigned int *_Nullable outCount)
 Copies the instance variable list of the specified class. More...
 
const char *_Nonnull ivar_getName (Ivar _Nonnull ivar)
 Returns the name of the specified instance variable. More...
 
const char *_Nonnull ivar_getTypeEncoding (Ivar _Nonnull ivar)
 Returns the type encoding of the specified instance variable. More...
 
ptrdiff_t ivar_getOffset (Ivar _Nonnull ivar)
 Returns the offset of the specified instance variable. More...
 
objc_property_t _Nullable *_Nullable class_copyPropertyList (Class _Nullable class_, unsigned int *_Nullable outCount)
 Copies the property list of the specified class. More...
 
const char *_Nonnull property_getName (objc_property_t _Nonnull property)
 Returns the name of the specified property. More...
 
char *_Nullable property_copyAttributeValue (objc_property_t _Nonnull property, const char *_Nonnull name)
 Copies the specified attribute value. More...
 
void objc_exit (void)
 Exits the Objective-C runtime. More...
 
_Nullable objc_uncaught_exception_handler_t objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler_t _Nullable handler)
 Sets the handler for uncaught exceptions. More...
 
void objc_setForwardHandler (IMP _Nullable forward, IMP _Nullable stretForward)
 Sets the forwarding handler for unimplemented methods. More...
 
void objc_setEnumerationMutationHandler (objc_enumeration_mutation_handler_t _Nullable handler)
 Sets the handler for mutations during enumeration. More...
 
id _Nullable objc_constructInstance (Class _Nullable class_, void *_Nullable bytes)
 Constructs an instance of the specified class in the specified array of bytes. More...
 
void *_Nullable objc_destructInstance (id _Nullable object)
 Destructs the specified object. More...
 
void *_Null_unspecified objc_autoreleasePoolPush (void)
 Creates a new autorelease pool and puts it on top of the stack of autorelease pools. More...
 
void objc_autoreleasePoolPop (void *_Null_unspecified pool)
 Drains the specified autorelease pool and all pools on top of it and removes it from the stack of autorelease pools. More...
 
id _Nullable _objc_rootAutorelease (id _Nullable object)
 Adds the specified object to the topmost autorelease pool. More...
 
void objc_setTaggedPointerSecret (uintptr_t secret)
 Sets the tagged pointer secret. More...
 
int objc_registerTaggedPointerClass (Class _Nonnull class)
 Registers a class for tagged pointers. More...
 
bool object_isTaggedPointer (id _Nullable object)
 Returns whether the specified object is a tagged pointer. More...
 
uintptr_t object_getTaggedPointerValue (id _Nonnull object)
 Returns the value of the specified tagged pointer. More...
 
id _Nullable objc_createTaggedPointer (int class, uintptr_t value)
 Creates a new tagged pointer. More...
 

Macro Definition Documentation

◆ NO

#define NO   false

An Objective-C boolean representing false.

Note
This is a legacy from before C had a boolean type. Prefer the standard C99 false instead!

◆ YES

#define YES   true

An Objective-C boolean representing true.

Note
This is a legacy from before C had a boolean type. Prefer the standard C99 true instead!

Typedef Documentation

◆ BOOL

typedef bool BOOL

An Objective-C boolean. Either YES or NO.

Note
This is a legacy from before C had a boolean type. Prefer the standard C99 bool instead!

◆ IMP

typedef id _Nullable(* IMP) (id _Nonnull object, SEL _Nonnull selector,...)

A method implemenation.

Parameters
objectThe messaged object
selectorThe selector sent

◆ Method

typedef const struct objc_method* Method

A method.

A method consists of a selector with a type encoding and an implementation.

◆ objc_enumeration_mutation_handler_t

typedef void(* objc_enumeration_mutation_handler_t) (id _Nonnull object)

A handler for mutation during enumeration.

Parameters
objectThe object that was mutated during enumeration

◆ objc_uncaught_exception_handler_t

typedef void(* objc_uncaught_exception_handler_t) (id _Nullable exception)

A handler for uncaught exceptions.

Parameters
exceptionThe exception which was not caught.

◆ SEL

typedef const struct objc_selector* SEL

A selector.

A selector is the name of a method including the colons and an optional type encoding.

Function Documentation

◆ _objc_rootAutorelease()

id _Nullable _objc_rootAutorelease ( id _Nullable  object)

Adds the specified object to the topmost autorelease pool.

This is only to be used to implement the autorelease method in a root class.

Parameters
objectThe object to add to the topmost autorelease pool
Returns
The autoreleased object

◆ class_addMethod()

bool class_addMethod ( Class _Nonnull  class_,
SEL _Nonnull  selector,
IMP _Nonnull  implementation,
const char *_Nullable  typeEncoding 
)

Adds the specified method to the class.

Parameters
class_The class to which to add the method
selectorThe selector for the method to add
implementationThe implementation of the method to add
typeEncodingThe type encoding of the method to add
Returns
Whether the specified method was added

◆ class_conformsToProtocol()

bool class_conformsToProtocol ( Class _Nullable  class_,
Protocol *_Nonnull  protocol 
)

Returns whether the specified class conforms to the specified protocol.

Parameters
class_The class which should be examined
protocolThe protocol for which conformance should be checked
Returns
Whether the specified class conforms to the specified protocol

◆ class_copyIvarList()

Ivar _Nullable* _Nullable class_copyIvarList ( Class _Nullable  class_,
unsigned int *_Nullable  outCount 
)

Copies the instance variable list of the specified class.

Parameters
class_The class whose instance variable list should be copied
outCountAn optional pointer to an unsigned int that should be set to the number of instance variables returned
Returns
An array of instance variables, terminated by NULL. You need to call free() on it when done.

◆ class_copyMethodList()

Method _Nullable* _Nullable class_copyMethodList ( Class _Nullable  class_,
unsigned int *_Nullable  outCount 
)

Copies the method list of the specified class.

Parameters
class_The class whose method list should be copied
outCountAn optional pointer to an unsigned int that should be set to the number of methods returned
Returns
An array of methods, terminated by NULL. You need to call free() on it when done.

◆ class_copyPropertyList()

objc_property_t _Nullable* _Nullable class_copyPropertyList ( Class _Nullable  class_,
unsigned int *_Nullable  outCount 
)

Copies the property list of the specified class.

Parameters
class_The class whose property list should be copied
outCountAn optional pointer to an unsigned int that should be set to the number of properties returned
Returns
An array of properties, terminated by NULL. You need to call free() on it when done.

◆ class_getInstanceMethod()

Method _Nullable class_getInstanceMethod ( Class _Nullable  class_,
SEL _Nonnull  selector 
)

Returns the class's instance method for the specified selector.

Parameters
class_The class whose instance method should be returned
selectorThe selector of the instance method to return
Returns
The class's instance method for the specified selector

◆ class_getInstanceSize()

unsigned long class_getInstanceSize ( Class _Nullable  class_)

Returns the instance size of the specified class.

Parameters
class_The class whose instance size should be returned
Returns
The instance size of the specified class

◆ class_getMethodImplementation()

IMP _Nullable class_getMethodImplementation ( Class _Nullable  class_,
SEL _Nonnull  selector 
)

Returns the class's method implementation for the specified selector.

Warning
If the method uses the struct return ABI, you need to use class_getMethodImplementation_stret instead! Depending on the ABI, small structs might not use the struct return ABI.
Parameters
class_The class whose method implementation should be returned
selectorThe selector for the method whose implementation should be returned
Returns
The class's metod implementation for the specified selector

◆ class_getMethodImplementation_stret()

IMP _Nullable class_getMethodImplementation_stret ( Class _Nullable  class_,
SEL _Nonnull  selector 
)

Returns the class's method implementation for the specified selector.

Warning
If the method does not use use the struct return ABI, you need to use class_getMethodImplementation instead! Depending on the ABI, small structs might not use the struct return ABI.
Parameters
class_The class whose method implementation should be returned
selectorThe selector for the method whose implementation should be returned
Returns
The class's metod implementation for the specified selector

◆ class_getName()

const char* _Nullable class_getName ( Class _Nullable  class_)

Returns the name of the specified class.

Parameters
class_The class whose name should be returned
Returns
The name of the specified class

◆ class_getSuperclass()

Class _Nullable class_getSuperclass ( Class _Nullable  class_)

Returns the superclass of the specified class.

Parameters
class_The class whose superclass should be returned
Returns
The superclass of the specified class

◆ class_isMetaClass()

bool class_isMetaClass ( Class _Nullable  class_)

Returns whether the specified class is a metaclass.

Parameters
class_The class which should be examined
Returns
Whether the specified class is a metaclass

◆ class_replaceMethod()

IMP _Nullable class_replaceMethod ( Class _Nonnull  class_,
SEL _Nonnull  selector,
IMP _Nonnull  implementation,
const char *_Nullable  typeEncoding 
)

Replaces or adds the specified method of the class.

Parameters
class_The class to which to replace the method
selectorThe selector for the method to replace
implementationThe implementation of the method to replace
typeEncodingThe type encoding of the method to replace. Only used if the method does not exist yet.
Returns
The old implementation of the method

◆ class_respondsToSelector()

bool class_respondsToSelector ( Class _Nullable  class_,
SEL _Nonnull  selector 
)

Returns whether the specified class responds to the specified selector.

Parameters
class_The class which should be examined
selectorThe selector which should be checked
Returns
Whether the specified class responds to the specified selector

◆ ivar_getName()

const char* _Nonnull ivar_getName ( Ivar _Nonnull  ivar)

Returns the name of the specified instance variable.

Parameters
ivarThe instance variable whose name should be returned
Returns
The name of the specified instance variable

◆ ivar_getOffset()

ptrdiff_t ivar_getOffset ( Ivar _Nonnull  ivar)

Returns the offset of the specified instance variable.

Parameters
ivarThe instance variable whose offset should be returned
Returns
The offset of the specified instance variable

◆ ivar_getTypeEncoding()

const char* _Nonnull ivar_getTypeEncoding ( Ivar _Nonnull  ivar)

Returns the type encoding of the specified instance variable.

Parameters
ivarThe instance variable whose type encoding should be returned
Returns
The type encoding of the specified instance variable

◆ method_getName()

SEL _Nonnull method_getName ( Method _Nonnull  method)

Returns the name of the specified method.

Parameters
methodThe method whose name should be returned
Returns
The name of the specified method

◆ method_getTypeEncoding()

const char* _Nullable method_getTypeEncoding ( Method _Nonnull  method)

Returns the type encoding of the specified method.

Parameters
methodThe method whose type encoding should be returned
Returns
The type encoding of the specified method

◆ objc_allocateClassPair()

Class _Nonnull objc_allocateClassPair ( Class _Nullable  superclass,
const char *_Nonnull  name,
size_t  extraBytes 
)

Allocates a new class and its metaclass.

Parameters
superclassThe superclass for the new class
nameThe name for the new class
extraBytesExtra bytes to add to the instance size
Returns
A new, unregistered class pair

◆ objc_autoreleasePoolPop()

void objc_autoreleasePoolPop ( void *_Null_unspecified  pool)

Drains the specified autorelease pool and all pools on top of it and removes it from the stack of autorelease pools.

Parameters
poolThe pool which should be drained together with all pools on top of it

◆ objc_autoreleasePoolPush()

void* _Null_unspecified objc_autoreleasePoolPush ( void  )

Creates a new autorelease pool and puts it on top of the stack of autorelease pools.

Returns
A new autorelease pool, which is now on the top of the stack of autorelease pools

◆ objc_constructInstance()

id _Nullable objc_constructInstance ( Class _Nullable  class_,
void *_Nullable  bytes 
)

Constructs an instance of the specified class in the specified array of bytes.

Parameters
class_The class of which to construct an instance
bytesAn array of bytes of at least the length of the instance size. Must be properly aligned for the class.
Returns
The constructed instance

◆ objc_copyClassList()

Class _Nonnull* _Nonnull objc_copyClassList ( unsigned int *_Nullable  length)

Copies the list of all classes known to the runtime.

This is like objc_getClassList, but allocates a buffer large enough for all classes.

Parameters
lengthAn optional pointer to an unsigned int that will be set to the number of classes returned
Returns
An array of classes, terminated by Nil. You need to call free() on it when done.

◆ objc_createTaggedPointer()

id _Nullable objc_createTaggedPointer ( int  class,
uintptr_t  value 
)

Creates a new tagged pointer.

Parameters
classThe tag ID for the tagged pointer class to use
valueThe value the tagged pointer should have
Returns
A tagged pointer, or nil if it could not be created

◆ objc_destructInstance()

void* _Nullable objc_destructInstance ( id _Nullable  object)

Destructs the specified object.

Parameters
objectThe object to destruct
Returns
The array of bytes that was used to back the instance

◆ objc_exit()

void objc_exit ( void  )

Exits the Objective-C runtime.

This frees all data structures used by the runtime, after which Objective-C can no longer be used inside the current process. This is only useful for debugging.

◆ objc_getClassList()

unsigned int objc_getClassList ( Class _Nonnull *_Nullable  buffer,
unsigned int  count 
)

Gets the list of all classes known to the runtime.

Parameters
bufferAn array of Class to write to. If the buffer does not have enough space, the result is truncated.
countThe number of classes for which there is space in buffer
Returns
The number of classes written

◆ objc_registerClassPair()

void objc_registerClassPair ( Class _Nonnull  class_)

Registers an already allocated class pair.

Parameters
class_The class pair to register

◆ objc_registerTaggedPointerClass()

int objc_registerTaggedPointerClass ( Class _Nonnull  class)

Registers a class for tagged pointers.

Parameters
classThe class to register for tagged pointers
Returns
The tagged pointer ID for the registered class

◆ objc_setEnumerationMutationHandler()

void objc_setEnumerationMutationHandler ( objc_enumeration_mutation_handler_t _Nullable  handler)

Sets the handler for mutations during enumeration.

Parameters
handlerThe handler for mutations during enumeration

◆ objc_setForwardHandler()

void objc_setForwardHandler ( IMP _Nullable  forward,
IMP _Nullable  stretForward 
)

Sets the forwarding handler for unimplemented methods.

Parameters
forwardThe forwarding handler for regular methods
stretForwardThe forwarding handler for methods using the struct return ABI

◆ objc_setTaggedPointerSecret()

void objc_setTaggedPointerSecret ( uintptr_t  secret)

Sets the tagged pointer secret.

Parameters
secretA secret, random value that will be used to XOR all tagged pointers with

◆ objc_setUncaughtExceptionHandler()

_Nullable objc_uncaught_exception_handler_t objc_setUncaughtExceptionHandler ( objc_uncaught_exception_handler_t _Nullable  handler)

Sets the handler for uncaught exceptions.

Parameters
handlerThe new handler for uncaught exceptions
Returns
The old handler for uncaught exceptions

◆ object_getClass()

Class _Nullable object_getClass ( id _Nullable  object)

Returns the object's class.

Parameters
objectThe object whose class should be returned
Returns
The object's class

◆ object_getClassName()

const char* _Nullable object_getClassName ( id _Nullable  object)

Returns the object's class name.

Parameters
objectThe object whose class name should be returned
Returns
The object's class name

◆ object_getTaggedPointerValue()

uintptr_t object_getTaggedPointerValue ( id _Nonnull  object)

Returns the value of the specified tagged pointer.

Parameters
objectThe object whose tagged pointer value should be returned
Returns
The tagged pointer value of the object

◆ object_isTaggedPointer()

bool object_isTaggedPointer ( id _Nullable  object)

Returns whether the specified object is a tagged pointer.

Parameters
objectThe object to inspect
Returns
Whether the specified object is a tagged pointer

◆ object_setClass()

Class _Nullable object_setClass ( id _Nullable  object,
Class _Nonnull  class_ 
)

Sets the object's class.

This can be used to swizzle an object's class.

Parameters
objectThe object whose class should be set
class_The new class for the object
Returns
The old class of the object

◆ property_copyAttributeValue()

char* _Nullable property_copyAttributeValue ( objc_property_t _Nonnull  property,
const char *_Nonnull  name 
)

Copies the specified attribute value.

Parameters
propertyThe property whose attribute value should be copied
nameThe name of the attribute value to copy
Returns
A copy of the attribute value. You need to call free() on it when done.

◆ property_getName()

const char* _Nonnull property_getName ( objc_property_t _Nonnull  property)

Returns the name of the specified property.

Parameters
propertyThe property whose name should be returned
Returns
The name of the specified property

◆ protocol_conformsToProtocol()

bool protocol_conformsToProtocol ( Protocol *_Nonnull  protocol1,
Protocol *_Nonnull  protocol2 
)

Returns whether the first protocol conforms to the second protocol.

Parameters
protocol1The first protocol
protocol2The second protocol
Returns
Whether the first protocol conforms to the second protocol

◆ protocol_getName()

const char* _Nonnull protocol_getName ( Protocol *_Nonnull  protocol)

Returns the name of the specified protocol.

Parameters
protocolThe protocol whose name should be returned
Returns
The name of the specified protocol

◆ protocol_isEqual()

bool protocol_isEqual ( Protocol *_Nonnull  protocol1,
Protocol *_Nonnull  protocol2 
)

Returns whether two protocols are equal.

Parameters
protocol1The first protocol
protocol2The second protocol
Returns
Whether the two protocols are equal

◆ sel_getName()

const char* _Nonnull sel_getName ( SEL _Nonnull  selector)

Returns the name of the specified selector.

Parameters
selectorThe selector whose name should be returned
Returns
The name of the specified selector

◆ sel_isEqual()

bool sel_isEqual ( SEL _Nonnull  selector1,
SEL _Nonnull  selector2 
)

Checks two selectors for equality.

Selectors are considered equal if they have the same name - any type encoding is ignored.

Parameters
selector1The first selector
selector2The second selector
Returns
Whether the two selectors are equal

◆ sel_registerName()

SEL _Nonnull sel_registerName ( const char *_Nonnull  name)

Registers a selector with the specified name with the runtime.

Parameters
nameThe name for the selector to register
Returns
The registered selector