ObjFW
ObjFWRT.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #ifndef OBJFWRT_OBJFWRT_H
17 #define OBJFWRT_OBJFWRT_H
18 
19 #ifndef __STDC_LIMIT_MACROS
20 # define __STDC_LIMIT_MACROS
21 #endif
22 #ifndef __STDC_CONSTANT_MACROS
23 # define __STDC_CONSTANT_MACROS
24 #endif
25 
26 #include <stdbool.h>
27 #include <stddef.h>
28 #include <stdint.h>
29 
32 #ifndef __has_feature
33 # define __has_feature(x) 0
34 #endif
35 
36 #ifndef __has_attribute
37 # define __has_attribute(x) 0
38 #endif
39 
40 #if !__has_feature(nullability)
41 # ifndef _Nonnull
42 # define _Nonnull
43 # endif
44 # ifndef _Nullable
45 # define _Nullable
46 # endif
47 # ifndef _Null_unspecified
48 # define _Null_unspecified
49 # endif
50 #endif
51 
52 #if !__has_feature(objc_arc) && !defined(__unsafe_unretained)
53 # define __unsafe_unretained
54 #endif
55 
59 #define Nil (Class _Null_unspecified)0
60 
64 #define nil (id _Null_unspecified)0
65 
72 #define YES true
73 
80 #define NO false
81 
85 typedef struct objc_class *Class;
86 
90 typedef struct objc_object *id;
91 
98 typedef const struct objc_selector *SEL;
99 
105 typedef const struct objc_method *Method;
106 
110 #if defined(__OBJC__) && !defined(DOXYGEN)
111 @class Protocol;
112 #else
113 typedef const struct objc_protocol *Protocol;
114 #endif
115 
119 typedef const struct objc_ivar *Ivar;
120 
124 typedef const struct objc_property *objc_property_t;
125 
126 #if !defined(__wii__) && !defined(__amigaos__)
133 typedef bool BOOL;
134 #endif
135 
142 typedef id _Nullable (*IMP)(id _Nonnull object, SEL _Nonnull selector, ...);
143 
149 typedef void (*objc_uncaught_exception_handler)(id _Nullable exception);
150 
156 typedef void (*objc_enumeration_mutation_handler)(id _Nonnull object);
157 
161 struct objc_super {
165  id __unsafe_unretained _Nullable self;
169 #ifdef __cplusplus
170  Class _Nonnull class_;
171 #else
172  Class _Nonnull class;
173 #endif
174 };
175 
176 #ifdef __cplusplus
177 extern "C" {
178 #endif
179 
186 extern SEL _Nonnull sel_registerName(const char *_Nonnull name);
187 
194 extern const char *_Nonnull sel_getName(SEL _Nonnull selector);
195 
206 extern bool sel_isEqual(SEL _Nonnull selector1, SEL _Nonnull selector2);
207 
216 extern Class _Nonnull objc_allocateClassPair(Class _Nullable superclass,
217  const char *_Nonnull name, size_t extraBytes);
218 
224 extern void objc_registerClassPair(Class _Nonnull class_);
225 
234 extern unsigned int objc_getClassList(Class _Nonnull *_Nullable buffer,
235  unsigned int count);
236 
248 extern Class _Nonnull *_Nonnull objc_copyClassList(
249  unsigned int *_Nullable length);
250 
257 extern bool class_isMetaClass(Class _Nullable class_);
258 
265 extern const char *_Nullable class_getName(Class _Nullable class_);
266 
273 extern Class _Nullable class_getSuperclass(Class _Nullable class_);
274 
281 extern unsigned long class_getInstanceSize(Class _Nullable class_);
282 
291 extern bool class_respondsToSelector(Class _Nullable class_,
292  SEL _Nonnull selector);
293 
302 extern bool class_conformsToProtocol(Class _Nullable class_,
303  Protocol *_Nonnull protocol);
304 
317 extern IMP _Nullable class_getMethodImplementation(Class _Nullable class_,
318  SEL _Nonnull selector);
319 
332 extern IMP _Nullable class_getMethodImplementation_stret(Class _Nullable class_,
333  SEL _Nonnull selector);
334 
342 extern Method _Nullable class_getInstanceMethod(Class _Nullable class_,
343  SEL _Nonnull selector);
344 
354 extern bool class_addMethod(Class _Nonnull class_, SEL _Nonnull selector,
355  IMP _Nonnull implementation, const char *_Nullable typeEncoding);
356 
367 extern IMP _Nullable class_replaceMethod(Class _Nonnull class_,
368  SEL _Nonnull selector, IMP _Nonnull implementation,
369  const char *_Nullable typeEncoding);
370 
377 extern Class _Nullable object_getClass(id _Nullable object);
378 
388 extern Class _Nullable object_setClass(id _Nullable object,
389  Class _Nonnull class_);
390 
397 extern const char *_Nullable object_getClassName(id _Nullable object);
398 
405 extern const char *_Nonnull protocol_getName(Protocol *_Nonnull protocol);
406 
414 extern bool protocol_isEqual(Protocol *_Nonnull protocol1,
415  Protocol *_Nonnull protocol2);
416 
424 extern bool protocol_conformsToProtocol(Protocol *_Nonnull protocol1,
425  Protocol *_Nonnull protocol2);
426 
436 extern Method _Nullable *_Nullable class_copyMethodList(Class _Nullable class_,
437  unsigned int *_Nullable outCount);
438 
445 extern SEL _Nonnull method_getName(Method _Nonnull method);
446 
453 extern const char *_Nullable method_getTypeEncoding(Method _Nonnull method);
454 
464 extern Ivar _Nullable *_Nullable class_copyIvarList(Class _Nullable class_,
465  unsigned int *_Nullable outCount);
466 
473 extern const char *_Nonnull ivar_getName(Ivar _Nonnull ivar);
474 
481 extern const char *_Nonnull ivar_getTypeEncoding(Ivar _Nonnull ivar);
482 
489 extern ptrdiff_t ivar_getOffset(Ivar _Nonnull ivar);
490 
500 extern objc_property_t _Nullable *_Nullable class_copyPropertyList(
501  Class _Nullable class_, unsigned int *_Nullable outCount);
502 
509 extern const char *_Nonnull property_getName(objc_property_t _Nonnull property);
510 
519 extern char *_Nullable property_copyAttributeValue(
520  objc_property_t _Nonnull property, const char *_Nonnull name);
521 
529 extern void objc_deinit(void);
530 
537 extern _Nullable objc_uncaught_exception_handler
539  objc_uncaught_exception_handler _Nullable handler);
540 
548 extern void objc_setForwardHandler(IMP _Nullable forward,
549  IMP _Nullable stretForward);
550 
557  objc_enumeration_mutation_handler _Nullable handler);
558 
568 extern id _Nullable objc_constructInstance(Class _Nullable class_,
569  void *_Nullable bytes);
570 
577 extern void *_Nullable objc_destructInstance(id _Nullable object);
578 
586 extern void *_Null_unspecified objc_autoreleasePoolPush(void);
587 
595 extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
596 
606 extern id _Nullable _objc_rootAutorelease(id _Nullable object);
607 
614 extern void objc_setTaggedPointerSecret(uintptr_t secret);
615 
622 extern int objc_registerTaggedPointerClass(Class _Nonnull class_);
623 
630 extern bool object_isTaggedPointer(id _Nullable object);
631 
638 extern uintptr_t object_getTaggedPointerValue(id _Nonnull object);
639 
647 extern id _Nullable objc_createTaggedPointer(int class_, uintptr_t value);
648 
649 /*
650  * Used by the compiler, but can also be called manually.
651  *
652  * These declarations are also required to prevent Clang's implicit
653  * declarations which include __declspec(dllimport) on Windows.
654  */
655 struct objc_module;
656 extern void __objc_exec_class(struct objc_module *_Nonnull module);
657 extern IMP _Nonnull objc_msg_lookup(id _Nullable object, SEL _Nonnull selector);
658 extern IMP _Nonnull objc_msg_lookup_stret(id _Nullable object,
659  SEL _Nonnull selector);
660 extern IMP _Nonnull objc_msg_lookup_super(struct objc_super *_Nonnull super,
661  SEL _Nonnull selector);
662 extern IMP _Nonnull objc_msg_lookup_super_stret(
663  struct objc_super *_Nonnull super, SEL _Nonnull selector);
664 extern Class _Nullable objc_lookUpClass(const char *_Nonnull name);
665 extern Class _Nullable objc_getClass(const char *_Nonnull name);
666 extern Class _Nonnull objc_getRequiredClass(const char *_Nonnull name);
667 extern Class _Nullable objc_lookup_class(const char *_Nonnull name);
668 extern Class _Nonnull objc_get_class(const char *_Nonnull name);
669 extern void objc_exception_throw(id _Nullable object);
670 extern int objc_sync_enter(id _Nullable object);
671 extern int objc_sync_exit(id _Nullable object);
672 extern id _Nullable objc_getProperty(id _Nonnull self, SEL _Nonnull _cmd,
673  ptrdiff_t offset, bool atomic);
674 extern void objc_setProperty(id _Nonnull self, SEL _Nonnull _cmd,
675  ptrdiff_t offset, id _Nullable value, bool atomic, signed char copy);
676 extern void objc_getPropertyStruct(void *_Nonnull dest,
677  const void *_Nonnull src, ptrdiff_t size, bool atomic, bool strong);
678 extern void objc_setPropertyStruct(void *_Nonnull dest,
679  const void *_Nonnull src, ptrdiff_t size, bool atomic, bool strong);
680 extern void objc_enumerationMutation(id _Nonnull object);
681 #ifndef OBJC_NO_PERSONALITY_DECLARATION
682 /*
683  * No objfw-defs.h or config.h is available for the installed runtime headers,
684  * so we don't know which exceptions we have.
685  */
686 extern int __gnu_objc_personality_v0(int version, int actions,
687  uint64_t exClass, void *_Nonnull ex, void *_Nonnull ctx);
688 extern int __gnu_objc_personality_sj0(int version, int actions,
689  uint64_t exClass, void *_Nonnull ex, void *_Nonnull ctx);
690 #endif
691 extern id _Nullable objc_retain(id _Nullable object);
692 extern id _Nullable objc_retainBlock(id _Nullable block);
693 extern id _Nullable objc_retainAutorelease(id _Nullable object);
694 extern void objc_release(id _Nullable object);
695 extern id _Nullable objc_autorelease(id _Nullable object);
696 extern id _Nullable objc_autoreleaseReturnValue(id _Nullable object);
697 extern id _Nullable objc_retainAutoreleaseReturnValue(id _Nullable object);
698 extern id _Nullable objc_retainAutoreleasedReturnValue(id _Nullable object);
699 extern id _Nullable objc_storeStrong(id _Nullable *_Nonnull object,
700  id _Nullable value);
701 extern id _Nullable objc_storeWeak(id _Nullable *_Nonnull object,
702  id _Nullable value);
703 extern id _Nullable objc_loadWeakRetained(id _Nullable *_Nonnull object);
704 extern _Nullable id objc_initWeak(id _Nullable *_Nonnull object,
705  id _Nullable value);
706 extern void objc_destroyWeak(id _Nullable *_Nonnull object);
707 extern id _Nullable objc_loadWeak(id _Nullable *_Nonnull object);
708 extern void objc_copyWeak(id _Nullable *_Nonnull dest,
709  id _Nullable *_Nonnull src);
710 extern void objc_moveWeak(id _Nullable *_Nonnull dest,
711  id _Nullable *_Nonnull src);
712 #ifdef __cplusplus
713 }
714 #endif
715 
716 #endif
Class class_getSuperclass(Class class_)
Returns the superclass of the specified class.
Definition: class.m:669
const char * method_getTypeEncoding(Method method)
Returns the type encoding of the specified method.
Definition: method.m:77
Class object_getClass(id object)
Returns the object's class.
Definition: class.m:856
IMP class_getMethodImplementation_stret(Class class_, SEL selector)
Returns the class's method implementation for the specified selector.
Definition: class.m:711
SEL method_getName(Method method)
Returns the name of the specified method.
Definition: method.m:71
const struct objc_property * objc_property_t
A property.
Definition: ObjFWRT.h:124
const char * object_getClassName(id object)
Returns the object's class name.
Definition: class.m:889
const char * ivar_getTypeEncoding(Ivar ivar)
Returns the type encoding of the specified instance variable.
Definition: ivar.m:68
IMP class_replaceMethod(Class class_, SEL selector, IMP implementation, const char *typeEncoding)
Replaces or adds the specified method of the class.
Definition: class.m:833
SEL sel_registerName(const char *name)
Registers a selector with the specified name with the runtime.
Definition: selector.m:71
Method class_getInstanceMethod(Class class_, SEL selector)
Returns the class's instance method for the specified selector.
Definition: class.m:788
id(* IMP)(id object, SEL selector,...)
A method implemenation.
Definition: ObjFWRT.h:142
void *_Null_unspecified objc_autoreleasePoolPush(void)
Creates a new autorelease pool and puts it on top of the stack of autorelease pools.
Definition: autorelease.m:66
Class object_setClass(id object, Class class_)
Sets the object's class.
Definition: class.m:872
void objc_deinit(void)
Deinitializes the Objective-C runtime.
Definition: init.m:35
const char * class_getName(Class class_)
Returns the name of the specified class.
Definition: class.m:660
const char * protocol_getName(Protocol *protocol)
Returns the name of the specified protocol.
Definition: protocol.m:27
ptrdiff_t ivar_getOffset(Ivar ivar)
Returns the offset of the specified instance variable.
Definition: ivar.m:74
uintptr_t object_getTaggedPointerValue(id object)
Returns the value of the specified tagged pointer.
Definition: tagged-pointer.m:76
unsigned int objc_getClassList(Class *buffer, unsigned int count)
Gets the list of all classes known to the runtime.
Definition: class.m:586
void objc_setTaggedPointerSecret(uintptr_t secret)
Sets the tagged pointer secret.
Definition: tagged-pointer.m:28
const struct objc_ivar * Ivar
An instance variable.
Definition: ObjFWRT.h:119
bool class_conformsToProtocol(Class class_, Protocol *protocol)
Returns whether the specified class conforms to the specified protocol.
Definition: protocol.m:56
char * property_copyAttributeValue(objc_property_t property, const char *name)
Copies the specified attribute value.
Definition: property.m:228
Class * objc_copyClassList(unsigned int *length)
Copies the list of all classes known to the runtime.
Definition: class.m:626
void * objc_destructInstance(id object)
Destructs the specified object.
Definition: instance.m:75
objc_uncaught_exception_handler objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler)
Sets the handler for uncaught exceptions.
Definition: exception.m:777
Method * class_copyMethodList(Class class_, unsigned int *outCount)
Copies the method list of the specified class.
Definition: method.m:22
id _objc_rootAutorelease(id object)
Adds the specified object to the topmost autorelease pool.
Definition: autorelease.m:119
void(* objc_uncaught_exception_handler)(id exception)
A handler for uncaught exceptions.
Definition: ObjFWRT.h:149
objc_property_t * class_copyPropertyList(Class class_, unsigned int *outCount)
Copies the property list of the specified class.
Definition: property.m:170
id objc_constructInstance(Class class_, void *bytes)
Constructs an instance of the specified class in the specified array of bytes.
Definition: instance.m:59
void objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler handler)
Sets the handler for mutations during enumeration.
Definition: misc.m:52
bool protocol_isEqual(Protocol *protocol1, Protocol *protocol2)
Returns whether two protocols are equal.
Definition: protocol.m:33
bool object_isTaggedPointer(id object)
Returns whether the specified object is a tagged pointer.
Definition: tagged-pointer.m:54
const char * sel_getName(SEL selector)
Returns the name of the specified selector.
Definition: selector.m:115
void(* objc_enumeration_mutation_handler)(id object)
A handler for mutation during enumeration.
Definition: ObjFWRT.h:156
bool protocol_conformsToProtocol(Protocol *protocol1, Protocol *protocol2)
Returns whether the first protocol conforms to the second protocol.
Definition: protocol.m:40
bool BOOL
An Objective-C boolean. Either YES or NO.
Definition: ObjFWRT.h:133
bool sel_isEqual(SEL selector1, SEL selector2)
Checks two selectors for equality.
Definition: selector.m:127
unsigned long class_getInstanceSize(Class class_)
Returns the instance size of the specified class.
Definition: class.m:678
const struct objc_method * Method
A method.
Definition: ObjFWRT.h:105
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 aut...
bool class_isMetaClass(Class class_)
Returns whether the specified class is a metaclass.
Definition: class.m:651
const struct objc_selector * SEL
A selector.
Definition: ObjFWRT.h:98
IMP class_getMethodImplementation(Class class_, SEL selector)
Returns the class's method implementation for the specified selector.
Definition: class.m:687
id objc_createTaggedPointer(int class_, uintptr_t value)
Creates a new tagged pointer.
Definition: tagged-pointer.m:86
bool class_addMethod(Class class_, SEL selector, IMP implementation, const char *typeEncoding)
Adds the specified method to the class.
Definition: class.m:814
bool class_respondsToSelector(Class class_, SEL selector)
Returns whether the specified class responds to the specified selector.
Definition: lookup.m:122
Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)
Allocates a new class and its metaclass.
Definition: class.m:472
int objc_registerTaggedPointerClass(Class class_)
Registers a class for tagged pointers.
Definition: tagged-pointer.m:34
const struct objc_protocol * Protocol
A protocol.
Definition: ObjFWRT.h:113
void objc_registerClassPair(Class class_)
Registers an already allocated class pair.
Definition: class.m:509
const char * property_getName(objc_property_t property)
Returns the name of the specified property.
Definition: property.m:222
void objc_setForwardHandler(IMP forward, IMP stretForward)
Sets the forwarding handler for unimplemented methods.
Definition: lookup.m:115
Ivar * class_copyIvarList(Class class_, unsigned int *outCount)
Copies the instance variable list of the specified class.
Definition: ivar.m:22
const char * ivar_getName(Ivar ivar)
Returns the name of the specified instance variable.
Definition: ivar.m:62
A pointer to a class.
Definition: private.h:33
A pointer to any object.
Definition: private.h:62
A struct representing a call to super.
Definition: ObjFWRT.h:161