Revision: 524 http://trac.macosforge.org/projects/ruby/changeset/524 Author: lsansonetti@apple.com Date: 2008-08-29 21:26:04 -0700 (Fri, 29 Aug 2008) Log Message: ----------- fix for #113 Modified Paths: -------------- MacRuby/trunk/objc.m MacRuby/trunk/test/ruby/test_objc.rb Modified: MacRuby/trunk/objc.m =================================================================== --- MacRuby/trunk/objc.m 2008-08-30 02:49:58 UTC (rev 523) +++ MacRuby/trunk/objc.m 2008-08-30 04:26:04 UTC (rev 524) @@ -630,12 +630,17 @@ else { void *data; - Data_Get_Struct(rval, void, data); - if (data == NULL) { + if (rval == Qnil) { *(void **)ocval = NULL; } else { - memcpy(ocval, data, bs_boxed->ffi_type->size); + Data_Get_Struct(rval, void, data); + if (data == NULL) { + *(void **)ocval = NULL; + } + else { + memcpy(ocval, data, bs_boxed->ffi_type->size); + } } } @@ -3065,6 +3070,32 @@ RUBY_VM_CHECK_INTS(); } +static IMP old_imp_isaForAutonotifying; + +static Class +rb_obj_imp_isaForAutonotifying(void *rcv, SEL sel) +{ + Class ret; + +#define KVO_CHECK_DONE 0x100000 + + ret = ((Class (*)(void *, SEL)) old_imp_isaForAutonotifying)(rcv, sel); + if (ret != NULL && (RCLASS_VERSION(ret) & KVO_CHECK_DONE) == 0) { + const char *name = class_getName(ret); + if (strncmp(name, "NSKVONotifying_", 15) == 0) { + Class ret_orig; + name += 15; + ret_orig = objc_getClass(name); + if (ret_orig != NULL && RCLASS_VERSION(ret_orig) & RCLASS_IS_OBJECT_SUBCLASS) { + DLOG("XXX", "marking KVO generated klass %p (%s) as RObject", ret, class_getName(ret)); + RCLASS_VERSION(ret) |= RCLASS_IS_OBJECT_SUBCLASS; + } + } + RCLASS_VERSION(ret) |= KVO_CHECK_DONE; + } + return ret; +} + void Init_ObjC(void) { @@ -3103,6 +3134,11 @@ } rb_define_method(rb_cBasicObject, "__super_objc_send__", rb_super_objc_send, -1); + + Method m = class_getInstanceMethod(objc_getClass("NSKeyValueUnnestedProperty"), sel_registerName("isaForAutonotifying")); + assert(m != NULL); + old_imp_isaForAutonotifying = method_getImplementation(m); + method_setImplementation(m, (IMP)rb_obj_imp_isaForAutonotifying); } // for debug in gdb Modified: MacRuby/trunk/test/ruby/test_objc.rb =================================================================== --- MacRuby/trunk/test/ruby/test_objc.rb 2008-08-30 02:49:58 UTC (rev 523) +++ MacRuby/trunk/test/ruby/test_objc.rb 2008-08-30 04:26:04 UTC (rev 524) @@ -65,6 +65,7 @@ def setup framework 'Foundation' + framework 'AppKit' end def test_all_objects_inherit_from_nsobject @@ -330,4 +331,25 @@ d.testCallGetRectMethod(obj, expectedValue:obj.val) end + class Icon + attr_accessor :name + def initialize(name) + @name = name + end + end + def test_NSKVONotifying_class_preserve_ivars + array_controller = NSArrayController.new + array_controller.setAvoidsEmptySelection(false) + array_controller.setPreservesSelection(false) + array_controller.setSelectsInsertedObjects(false) + array_controller.setAutomaticallyRearrangesObjects(true) + array_controller.setSortDescriptors([NSSortDescriptor.alloc.initWithKey("name", ascending: false)]) + array_controller.addObjects([Icon.new("Rich"), Icon.new("Chad")]) + o = array_controller.arrangedObjects[0] + assert_equal(Icon, o.class) + assert_equal('Rich', o.name) + o = array_controller.arrangedObjects[1] + assert_equal(Icon, o.class) + assert_equal('Chad', o.name) + end end
participants (1)
-
source_changes@macosforge.org