[前][次][番号順一覧][スレッド一覧]

ruby-changes:41444

From: normal <ko1@a...>
Date: Wed, 13 Jan 2016 04:25:43 +0900 (JST)
Subject: [ruby-changes:41444] normal:r53518 (trunk): resolve class name earlier and more consistently

normal	2016-01-13 04:26:07 +0900 (Wed, 13 Jan 2016)

  New Revision: 53518

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53518

  Log:
    resolve class name earlier and more consistently
    
    This further avoids class name resolution issues which came
    about due to relying on hash table ordering before r53376.
    
    Pre-caching the class name when it is never used raises memory
    use, but the overall gain from moving away from st still gives
    us a small gain.  Reverting r53376 and this patch and testing with
    "valgrind -v ./ruby -rrdoc -eexit" on x86 (32-bit) shows:
    
    before:
        in use at exit: 1,662,239 bytes in 25,286 blocks
      total heap usage: 49,514 allocs, 24,228 frees, 6,005,561 bytes allocated
    
    after, with this change:
        in use at exit: 1,646,529 bytes in 24,572 blocks
      total heap usage: 48,891 allocs, 24,319 frees, 6,003,921 bytes allocated
    
    * class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP
    * object.c (rb_mod_const_set): move name resolution to rb_const_set
    * variable.c (rb_const_set): do class resolution here
      [ruby-core:72807] [Bug #11977]

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/object.c
    trunk/variable.c
Index: class.c
===================================================================
--- class.c	(revision 53517)
+++ class.c	(revision 53518)
@@ -547,6 +547,10 @@ Init_class_hierarchy(void) https://github.com/ruby/ruby/blob/trunk/class.c#L547
 {
     rb_cBasicObject = boot_defclass("BasicObject", 0);
     rb_cObject = boot_defclass("Object", rb_cBasicObject);
+
+    /* resolve class name ASAP for order-independence */
+    rb_class_name(rb_cObject);
+
     rb_cModule = boot_defclass("Module", rb_cObject);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53517)
+++ ChangeLog	(revision 53518)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jan 13 03:42:58 2016  Eric Wong  <e@8...>
+
+	* class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP
+	* object.c (rb_mod_const_set): move name resolution to rb_const_set
+	* variable.c (rb_const_set): do class resolution here
+	  [ruby-core:72807] [Bug #11977]
+
 Wed Jan 13 00:37:12 2016  Satoshi Ohmori  <sachin21dev@g...>
 
 	* man/ruby.1: fix double word typo.  [Fix GH-1194]
Index: variable.c
===================================================================
--- variable.c	(revision 53517)
+++ variable.c	(revision 53518)
@@ -2569,6 +2569,13 @@ rb_const_set(VALUE klass, ID id, VALUE v https://github.com/ruby/ruby/blob/trunk/variable.c#L2569
 	args.value = val;
 	const_tbl_update(&args);
     }
+    /*
+     * Resolve and cache class name immediately to resolve ambiguity
+     * and avoid order-dependency on const_tbl
+     */
+    if (rb_cObject && (RB_TYPE_P(val, T_MODULE) || RB_TYPE_P(val, T_CLASS))) {
+	rb_class_name(val);
+    }
 }
 
 static void
Index: object.c
===================================================================
--- object.c	(revision 53517)
+++ object.c	(revision 53518)
@@ -2178,13 +2178,6 @@ rb_mod_const_set(VALUE mod, VALUE name, https://github.com/ruby/ruby/blob/trunk/object.c#L2178
     if (!id) id = rb_intern_str(name);
     rb_const_set(mod, id, value);
 
-    /*
-     * Resolve and cache class name immediately to resolve ambiguity
-     * and avoid order-dependency on const_tbl
-     */
-    if (RB_TYPE_P(value, T_MODULE) || RB_TYPE_P(value, T_CLASS)) {
-	rb_class_name(value);
-    }
     return value;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]