From 2cc96a6f7e2238daa812cbbe73a291f4e561fbce Mon Sep 17 00:00:00 2001 From: theraven Date: Wed, 21 Jul 2010 12:26:49 +0000 Subject: [PATCH] Fix message forwarding by, for example, actually calling the public forwarding hook, instead of one that isn't exposed to GNUstep... --- objc/hooks.h | 4 ++-- sendmsg2.c | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/objc/hooks.h b/objc/hooks.h index 2cc8261..2ef5ae6 100644 --- a/objc/hooks.h +++ b/objc/hooks.h @@ -26,13 +26,13 @@ OBJC_HOOK void (*_objc_load_callback)(Class cls, struct objc_category *category) * The hook used for fast proxy lookups. This takes an object and a selector * and returns the instance that the message should be forwarded to. */ -OBJC_HOOK id (*objc_proxy_lookup)(id receiver, SEL op); +extern id (*objc_proxy_lookup)(id receiver, SEL op); /** * New runtime forwarding hook. This might be removed in future - it's * actually no more expressive than the forward2 hook and forces Foundation to * do some stuff that the runtime is better suited to. */ -OBJC_HOOK struct objc_slot *(*__objc_msg_forward3)(id, SEL); +extern struct objc_slot *(*__objc_msg_forward3)(id, SEL); /** * Forwarding hook. Takes an object and a selector and returns a method that * handles the forwarding. diff --git a/sendmsg2.c b/sendmsg2.c index 2b3337d..c9d7334 100644 --- a/sendmsg2.c +++ b/sendmsg2.c @@ -25,11 +25,15 @@ static id objc_proxy_lookup_null(id receiver, SEL op) { return nil; } static Slot_t objc_msg_forward3_null(id receiver, SEL op) { return &nil_slot; } id (*objc_proxy_lookup)(id receiver, SEL op) = objc_proxy_lookup_null; -Slot_t (*objc_msg_forward3)(id receiver, SEL op) = objc_msg_forward3_null; +Slot_t (*__objc_msg_forward3)(id receiver, SEL op) = objc_msg_forward3_null; -static inline Slot_t objc_msg_lookup_internal(id *receiver, - SEL selector, - id sender) +static +// Uncomment for debugging +//__attribute__((noinline)) +__attribute__((always_inline)) +Slot_t objc_msg_lookup_internal(id *receiver, + SEL selector, + id sender) { Slot_t result = SparseArrayLookup((*receiver)->isa->dtable, PTR_TO_IDX(selector->name)); @@ -62,8 +66,8 @@ static inline Slot_t objc_msg_lookup_internal(id *receiver, return result; } id newReceiver = objc_proxy_lookup(*receiver, selector); - // If some other library wants us to play forwarding games, try again - // with the new object. + // If some other library wants us to play forwarding games, try + // again with the new object. if (nil != newReceiver) { *receiver = newReceiver; @@ -71,7 +75,7 @@ static inline Slot_t objc_msg_lookup_internal(id *receiver, } if (0 == result) { - result = objc_msg_forward3(*receiver, selector); + result = __objc_msg_forward3(*receiver, selector); } } } @@ -299,9 +303,7 @@ IMP objc_msg_lookup(id receiver, SEL selector) Slot_t slot = objc_msg_lookup_internal(&self, selector, nil); if (self != receiver) { - if (0 == __objc_msg_forward2) { return 0; } - - return __objc_msg_forward2(receiver, selector); + slot = __objc_msg_forward3(receiver, selector); } return slot->method; }