Revision: 2901 http://trac.macosforge.org/projects/ruby/changeset/2901 Author: lsansonetti@apple.com Date: 2009-10-26 15:05:40 -0700 (Mon, 26 Oct 2009) Log Message: ----------- create -copyWithZone: on every new Object-based Ruby class Modified Paths: -------------- MacRuby/trunk/class.c MacRuby/trunk/id.c MacRuby/trunk/id.h Modified: MacRuby/trunk/class.c =================================================================== --- MacRuby/trunk/class.c 2009-10-26 21:42:12 UTC (rev 2900) +++ MacRuby/trunk/class.c 2009-10-26 22:05:40 UTC (rev 2901) @@ -59,9 +59,21 @@ static void * rb_obj_imp_allocWithZone(void *rcv, SEL sel, void *zone) { + // XXX honor zone? return (void *)rb_robject_allocate_instance((VALUE)rcv); } +VALUE rb_obj_init_copy(VALUE, SEL, VALUE); + +static void * +rb_obj_imp_copyWithZone(void *rcv, SEL sel, void *zone) +{ + // XXX honor zone? + VALUE copy = rb_robject_allocate_instance(CLASS_OF(rcv)); + rb_obj_init_copy(copy, 0, (VALUE)rcv); + return (void *)copy; +} + static BOOL rb_obj_imp_isEqual(void *rcv, SEL sel, void *obj) { @@ -101,8 +113,6 @@ return rcv; } -VALUE rb_obj_init_copy(VALUE, SEL, VALUE); - VALUE rb_class_new_instance_imp(VALUE klass, SEL sel, int argc, VALUE *argv); void @@ -123,7 +133,16 @@ (IMP)rb_obj_imp_allocWithZone); rb_objc_install_method((Class)klass, selIsEqual, (IMP)rb_obj_imp_isEqual); rb_objc_install_method((Class)klass, selInit, (IMP)rb_obj_imp_init); - rb_objc_install_method((Class)klass, selDescription, (IMP)rb_obj_imp_description); + rb_objc_install_method((Class)klass, selDescription, + (IMP)rb_obj_imp_description); + + // Create -copyWithZone:, since the method doesn't exist yet we need to + // find the type encoding somewhere, here we check Symbol since it's + // created very early. + Method m = class_getInstanceMethod((Class)rb_cSymbol, selCopyWithZone); + assert(m != NULL); + class_replaceMethod((Class)klass, selCopyWithZone, + (IMP)rb_obj_imp_copyWithZone, method_getTypeEncoding(m)); } static VALUE Modified: MacRuby/trunk/id.c =================================================================== --- MacRuby/trunk/id.c 2009-10-26 21:42:12 UTC (rev 2900) +++ MacRuby/trunk/id.c 2009-10-26 22:05:40 UTC (rev 2901) @@ -63,6 +63,7 @@ selNot = sel_registerName("!"); selAlloc = sel_registerName("alloc"); selAllocWithZone = sel_registerName("allocWithZone:"); + selCopyWithZone = sel_registerName("copyWithZone:"); selInit = sel_registerName("init"); selInitialize = sel_registerName("initialize"); selInitialize2 = sel_registerName("initialize:"); Modified: MacRuby/trunk/id.h =================================================================== --- MacRuby/trunk/id.h 2009-10-26 21:42:12 UTC (rev 2900) +++ MacRuby/trunk/id.h 2009-10-26 22:05:40 UTC (rev 2901) @@ -73,6 +73,7 @@ extern SEL selNot; extern SEL selAlloc; extern SEL selAllocWithZone; +extern SEL selCopyWithZone; extern SEL selInit; extern SEL selInitialize; extern SEL selInitialize2;
participants (1)
-
source_changes@macosforge.org