Skip to content

Commit

Permalink
Deletion of old GCC structs and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Sep 8, 2024
1 parent aa86717 commit 07d65fa
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 124 deletions.
42 changes: 21 additions & 21 deletions category.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
27 changes: 2 additions & 25 deletions class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ivar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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[];
};

40 changes: 10 additions & 30 deletions legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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;
Expand Down Expand Up @@ -135,7 +135,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)
{
Expand Down Expand Up @@ -367,10 +367,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)
Expand All @@ -389,7 +390,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))
{
Expand All @@ -408,27 +409,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 == objc_getClass("ProtocolGCC"))
{
return objc_getProtocol(p->name);
}
p->isa = objc_getClass("ProtocolGCC");
Protocol *proto =
(Protocol*)class_createInstance((Class)objc_getClass("Protocol"),
sizeof(struct objc_protocol) - sizeof(id));
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.
Expand All @@ -439,19 +419,19 @@ PRIVATE struct objc_protocol *objc_upgrade_protocol_gsv1(struct objc_protocol_gs
Protocol *n =
(Protocol*)class_createInstance((Class)objc_getClass("Protocol"),
sizeof(struct objc_protocol) - sizeof(id));
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 = objc_getClass("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 = objc_getClass("ProtocolGSv1");
Expand Down
6 changes: 1 addition & 5 deletions legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);

8 changes: 4 additions & 4 deletions method.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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
Expand Down Expand Up @@ -86,18 +86,18 @@ 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.
*/
int count;
/**
* An array of methods. Note that the actual size of this is count.
*/
struct objc_method_gcc methods[];
struct objc_method_gsv1 methods[];
};
24 changes: 2 additions & 22 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ static id incompleteProtocolClass(void)
return IncompleteProtocolClass;
}

/**
* Class used for legacy GCC protocols (`ProtocolGCC`).
*/
static id protocol_class_gcc;
/**
* Class used for legacy GNUstep V1 ABI protocols (`ProtocolGSv1`).
*/
Expand All @@ -72,10 +68,6 @@ static id protocol_class_gsv2;

static BOOL init_protocol_classes(void)
{
if (nil == protocol_class_gcc)
{
protocol_class_gcc = objc_getClass("ProtocolGCC");
}
if (nil == protocol_class_gsv1)
{
protocol_class_gsv1 = objc_getClass("ProtocolGSv1");
Expand All @@ -84,8 +76,7 @@ static BOOL init_protocol_classes(void)
{
protocol_class_gsv2 = objc_getClass("Protocol");
}
if ((nil == protocol_class_gcc) ||
(nil == protocol_class_gsv1) ||
if ((nil == protocol_class_gsv1) ||
(nil == protocol_class_gsv2))
{
return NO;
Expand All @@ -108,10 +99,6 @@ static BOOL protocol_hasOptionalMethodsAndProperties(struct objc_protocol *p)
{
return NO;
}
if (p->isa == protocol_class_gcc)
{
return NO;
}
return YES;
}

Expand Down Expand Up @@ -207,8 +194,7 @@ static BOOL init_protocols(struct objc_protocol_list *protocols)
{
struct objc_protocol *aProto = protocols->list[i];
// Don't initialise a protocol twice
if ((aProto->isa == protocol_class_gcc) ||
(aProto->isa == protocol_class_gsv1) ||
if ((aProto->isa == protocol_class_gsv1) ||
(aProto->isa == protocol_class_gsv2))
{
continue;
Expand All @@ -224,12 +210,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 == protocol_class_gcc);
assert(protocols->list[i]->isa == protocol_class_gsv2);
aProto = protocols->list[i];
break;
case protocol_version_gsv1:
protocols->list[i] = objc_upgrade_protocol_gsv1((struct objc_protocol_gsv1 *)aProto);
assert(aProto->isa == protocol_class_gsv1);
Expand Down
21 changes: 7 additions & 14 deletions protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdlib.h>
#include <assert.h>

struct objc_protocol_method_description_list_gcc
struct objc_protocol_method_description_list_gsv1
{
/**
* Number of method descriptions in this list.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -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.
*/
Expand All @@ -196,9 +192,6 @@ struct objc_protocol_gsv1
@interface Protocol : Object
@end

@interface ProtocolGCC : Protocol
@end

@interface ProtocolGSv1 : Protocol
@end

Expand Down

0 comments on commit 07d65fa

Please sign in to comment.