[macruby-changes] [2901] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 26 15:05:41 PDT 2009


Revision: 2901
          http://trac.macosforge.org/projects/ruby/changeset/2901
Author:   lsansonetti at 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;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091026/65330199/attachment-0001.html>


More information about the macruby-changes mailing list