diff --git a/CMakeLists.txt b/CMakeLists.txt index bf38b34c..6269ba2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,6 @@ set(libobjc_HDRS objc/objc-runtime.h objc/objc-visibility.h objc/objc.h - objc/runtime-deprecated.h objc/runtime.h objc/slot.h) @@ -134,7 +133,6 @@ option(ENABLE_TRACING option(OLDABI_COMPAT "Enable compatibility with GCC and old GNUstep ABIs" ${OLD_ABI_COMPAT_DEFAULT}) -option(LEGACY_COMPAT "Enable legacy compatibility features" OFF) option(DEBUG_ARC_COMPAT "Log warnings for classes that don't hit ARC fast paths" OFF) option(ENABLE_OBJCXX "Enable support for Objective-C++" ON) @@ -153,12 +151,6 @@ if (OLDABI_COMPAT) add_definitions(-DOLDABI_COMPAT=1) endif() -if (LEGACY_COMPAT) - list(APPEND libobjc_C_SRCS legacy_malloc.c) -else () - add_definitions(-DNO_LEGACY) -endif () - set(LIBOBJC_NAME "objc" CACHE STRING "Name of the Objective-C runtime library (e.g. objc2 for libobjc2)") diff --git a/abi_version.c b/abi_version.c index cfddfe0e..75c09ff7 100644 --- a/abi_version.c +++ b/abi_version.c @@ -32,7 +32,6 @@ struct objc_abi_version enum { - gcc_abi = 8, gnustep_abi = 9, gc_abi = 10 }; @@ -42,12 +41,10 @@ enum */ static struct objc_abi_version known_abis[] = { - /* GCC ABI. */ - {gcc_abi, gcc_abi, gnustep_abi, sizeof(struct objc_module_abi_8)}, /* Non-fragile ABI. */ - {gnustep_abi, gcc_abi, gc_abi, sizeof(struct objc_module_abi_8)}, + {gnustep_abi, gnustep_abi, gc_abi, sizeof(struct objc_module_abi_8)}, /* GC ABI. Adds a field describing the GC mode. */ - {gc_abi, gcc_abi, gc_abi, sizeof(struct objc_module_abi_10)} + {gc_abi, gnustep_abi, gc_abi, sizeof(struct objc_module_abi_10)} }; static int known_abi_count = diff --git a/category.h b/category.h index 4a3b685c..c228d05a 100644 --- a/category.h +++ b/category.h @@ -37,26 +37,26 @@ struct objc_category struct objc_property_list *class_properties; }; -struct objc_category_gcc +struct objc_category_gsv1 { - /** - * The name of this category. - */ - const char *name; - /** - * The name of the class to which this category should be applied. - */ - const char *class_name; - /** - * The list of instance methods to add to the class. - */ - struct objc_method_list_gcc *instance_methods; - /** - * The list of class methods to add to the class. - */ - struct objc_method_list_gcc *class_methods; - /** - * The list of protocols adopted by this category. - */ - struct objc_protocol_list *protocols; + /** + * The name of this category. + */ + const char *name; + /** + * The name of the class to which this category should be applied. + */ + const char *class_name; + /** + * The list of instance methods to add to the class. + */ + struct objc_method_list_gsv1 *instance_methods; + /** + * The list of class methods to add to the class. + */ + struct objc_method_list_gsv1 *class_methods; + /** + * The list of protocols adopted by this category. + */ + struct objc_protocol_list *protocols; }; diff --git a/class.h b/class.h index 081feab4..fa4b1105 100644 --- a/class.h +++ b/class.h @@ -184,12 +184,12 @@ struct objc_class_gsv1 /** * Metadata describing the instance variables in this class. */ - struct objc_ivar_list_gcc *ivars; + struct objc_ivar_list_gsv1 *ivars; /** * Metadata for for defining the mappings from selectors to IMPs. Linked * list of method list structures, one per class and one per category. */ - struct objc_method_list_gcc *methods; + struct objc_method_list_gsv1 *methods; /** * The dispatch table for this class. Intialized and maintained by the * runtime. @@ -274,29 +274,6 @@ struct objc_class_gsv1 uintptr_t weak_pointers; }; -/** - * Structure representing the GCC ABI class structure. This is only ever - * required so that we can take its size - struct objc_class begins with the - * same fields, and you can test the new abi flag to tell whether it is safe to - * access the subsequent fields. - */ -struct objc_class_gcc -{ - Class isa; - Class super_class; - const char *name; - long version; - unsigned long info; - long instance_size; - struct objc_ivar_list_gcc *ivars; - struct objc_method_list *methods; - void *dtable; - Class subclass_list; - Class sibling_class; - struct objc_protocol_list *protocols; - void *gc_object_type; -}; - /** * An enumerated type describing all of the valid flags that may be used in the diff --git a/ivar.h b/ivar.h index 67abd0c4..1637cca0 100644 --- a/ivar.h +++ b/ivar.h @@ -125,7 +125,7 @@ static inline objc_ivar_ownership ivarGetOwnership(Ivar ivar) /** * Legacy ivar structure, inherited from the GCC ABI. */ -struct objc_ivar_gcc +struct objc_ivar_gsv1 { /** * Name of this instance variable. @@ -189,7 +189,7 @@ static inline struct objc_ivar *ivar_at_index(struct objc_ivar_list *l, int i) /** * Legacy version of the ivar list */ -struct objc_ivar_list_gcc +struct objc_ivar_list_gsv1 { /** * The number of instance variables in this list. @@ -199,6 +199,6 @@ struct objc_ivar_list_gcc * An array of instance variable metadata structures. Note that this array * has count elements. */ - struct objc_ivar_gcc ivar_list[]; + struct objc_ivar_gsv1 ivar_list[]; }; diff --git a/legacy.c b/legacy.c index 1ef1b810..ba2c9cfd 100644 --- a/legacy.c +++ b/legacy.c @@ -67,7 +67,7 @@ static objc_ivar_ownership ownershipForIvar(struct objc_class_gsv1 *cls, int idx static struct objc_ivar_list *upgradeIvarList(struct objc_class_gsv1 *cls) { - struct objc_ivar_list_gcc *l = cls->ivars; + struct objc_ivar_list_gsv1 *l = cls->ivars; if (l == NULL) { return NULL; @@ -136,7 +136,7 @@ static struct objc_ivar_list *upgradeIvarList(struct objc_class_gsv1 *cls) return n; } -static struct objc_method_list *upgradeMethodList(struct objc_method_list_gcc *old) +static struct objc_method_list *upgradeMethodList(struct objc_method_list_gsv1 *old) { if (old == NULL) { @@ -368,10 +368,11 @@ PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass) } return cls; } -PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *old) + +PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gsv1 *old) { struct objc_category *cat = calloc(1, sizeof(struct objc_category)); - memcpy(cat, old, sizeof(struct objc_category_gcc)); + memcpy(cat, old, sizeof(struct objc_category_gsv1)); cat->instance_methods = upgradeMethodList(old->instance_methods); cat->class_methods = upgradeMethodList(old->class_methods); if (cat->instance_methods != NULL) @@ -390,7 +391,7 @@ PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *ol } static struct objc_protocol_method_description_list* -upgrade_protocol_method_list_gcc(struct objc_protocol_method_description_list_gcc *l) +upgrade_protocol_method_list_gsv1(struct objc_protocol_method_description_list_gsv1 *l) { if ((l == NULL) || (l->count == 0)) { @@ -409,26 +410,6 @@ upgrade_protocol_method_list_gcc(struct objc_protocol_method_description_list_gc return n; } -PRIVATE struct objc_protocol *objc_upgrade_protocol_gcc(struct objc_protocol_gcc *p) -{ - // If the protocol has already been upgraded, the don't try to upgrade it twice. - if (p->isa == (id)&_OBJC_CLASS_ProtocolGCC) - { - return objc_getProtocol(p->name); - } - p->isa = (id)&_OBJC_CLASS_ProtocolGCC; - Protocol *proto = - (Protocol*)class_createInstance(&_OBJC_CLASS_Protocol, 0); - proto->name = p->name; - // Aliasing of this between the new and old structures means that when this - // returns these will all be updated. - proto->protocol_list = p->protocol_list; - proto->instance_methods = upgrade_protocol_method_list_gcc(p->instance_methods); - proto->class_methods = upgrade_protocol_method_list_gcc(p->class_methods); - assert(proto->isa); - return proto; -} - PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gsv1 *p) { // If the protocol has already been upgraded, the don't try to upgrade it twice. @@ -438,19 +419,19 @@ PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gs } Protocol *n = (Protocol*)class_createInstance(&_OBJC_CLASS_Protocol, 0); - n->instance_methods = upgrade_protocol_method_list_gcc(p->instance_methods); + n->instance_methods = upgrade_protocol_method_list_gsv1(p->instance_methods); // Aliasing of this between the new and old structures means that when this // returns these will all be updated. n->name = p->name; n->protocol_list = p->protocol_list; - n->class_methods = upgrade_protocol_method_list_gcc(p->class_methods); + n->class_methods = upgrade_protocol_method_list_gsv1(p->class_methods); n->properties = upgradePropertyList(p->properties); n->optional_properties = upgradePropertyList(p->optional_properties); n->isa = (id)&_OBJC_CLASS_Protocol; // We do in-place upgrading of these, because they might be referenced // directly - p->instance_methods = (struct objc_protocol_method_description_list_gcc*)n->instance_methods; - p->class_methods = (struct objc_protocol_method_description_list_gcc*)n->class_methods; + p->instance_methods = (struct objc_protocol_method_description_list_gsv1*)n->instance_methods; + p->class_methods = (struct objc_protocol_method_description_list_gsv1*)n->class_methods; p->properties = (struct objc_property_list_gsv1*)n->properties; p->optional_properties = (struct objc_property_list_gsv1*)n->optional_properties; p->isa = (id)&_OBJC_CLASS_ProtocolGSv1; diff --git a/legacy.h b/legacy.h index a1326195..432382b0 100644 --- a/legacy.h +++ b/legacy.h @@ -6,10 +6,6 @@ #include "protocol.h" PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass); -PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *); - +PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gsv1 *old); PRIVATE struct objc_class_gsv1* objc_legacy_class_for_class(Class); - -PRIVATE struct objc_protocol *objc_upgrade_protocol_gcc(struct objc_protocol_gcc*); PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gsv1*); - diff --git a/legacy_malloc.c b/legacy_malloc.c deleted file mode 100644 index 3eedf273..00000000 --- a/legacy_malloc.c +++ /dev/null @@ -1,43 +0,0 @@ -#include - -void *valloc(size_t); - -// Stubs that just call the libc implementations when you call these. - -void *objc_malloc(size_t size) -{ - return malloc(size); -} - -void *objc_atomic_malloc(size_t size) -{ - return malloc(size); -} - -#ifdef __MINGW32__ -void *objc_valloc(size_t size) -{ - return malloc(size); -} -#else -void *objc_valloc(size_t size) -{ - return valloc(size); -} -#endif - -void *objc_realloc(void *mem, size_t size) -{ - return realloc(mem, size); -} - -void * objc_calloc(size_t nelem, size_t size) -{ - return calloc(nelem, size); -} - -void objc_free(void *mem) -{ - free(mem); -} - diff --git a/method.h b/method.h index a155cb84..fbd24a60 100644 --- a/method.h +++ b/method.h @@ -22,7 +22,7 @@ struct objc_method }; // end: objc_method -struct objc_method_gcc +struct objc_method_gsv1 { /** * Selector used to send messages to this method. The type encoding of @@ -87,12 +87,12 @@ static inline struct objc_method *method_at_index(struct objc_method_list *l, in /** * Legacy version of the method list. */ -struct objc_method_list_gcc +struct objc_method_list_gsv1 { /** * The next group of methods in the list. */ - struct objc_method_list_gcc *next; + struct objc_method_list_gsv1 *next; /** * The number of methods in this list. */ @@ -100,5 +100,5 @@ struct objc_method_list_gcc /** * An array of methods. Note that the actual size of this is count. */ - struct objc_method_gcc methods[]; + struct objc_method_gsv1 methods[]; }; diff --git a/objc/runtime-deprecated.h b/objc/runtime-deprecated.h deleted file mode 100644 index 1f491e39..00000000 --- a/objc/runtime-deprecated.h +++ /dev/null @@ -1,103 +0,0 @@ -#if defined(__clang__) && !defined(__OBJC_RUNTIME_INTERNAL__) -#pragma clang system_header -#endif - -#if !defined(__GNUSTEP_LIBOBJC_RUNTIME_DEPRECATED_INCLUDED__) && !defined(GNUSTEP_LIBOBJC_NO_LEGACY) -# define __GNUSTEP_LIBOBJC_RUNTIME_DEPRECATED_INCLUDED__ - -/** - * Legacy GNU runtime compatibility. - * - * All of the functions in this section are deprecated and should not be used - * in new code. - */ - -OBJC_PUBLIC -__attribute__((deprecated)) -void *objc_malloc(size_t size); - -OBJC_PUBLIC -__attribute__((deprecated)) -void *objc_atomic_malloc(size_t size); - -OBJC_PUBLIC -__attribute__((deprecated)) -void *objc_valloc(size_t size); - -OBJC_PUBLIC -__attribute__((deprecated)) -void *objc_realloc(void *mem, size_t size); - -OBJC_PUBLIC -__attribute__((deprecated)) -void * objc_calloc(size_t nelem, size_t size); - -OBJC_PUBLIC -__attribute__((deprecated)) -void objc_free(void *mem); - -OBJC_PUBLIC -__attribute__((deprecated)) -id objc_get_class(const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -id objc_lookup_class(const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -id objc_get_meta_class(const char *name); - -OBJC_PUBLIC -#if !defined(__OBJC_RUNTIME_INTERNAL__) -__attribute__((deprecated)) -#endif -Class objc_next_class(void **enum_state); - -OBJC_PUBLIC -__attribute__((deprecated)) -Class class_pose_as(Class impostor, Class super_class); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_get_typed_uid (const char *name, const char *types); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_get_any_typed_uid (const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_get_any_uid (const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_get_uid(const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -const char *sel_get_name(SEL selector); - -OBJC_PUBLIC -#if !defined(__OBJC_RUNTIME_INTERNAL__) -__attribute__((deprecated)) -#endif -BOOL sel_is_mapped(SEL selector); - -OBJC_PUBLIC -__attribute__((deprecated)) -const char *sel_get_type(SEL selector); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_register_name(const char *name); - -OBJC_PUBLIC -__attribute__((deprecated)) -SEL sel_register_typed_name(const char *name, const char *type); - -OBJC_PUBLIC -__attribute__((deprecated)) -BOOL sel_eq(SEL s1, SEL s2); - -#endif diff --git a/objc/runtime.h b/objc/runtime.h index ba9cf858..6ce8f765 100644 --- a/objc/runtime.h +++ b/objc/runtime.h @@ -1218,8 +1218,6 @@ void objc_send_initialize(id object) OBJC_NONPORTABLE; #define _C_BYCOPY 'O' #define _C_ONEWAY 'V' -#include "runtime-deprecated.h" - #ifdef __cplusplus } #endif diff --git a/protocol.c b/protocol.c index bd13dad5..b021b917 100644 --- a/protocol.c +++ b/protocol.c @@ -167,12 +167,6 @@ static BOOL init_protocols(struct objc_protocol_list *protocols) fprintf(stderr, "Unknown protocol version"); abort(); #ifdef OLDABI_COMPAT - case protocol_version_gcc: - protocols->list[i] = objc_upgrade_protocol_gcc((struct objc_protocol_gcc *)aProto); - assert(aProto->isa == (id)&_OBJC_CLASS_ProtocolGCC); - assert(protocols->list[i]->isa == (id)&_OBJC_CLASS_Protocol); - aProto = protocols->list[i]; - break; case protocol_version_gsv1: protocols->list[i] = objc_upgrade_protocol_gsv1((struct objc_protocol_gsv1 *)aProto); assert(aProto->isa == (id)&_OBJC_CLASS_ProtocolGSv1); diff --git a/protocol.h b/protocol.h index a5fd7ec7..39400981 100644 --- a/protocol.h +++ b/protocol.h @@ -5,7 +5,7 @@ #include #include -struct objc_protocol_method_description_list_gcc +struct objc_protocol_method_description_list_gsv1 { /** * Number of method descriptions in this list. @@ -25,10 +25,6 @@ struct objc_protocol_method_description_list_gcc */ enum protocol_version { - /** - * Legacy (GCC-compatible) protocol version. - */ - protocol_version_gcc = 2, /** * GNUstep V1 ABI protocol. */ @@ -152,11 +148,11 @@ struct objc_protocol_gcc /** * List of instance methods required by this protocol. */ - struct objc_protocol_method_description_list_gcc *instance_methods; + struct objc_protocol_method_description_list_gsv1 *instance_methods; /** * List of class methods required by this protocol. */ - struct objc_protocol_method_description_list_gcc *class_methods; + struct objc_protocol_method_description_list_gsv1 *class_methods; }; struct objc_protocol_gsv1 @@ -167,16 +163,16 @@ struct objc_protocol_gsv1 id isa; char *name; struct objc_protocol_list *protocol_list; - struct objc_protocol_method_description_list_gcc *instance_methods; - struct objc_protocol_method_description_list_gcc *class_methods; + struct objc_protocol_method_description_list_gsv1 *instance_methods; + struct objc_protocol_method_description_list_gsv1 *class_methods; /** * Instance methods that are declared as optional for this protocol. */ - struct objc_protocol_method_description_list_gcc *optional_instance_methods; + struct objc_protocol_method_description_list_gsv1 *optional_instance_methods; /** * Class methods that are declared as optional for this protocol. */ - struct objc_protocol_method_description_list_gcc *optional_class_methods; + struct objc_protocol_method_description_list_gsv1 *optional_class_methods; /** * Properties that are required by this protocol. */ diff --git a/selector_table.cc b/selector_table.cc index 3723ad57..75b4b977 100644 --- a/selector_table.cc +++ b/selector_table.cc @@ -176,39 +176,8 @@ static BOOL selector_types_equal(const char *t1, const char *t2) { t1 = skip_irrelevant_type_info(t1); t2 = skip_irrelevant_type_info(t2); - // This is a really ugly hack. For some stupid reason, the people - // designing Objective-C type encodings decided to allow * as a - // shorthand for char*, because strings are 'special'. Unfortunately, - // FSF GCC generates "*" for @encode(BOOL*), while Clang and Apple GCC - // generate "^c" or "^C" (depending on whether BOOL is declared - // unsigned). - // - // The correct fix is to remove * completely from type encodings, but - // unfortunately my time machine is broken so I can't travel to 1986 - // and apply a cluebat to those responsible. - if ((*t1 == '*') && (*t2 != '*')) - { - if (*t2 == '^' && (((*(t2+1) == 'C') || (*(t2+1) == 'c')))) - { - t2++; - } - else - { - return NO; - } - } - else if ((*t2 == '*') && (*t1 != '*')) - { - if (*t1 == '^' && (((*(t1+1) == 'C') || (*(t1+1) == 'c')))) - { - t1++; - } - else - { - return NO; - } - } - else if (*t1 != *t2) + + if (*t1 != *t2) { return NO; } @@ -294,20 +263,11 @@ struct SelectorHash hash = hash * 33 + c; } #ifdef TYPE_DEPENDENT_DISPATCH - // We can't use all of the values in the type encoding for the hash, - // because our equality test is a bit more complex than simple string - // encoding (for example, * and ^C have to be considered equivalent, since - // they are both used as encodings for C strings in different situations) if ((str = types)) { while((c = (size_t)*str++)) { - switch (c) - { - case '@': case 'i': case 'I': case 'l': case 'L': - case 'q': case 'Q': case 's': case 'S': - hash = hash * 33 + c; - } + hash = hash * 33 + c; } } #endif @@ -657,85 +617,4 @@ extern "C" PRIVATE void objc_register_selector_array(SEL selectors, unsigned lon } } - -/** - * Legacy GNU runtime compatibility. - * - * All of the functions in this section are deprecated and should not be used - * in new code. - */ -#ifndef NO_LEGACY -SEL sel_get_typed_uid (const char *name, const char *types) -{ - if (nullptr == name) { return nullptr; } - SEL sel = selector_lookup(name, types); - if (nullptr == sel) { return sel_registerTypedName_np(name, types); } - - struct sel_type_list *l = selLookup(sel->index); - // Skip the head, which just contains the name, not the types. - l = l->next; - if (nullptr != l) - { - sel = selector_lookup(name, l->value); - } - return sel; -} - -SEL sel_get_any_typed_uid (const char *name) -{ - if (nullptr == name) { return nullptr; } - SEL sel = selector_lookup(name, 0); - if (nullptr == sel) { return sel_registerName(name); } - - struct sel_type_list *l = selLookup(sel->index); - // Skip the head, which just contains the name, not the types. - l = l->next; - if (nullptr != l) - { - sel = selector_lookup(name, l->value); - } - return sel; -} - -SEL sel_get_any_uid (const char *name) -{ - return selector_lookup(name, 0); -} - -SEL sel_get_uid(const char *name) -{ - return selector_lookup(name, 0); -} - -const char *sel_get_name(SEL selector) -{ - return sel_getNameNonUnique(selector); -} - -BOOL sel_is_mapped(SEL selector) -{ - return isSelRegistered(selector); -} - -const char *sel_get_type(SEL selector) -{ - return sel_getType_np(selector); -} - -SEL sel_register_name(const char *name) -{ - return sel_registerName(name); -} - -SEL sel_register_typed_name(const char *name, const char *type) -{ - return sel_registerTypedName_np(name, type); -} - -BOOL sel_eq(SEL s1, SEL s2) -{ - return sel_isEqual(s1, s2); -} - -#endif // NO_LEGACY } diff --git a/visibility.h b/visibility.h index 07637fd0..0708522b 100644 --- a/visibility.h +++ b/visibility.h @@ -5,11 +5,7 @@ #else # define PRIVATE __attribute__ ((visibility("hidden"))) #endif -#ifdef NO_LEGACY -# define LEGACY PRIVATE -#else -# define LEGACY OBJC_PUBLIC -#endif +#define LEGACY PRIVATE #if defined(DEBUG) || (!defined(__clang__)) # include