From 0f1385e1b1af49346aac95d8fa81f1c2790bc547 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Wed, 11 Apr 2018 15:27:49 +0100 Subject: [PATCH] Correctly upgrade categories. 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. --- category_loader.c | 2 -- legacy.c | 13 ++++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/category_loader.c b/category_loader.c index 9f8f395..b1b0e72 100644 --- a/category_loader.c +++ b/category_loader.c @@ -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; diff --git a/legacy.c b/legacy.c index 3c9abe0..6f14682 100644 --- a/legacy.c +++ b/legacy.c @@ -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) @@ -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 ; iprotocols->count ; i++) { objc_init_protocols(cat->protocols);