[macruby-changes] [4249] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 18 18:33:52 PDT 2010


Revision: 4249
          http://trac.macosforge.org/projects/ruby/changeset/4249
Author:   martinlagardette at apple.com
Date:     2010-06-18 18:33:48 -0700 (Fri, 18 Jun 2010)
Log Message:
-----------
When the default `-description` is called, avoid calling `#to_s` on the object if the implementation is the same

 - The default `#to_s` method will be called instead
 - Fixes #752

Modified Paths:
--------------
    MacRuby/trunk/class.c
    MacRuby/trunk/object.c

Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c	2010-06-18 23:18:13 UTC (rev 4248)
+++ MacRuby/trunk/class.c	2010-06-19 01:33:48 UTC (rev 4249)
@@ -71,9 +71,18 @@
     return rcv;
 }
 
+VALUE rb_any_to_string(VALUE obj, SEL sel);
+
 static void *
 rb_obj_imp_description(void *rcv, SEL sel)
 {
+    // If #description and #to_s are the same method (ex. when aliased)
+    Class rcv_class = (Class)CLASS_OF(rcv);
+    IMP desc_imp = class_getMethodImplementation(rcv_class, selDescription);
+    IMP to_s_imp = class_getMethodImplementation(rcv_class, selToS);
+    if (desc_imp == to_s_imp) {
+	return (void *)rb_any_to_string((VALUE)rcv, sel);
+    }
     return (void *)rb_vm_call(OC2RB(rcv), selToS, 0, NULL);
 }
 

Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c	2010-06-18 23:18:13 UTC (rev 4248)
+++ MacRuby/trunk/object.c	2010-06-19 01:33:48 UTC (rev 4249)
@@ -370,7 +370,7 @@
  *  initial execution context of Ruby programs returns ``main.''
  */
 
-static VALUE
+VALUE
 rb_any_to_string(VALUE obj, SEL sel)
 {
     const char *cname = rb_obj_classname(obj);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100618/5a4eff3d/attachment.html>


More information about the macruby-changes mailing list