[macruby-changes] [2993] MacRuby/trunk/object.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 11 03:07:12 PST 2009


Revision: 2993
          http://trac.macosforge.org/projects/ruby/changeset/2993
Author:   lsansonetti at apple.com
Date:     2009-11-11 03:07:08 -0800 (Wed, 11 Nov 2009)
Log Message:
-----------
<rdar://problem/7382416> Inspect adds extra characters to objects with member variables

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

Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c	2009-11-11 08:59:02 UTC (rev 2992)
+++ MacRuby/trunk/object.c	2009-11-11 11:07:08 UTC (rev 2993)
@@ -423,27 +423,23 @@
 static int
 inspect_i(ID id, VALUE value, VALUE str)
 {
-    VALUE str2;
-    const char *ivname;
-    const char *cstr;
+    if (!rb_is_instance_id(id)) {
+	return ST_CONTINUE;
+    }
 
-    cstr = RSTRING_PTR(str);
-
-    /* need not to show internal data */
-    if (CLASS_OF(value) == 0) return ST_CONTINUE;
-    if (!rb_is_instance_id(id)) return ST_CONTINUE;
-
+    const char *cstr = RSTRING_PTR(str);
     if (cstr[0] == '-') { /* first element */
 	rb_str_update(str, 0, 0, rb_str_new2("#"));
 	rb_str_cat2(str, " ");
     }
     else {
-	rb_str_cat2(str, ", ");
+	rb_str_cat2(str, " ");
     }
-    ivname = rb_id2name(id);
+
+    const char *ivname = rb_id2name(id);
     rb_str_cat2(str, ivname);
     rb_str_cat2(str, "=");
-    str2 = rb_inspect(value);
+    VALUE str2 = rb_inspect(value);
     rb_str_append(str, str2);
     OBJ_INFECT(str, str2);
 
@@ -460,7 +456,6 @@
 	rb_ivar_foreach(obj, inspect_i, str);
     }
     rb_str_cat2(str, ">");
-    rb_str_update(str, 0, 0, rb_str_new2("#"));
     OBJ_INFECT(str, obj);
 
     return str;
@@ -485,12 +480,12 @@
     if (TYPE(obj) == T_OBJECT) {
         bool has_ivar = false;
 
-	if (ROBJECT(obj)->tbl != NULL && CFDictionaryGetCount(ROBJECT(obj)->tbl) > 0) {
+	if (ROBJECT(obj)->tbl != NULL
+		&& CFDictionaryGetCount(ROBJECT(obj)->tbl) > 0) {
 	    has_ivar = true;
 	}
 	else {
-	    int i;
-	    for (i = 0; i < ROBJECT(obj)->num_slots; i++) {
+	    for (int i = 0; i < ROBJECT(obj)->num_slots; i++) {
 		if (ROBJECT(obj)->slots[i] != Qundef) {
 		    has_ivar = true;
 		    break;
@@ -499,10 +494,8 @@
 	}
 
         if (has_ivar) {
-            VALUE str;
             const char *c = rb_obj_classname(obj);
-
-            str = rb_sprintf("-<%s:%p", c, (void*)obj);
+            VALUE str = rb_sprintf("<%s:%p", c, (void*)obj);
             return rb_exec_recursive(inspect_obj, obj, str);
         }
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091111/c28c1cf2/attachment.html>


More information about the macruby-changes mailing list