Skip to content

Commit

Permalink
Correctly upgrade categories.
Browse files Browse the repository at this point in the history
This was hidden by a compiler bug where the new version was generated in
the same format as the old, so upgrading in the wrong place worked.
  • Loading branch information
davidchisnall committed Apr 11, 2018
1 parent d11a031 commit 0f1385e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 0 additions & 2 deletions category_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ static void register_methods(struct objc_class *cls, struct objc_method_list *l)
{
if (NULL == l) { return; }

// Replace the method names with selectors.
objc_register_selectors_from_list(l);
// Add the method list at the head of the list of lists.
l->next = cls->methods;
cls->methods = l;
Expand Down
13 changes: 12 additions & 1 deletion legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ static struct objc_method_list *upgradeMethodList(struct objc_method_list_gcc *o
{
return NULL;
}
if (old->count == 0)
{
return NULL;
}
struct objc_method_list *l = calloc(sizeof(struct objc_method_list) + old->count * sizeof(struct objc_method), 1);
l->count = old->count;
if (old->next)
Expand Down Expand Up @@ -309,13 +313,20 @@ PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass)
}
return cls;
}

PRIVATE struct objc_category *objc_upgrade_category(struct objc_category_gcc *old)
{
struct objc_category *cat = calloc(1, sizeof(struct objc_category));
memcpy(cat, old, sizeof(struct objc_category_gcc));
cat->instance_methods = upgradeMethodList(old->instance_methods);
cat->class_methods = upgradeMethodList(old->class_methods);
if (cat->instance_methods != NULL)
{
objc_register_selectors_from_list(cat->instance_methods);
}
if (cat->class_methods != NULL)
{
objc_register_selectors_from_list(cat->class_methods);
}
for (int i=0 ; i<cat->protocols->count ; i++)
{
objc_init_protocols(cat->protocols);
Expand Down

0 comments on commit 0f1385e

Please sign in to comment.