Index: src/runtime/ObjFW-RT.h ================================================================== --- src/runtime/ObjFW-RT.h +++ src/runtime/ObjFW-RT.h @@ -34,28 +34,21 @@ #ifndef __has_attribute # define __has_attribute(x) 0 #endif -#if __has_feature(objc_arc) -# define OBJC_UNSAFE_UNRETAINED __unsafe_unretained -#else -# define OBJC_UNSAFE_UNRETAINED -#endif - -#if __has_feature(nullability) -# define OBJC_NONNULL _Nonnull -# define OBJC_NULLABLE _Nullable -#else -# define OBJC_NONNULL -# define OBJC_NULLABLE -#endif - -#if __has_attribute(__objc_root_class__) -# define OBJC_ROOT_CLASS __attribute__((__objc_root_class__)) -#else -# define OBJC_ROOT_CLASS +#if !__has_feature(nullability) +# ifndef _Nonnull +# define _Nonnull +# endif +# ifndef _Nullable +# define _Nullable +# endif +#endif + +#if !__has_feature(objc_arc) && !defined(__unsafe_unretained) +# define __unsafe_unretained #endif #define Nil (Class)0 #define nil (id)0 #define YES (BOOL)1 @@ -63,31 +56,31 @@ typedef struct objc_class *Class; typedef struct objc_object *id; typedef const struct objc_selector *SEL; typedef signed char BOOL; -typedef id OBJC_NULLABLE (*IMP)(id OBJC_NONNULL, SEL OBJC_NONNULL, ...); -typedef void (*objc_uncaught_exception_handler)(id OBJC_NULLABLE); -typedef void (*objc_enumeration_mutation_handler)(id OBJC_NONNULL); +typedef id _Nullable (*IMP)(id _Nonnull, SEL _Nonnull, ...); +typedef void (*objc_uncaught_exception_handler)(id _Nullable); +typedef void (*objc_enumeration_mutation_handler)(id _Nonnull); struct objc_class { - Class OBJC_NONNULL isa; - Class OBJC_NULLABLE superclass; - const char *OBJC_NONNULL name; + Class _Nonnull isa; + Class _Nullable superclass; + const char *_Nonnull name; unsigned long version; unsigned long info; long instance_size; - struct objc_ivar_list *OBJC_NULLABLE ivars; - struct objc_method_list *OBJC_NULLABLE methodlist; - struct objc_dtable *OBJC_NULLABLE dtable; - Class OBJC_NONNULL *OBJC_NULLABLE subclass_list; - void *OBJC_NULLABLE sibling_class; - struct objc_protocol_list *OBJC_NULLABLE protocols; - void *OBJC_NULLABLE gc_object_type; + struct objc_ivar_list *_Nullable ivars; + struct objc_method_list *_Nullable methodlist; + struct objc_dtable *_Nullable dtable; + Class _Nonnull *_Nullable subclass_list; + void *_Nullable sibling_class; + struct objc_protocol_list *_Nullable protocols; + void *_Nullable gc_object_type; unsigned long abi_version; - int32_t *OBJC_NONNULL *OBJC_NULLABLE ivar_offsets; - struct objc_property_list *OBJC_NULLABLE properties; + int32_t *_Nonnull *_Nullable ivar_offsets; + struct objc_property_list *_Nullable properties; }; enum objc_class_info { OBJC_CLASS_INFO_CLASS = 0x001, OBJC_CLASS_INFO_METACLASS = 0x002, @@ -97,45 +90,45 @@ OBJC_CLASS_INFO_DTABLE = 0x400, OBJC_CLASS_INFO_INITIALIZED = 0x800 }; struct objc_object { - Class OBJC_NONNULL isa; + Class _Nonnull isa; }; struct objc_selector { uintptr_t uid; - const char *OBJC_NULLABLE types; + const char *_Nullable types; }; struct objc_super { - id OBJC_UNSAFE_UNRETAINED OBJC_NULLABLE self; - Class OBJC_NONNULL cls; + id __unsafe_unretained _Nullable self; + Class _Nonnull cls; }; struct objc_method { struct objc_selector sel; - IMP OBJC_NONNULL imp; + IMP _Nonnull imp; }; struct objc_method_list { - struct objc_method_list *OBJC_NULLABLE next; + struct objc_method_list *_Nullable next; unsigned int count; struct objc_method methods[1]; }; struct objc_category { - const char *OBJC_NONNULL category_name; - const char *OBJC_NONNULL class_name; - struct objc_method_list *OBJC_NULLABLE instance_methods; - struct objc_method_list *OBJC_NULLABLE class_methods; - struct objc_protocol_list *OBJC_NULLABLE protocols; + const char *_Nonnull category_name; + const char *_Nonnull class_name; + struct objc_method_list *_Nullable instance_methods; + struct objc_method_list *_Nullable class_methods; + struct objc_protocol_list *_Nullable protocols; }; struct objc_ivar { - const char *OBJC_NONNULL name; - const char *OBJC_NONNULL type; + const char *_Nonnull name; + const char *_Nonnull type; unsigned int offset; }; struct objc_ivar_list { unsigned int count; @@ -162,132 +155,123 @@ OBJC_PROPERTY_STRONG = 0x10, OBJC_PROPERTY_UNSAFE_UNRETAINED = 0x20 }; struct objc_property { - const char *OBJC_NONNULL name; + const char *_Nonnull name; unsigned char attributes, extended_attributes; struct { - const char *OBJC_NULLABLE name; - const char *OBJC_NULLABLE type; + const char *_Nullable name; + const char *_Nullable type; } getter, setter; }; struct objc_property_list { unsigned int count; - struct objc_property_list *OBJC_NULLABLE next; + struct objc_property_list *_Nullable next; struct objc_property properties[1]; }; #ifdef __OBJC__ -OBJC_ROOT_CLASS +# if __has_attribute(__objc_root_class__) +__attribute__((__objc_root_class__)) +# endif @interface Protocol { @public #else typedef struct { #endif - Class OBJC_NONNULL isa; - const char *OBJC_NONNULL name; - struct objc_protocol_list *OBJC_NULLABLE protocol_list; - struct objc_abi_method_description_list *OBJC_NULLABLE instance_methods; - struct objc_abi_method_description_list *OBJC_NULLABLE class_methods; + Class _Nonnull isa; + const char *_Nonnull name; + struct objc_protocol_list *_Nullable protocol_list; + struct objc_abi_method_description_list *_Nullable instance_methods; + struct objc_abi_method_description_list *_Nullable class_methods; #ifdef __OBJC__ } @end #else } Protocol; #endif struct objc_protocol_list { - struct objc_protocol_list *OBJC_NULLABLE next; + struct objc_protocol_list *_Nullable next; long count; - Protocol *OBJC_UNSAFE_UNRETAINED OBJC_NONNULL list[1]; + Protocol *__unsafe_unretained _Nonnull list[1]; }; #ifdef __cplusplus extern "C" { #endif -extern SEL OBJC_NONNULL sel_registerName(const char *OBJC_NONNULL); -extern const char *OBJC_NONNULL sel_getName(SEL OBJC_NONNULL); -extern bool sel_isEqual(SEL OBJC_NONNULL, SEL OBJC_NONNULL); -extern Class OBJC_NONNULL objc_allocateClassPair(Class OBJC_NULLABLE, - const char *OBJC_NONNULL, size_t); -extern void objc_registerClassPair(Class OBJC_NONNULL); -extern id OBJC_NULLABLE objc_lookUpClass(const char *OBJC_NONNULL); -extern id OBJC_NULLABLE objc_getClass(const char *OBJC_NONNULL); -extern id OBJC_NONNULL objc_getRequiredClass(const char *OBJC_NONNULL); -extern unsigned int objc_getClassList(Class OBJC_NONNULL *OBJC_NULLABLE, - unsigned int); -extern Class OBJC_NONNULL *OBJC_NONNULL objc_copyClassList( - unsigned int *OBJC_NULLABLE); -extern bool class_isMetaClass(Class OBJC_NULLABLE); -extern const char *OBJC_NONNULL class_getName(Class OBJC_NULLABLE); -extern Class OBJC_NULLABLE class_getSuperclass(Class OBJC_NULLABLE); -extern unsigned long class_getInstanceSize(Class OBJC_NULLABLE); -extern bool class_respondsToSelector(Class OBJC_NULLABLE, SEL OBJC_NONNULL); -extern bool class_conformsToProtocol(Class OBJC_NULLABLE, - Protocol *OBJC_NONNULL); -extern IMP OBJC_NULLABLE class_getMethodImplementation(Class OBJC_NULLABLE, - SEL OBJC_NONNULL); -extern IMP OBJC_NULLABLE class_getMethodImplementation_stret( - Class OBJC_NULLABLE, SEL OBJC_NONNULL); -extern const char *OBJC_NULLABLE class_getMethodTypeEncoding( - Class OBJC_NULLABLE, SEL OBJC_NONNULL); -extern bool class_addMethod(Class OBJC_NONNULL, SEL OBJC_NONNULL, - IMP OBJC_NONNULL, const char *OBJC_NULLABLE); -extern IMP OBJC_NULLABLE class_replaceMethod(Class OBJC_NONNULL, - SEL OBJC_NONNULL, IMP OBJC_NONNULL, const char *OBJC_NULLABLE); -extern Class OBJC_NULLABLE object_getClass(id OBJC_NULLABLE); -extern Class OBJC_NULLABLE object_setClass(id OBJC_NULLABLE, - Class OBJC_NONNULL); -extern const char *OBJC_NONNULL object_getClassName(id OBJC_NULLABLE); -extern const char *OBJC_NONNULL protocol_getName(Protocol *OBJC_NONNULL); -extern bool protocol_isEqual(Protocol *OBJC_NONNULL, Protocol *OBJC_NONNULL); -extern bool protocol_conformsToProtocol(Protocol *OBJC_NONNULL, - Protocol *OBJC_NONNULL); +extern SEL _Nonnull sel_registerName(const char *_Nonnull); +extern const char *_Nonnull sel_getName(SEL _Nonnull); +extern bool sel_isEqual(SEL _Nonnull, SEL _Nonnull); +extern Class _Nonnull objc_allocateClassPair(Class _Nullable, + const char *_Nonnull, size_t); +extern void objc_registerClassPair(Class _Nonnull); +extern id _Nullable objc_lookUpClass(const char *_Nonnull); +extern id _Nullable objc_getClass(const char *_Nonnull); +extern id _Nonnull objc_getRequiredClass(const char *_Nonnull); +extern unsigned int objc_getClassList(Class _Nonnull *_Nullable, unsigned int); +extern Class _Nonnull *_Nonnull objc_copyClassList(unsigned int *_Nullable); +extern bool class_isMetaClass(Class _Nullable); +extern const char *_Nullable class_getName(Class _Nullable); +extern Class _Nullable class_getSuperclass(Class _Nullable); +extern unsigned long class_getInstanceSize(Class _Nullable); +extern bool class_respondsToSelector(Class _Nullable, SEL _Nonnull); +extern bool class_conformsToProtocol(Class _Nullable, Protocol *_Nonnull); +extern IMP _Nullable class_getMethodImplementation(Class _Nullable, + SEL _Nonnull); +extern IMP _Nullable class_getMethodImplementation_stret(Class _Nullable, + SEL _Nonnull); +extern const char *_Nullable class_getMethodTypeEncoding(Class _Nullable, + SEL _Nonnull); +extern bool class_addMethod(Class _Nonnull, SEL _Nonnull, IMP _Nonnull, + const char *_Nullable); +extern IMP _Nullable class_replaceMethod(Class _Nonnull, SEL _Nonnull, + IMP _Nonnull, const char *_Nullable); +extern Class _Nullable object_getClass(id _Nullable); +extern Class _Nullable object_setClass(id _Nullable, Class _Nonnull); +extern const char *_Nonnull object_getClassName(id _Nullable); +extern const char *_Nonnull protocol_getName(Protocol *_Nonnull); +extern bool protocol_isEqual(Protocol *_Nonnull, Protocol *_Nonnull); +extern bool protocol_conformsToProtocol(Protocol *_Nonnull, Protocol *_Nonnull); extern void objc_exit(void); -extern OBJC_NULLABLE objc_uncaught_exception_handler +extern _Nullable objc_uncaught_exception_handler objc_setUncaughtExceptionHandler( - objc_uncaught_exception_handler OBJC_NULLABLE); -extern void objc_setForwardHandler(IMP OBJC_NULLABLE, IMP OBJC_NULLABLE); -extern void objc_zero_weak_references(id OBJC_NONNULL); + objc_uncaught_exception_handler _Nullable); +extern void objc_setForwardHandler(IMP _Nullable, IMP _Nullable); +extern void objc_zero_weak_references(id _Nonnull); /* * Used by the compiler, but can also be called manually. * * These declarations are also required to prevent Clang's implicit * declarations which include __declspec(dllimport) on Windows. */ struct objc_abi_module; -extern void __objc_exec_class(void *OBJC_NONNULL); -extern IMP OBJC_NONNULL objc_msg_lookup(id OBJC_NULLABLE, SEL OBJC_NONNULL); -extern IMP OBJC_NONNULL objc_msg_lookup_stret(id OBJC_NULLABLE, - SEL OBJC_NONNULL); -extern IMP OBJC_NONNULL objc_msg_lookup_super(struct objc_super *OBJC_NONNULL, - SEL OBJC_NONNULL); -extern IMP OBJC_NONNULL objc_msg_lookup_super_stret( - struct objc_super *OBJC_NONNULL, SEL OBJC_NONNULL); -extern void objc_exception_throw(id OBJC_NULLABLE); -extern int objc_sync_enter(id OBJC_NULLABLE); -extern int objc_sync_exit(id OBJC_NULLABLE); -extern id OBJC_NULLABLE objc_getProperty(id OBJC_NONNULL, SEL OBJC_NONNULL, - ptrdiff_t, BOOL); -extern void objc_setProperty(id OBJC_NONNULL, SEL OBJC_NONNULL, ptrdiff_t, - id OBJC_NULLABLE, BOOL, signed char); -extern void objc_getPropertyStruct(void *OBJC_NONNULL, const void *OBJC_NONNULL, - ptrdiff_t, BOOL, BOOL); -extern void objc_setPropertyStruct(void *OBJC_NONNULL, const void *OBJC_NONNULL, - ptrdiff_t, BOOL, BOOL); -extern void objc_enumerationMutation(id OBJC_NONNULL); -extern void objc_setEnumerationMutationHandler( - objc_enumeration_mutation_handler OBJC_NULLABLE); +extern void __objc_exec_class(void *_Nonnull); +extern IMP _Nonnull objc_msg_lookup(id _Nullable, SEL _Nonnull); +extern IMP _Nonnull objc_msg_lookup_stret(id _Nullable, SEL _Nonnull); +extern IMP _Nonnull objc_msg_lookup_super(struct objc_super *_Nonnull, + SEL _Nonnull); +extern IMP _Nonnull objc_msg_lookup_super_stret(struct objc_super *_Nonnull, + SEL _Nonnull); +extern void objc_exception_throw(id _Nullable); +extern int objc_sync_enter(id _Nullable); +extern int objc_sync_exit(id _Nullable); +extern id _Nullable objc_getProperty(id _Nonnull, SEL _Nonnull, ptrdiff_t, + BOOL); +extern void objc_setProperty(id _Nonnull, SEL _Nonnull, ptrdiff_t, id _Nullable, + BOOL, signed char); +extern void objc_getPropertyStruct(void *_Nonnull, const void *_Nonnull, + ptrdiff_t, BOOL, BOOL); +extern void objc_setPropertyStruct(void *_Nonnull, const void *_Nonnull, + ptrdiff_t, BOOL, BOOL); +extern void objc_enumerationMutation(id _Nonnull); +extern void objc_setEnumerationMutationHandler( + objc_enumeration_mutation_handler _Nullable); #ifdef __cplusplus } #endif -#undef OBJC_NONNULL -#undef OBJC_NULLABLE -#undef OBJC_UNSAFE_UNRETAINED -#undef OBJC_ROOT_CLASS - #endif