Revision: 3953 http://trac.macosforge.org/projects/ruby/changeset/3953 Author: lsansonetti@apple.com Date: 2010-04-21 14:34:24 -0700 (Wed, 21 Apr 2010) Log Message: ----------- fixed the NSNumber conversion (which broke NSProxy), moved the support forwarding check from the dispatcher into objc.m Modified Paths: -------------- MacRuby/trunk/dispatcher.cpp MacRuby/trunk/objc.h MacRuby/trunk/objc.m Modified: MacRuby/trunk/dispatcher.cpp =================================================================== --- MacRuby/trunk/dispatcher.cpp 2010-04-21 17:37:17 UTC (rev 3952) +++ MacRuby/trunk/dispatcher.cpp 2010-04-21 21:34:24 UTC (rev 3953) @@ -471,21 +471,6 @@ rcache.node = node; } -static bool -can_forwardInvocation(VALUE recv, SEL sel) -{ - if (!SPECIAL_CONST_P(recv)) { - static SEL methodSignatureForSelector = 0; - if (methodSignatureForSelector == 0) { - methodSignatureForSelector = - sel_registerName("methodSignatureForSelector:"); - } - return objc_msgSend((id)recv, methodSignatureForSelector, (id)sel) - != nil; - } - return false; -} - static void fill_ocache(struct mcache *cache, VALUE self, Class klass, IMP imp, SEL sel, Method method, int argc) @@ -635,7 +620,8 @@ } // Does the receiver implements -forwardInvocation:? - if (opt != DISPATCH_SUPER && can_forwardInvocation(self, sel)) { + if (opt != DISPATCH_SUPER + && rb_objc_supports_forwarding(self, sel)) { fill_ocache(cache, self, klass, (IMP)objc_msgSend, sel, NULL, argc); goto dispatch; Modified: MacRuby/trunk/objc.h =================================================================== --- MacRuby/trunk/objc.h 2010-04-21 17:37:17 UTC (rev 3952) +++ MacRuby/trunk/objc.h 2010-04-21 21:34:24 UTC (rev 3953) @@ -18,6 +18,8 @@ bool rb_objc_get_types(VALUE recv, Class klass, SEL sel, Method m, bs_element_method_t *bs_method, char *buf, size_t buflen); +bool rb_objc_supports_forwarding(VALUE recv, SEL sel); + void rb_objc_define_kvo_setter(VALUE klass, ID mid); VALUE rb_vm_set_kvo_ivar(VALUE obj, ID name, VALUE val); @@ -192,7 +194,19 @@ return (id)obj; } -extern CFTypeID __CFNumberTypeID; +static inline bool +rb_objc_obj_is_nsnumber(id obj) +{ + Class k = object_getClass(obj); // might be an immediate + do { + if (k == (Class)rb_cNSNumber) { + return true; + } + k = class_getSuperclass(k); + } + while (k != NULL); + return false; +} static inline VALUE rb_ocid_to_rval(id obj) @@ -207,7 +221,7 @@ return Qnil; } - if (CFGetTypeID(obj) == __CFNumberTypeID) { + if (rb_objc_obj_is_nsnumber(obj)) { // TODO: this could be optimized in case the object is an immediate. if (CFNumberIsFloatType((CFNumberRef)obj)) { double v = 0; Modified: MacRuby/trunk/objc.m =================================================================== --- MacRuby/trunk/objc.m 2010-04-21 17:37:17 UTC (rev 3952) +++ MacRuby/trunk/objc.m 2010-04-21 21:34:24 UTC (rev 3953) @@ -25,8 +25,6 @@ # include "bs.h" #endif -CFTypeID __CFNumberTypeID = 0; - static inline const char * rb_get_bs_method_type(bs_element_method_t *bs_method, int arg) { @@ -122,6 +120,15 @@ return false; } +bool +rb_objc_supports_forwarding(VALUE recv, SEL sel) +{ + if (!SPECIAL_CONST_P(recv)) { + return [(id)recv methodSignatureForSelector:sel] != nil; + } + return false; +} + static id _symbolicator = nil; #define SYMBOLICATION_FRAMEWORK @"/System/Library/PrivateFrameworks/Symbolication.framework" @@ -685,9 +692,6 @@ void Init_ObjC(void) { - __CFNumberTypeID = CFNumberGetTypeID(); - assert(__CFNumberTypeID > 0); - rb_objc_define_method(rb_mKernel, "load_bridge_support_file", rb_objc_load_bs, 1);
participants (1)
-
source_changes@macosforge.org