From f059be533728a703e07bcf521ff4423919838ab5 Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 9 Jun 2012 10:43:57 +0000 Subject: [PATCH] Add better handling of messages returning floating point values sent to nil. --- sendmsg2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sendmsg2.c b/sendmsg2.c index b017e9e..0b026a8 100644 --- a/sendmsg2.c +++ b/sendmsg2.c @@ -10,8 +10,14 @@ void objc_send_initialize(id object); static long long nil_method(id self, SEL _cmd) { return 0; } +static long double nil_method_D(id self, SEL _cmd) { return 0; } +static double nil_method_d(id self, SEL _cmd) { return 0; } +static float nil_method_f(id self, SEL _cmd) { return 0; } static struct objc_slot nil_slot = { Nil, Nil, 0, 1, (IMP)nil_method }; +static struct objc_slot nil_slot_D = { Nil, Nil, 0, 1, (IMP)nil_method_D }; +static struct objc_slot nil_slot_d = { Nil, Nil, 0, 1, (IMP)nil_method_d }; +static struct objc_slot nil_slot_f = { Nil, Nil, 0, 1, (IMP)nil_method_f }; typedef struct objc_slot *Slot_t; @@ -134,6 +140,23 @@ Slot_t objc_msg_lookup_sender(id *receiver, SEL selector, id sender) // inlined trivially. if (UNLIKELY(*receiver == nil)) { + // Return the correct kind of zero, depending on the type encoding. + if (selector->types) + { + const char *t = selector->types; + // Skip type qualifiers + while ('r' == *t || 'n' == *t || 'N' == *t || 'o' == *t || + 'O' == *t || 'R' == *t || 'V' == *t) + { + t++; + } + switch (selector->types[0]) + { + case 'D': return &nil_slot_D; + case 'd': return &nil_slot_d; + case 'f': return &nil_slot_f; + } + } return &nil_slot; }