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

ruby-changes:46338

From: ko1 <ko1@a...>
Date: Sun, 23 Apr 2017 09:20:32 +0900 (JST)
Subject: [ruby-changes:46338] ko1:r58452 (trunk): mark Hash keys correctly.

ko1	2017-04-23 09:20:27 +0900 (Sun, 23 Apr 2017)

  New Revision: 58452

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

  Log:
    mark Hash keys correctly.
    
    * hash.c (rb_hash_new_from_object): same as r58434.
      Newly created frozen objects are not referred from any roots/objects.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 58451)
+++ hash.c	(revision 58452)
@@ -643,10 +643,8 @@ hash_insert_raw(VALUE hash, st_table *tb https://github.com/ruby/ruby/blob/trunk/hash.c#L643
         (st_data_t)key;
 
     st_insert(tbl, k, v);
-    if (hash != Qfalse) {
-	RB_OBJ_WRITTEN(hash, Qundef, key);
-	RB_OBJ_WRITTEN(hash, Qundef, val);
-    }
+    RB_OBJ_WRITTEN(hash, Qundef, key);
+    RB_OBJ_WRITTEN(hash, Qundef, val);
 }
 
 static VALUE
@@ -695,6 +693,8 @@ rb_hash_new_from_object(VALUE klass, VAL https://github.com/ruby/ruby/blob/trunk/hash.c#L693
 	long i;
 	long len = RARRAY_LEN(tmp);
 	st_table *tbl = len ? st_init_table_with_size(&objhash, len) : NULL;
+	VALUE hv = hash_alloc_from_st(klass, tbl);;
+
 	for (i = 0; i < len; ++i) {
 	    VALUE e = RARRAY_AREF(tmp, i);
 	    VALUE v = rb_check_array_type(e);
@@ -721,10 +721,10 @@ rb_hash_new_from_object(VALUE klass, VAL https://github.com/ruby/ruby/blob/trunk/hash.c#L721
 		val = RARRAY_AREF(v, 1);
 	      case 1:
 		key = RARRAY_AREF(v, 0);
-		hash_insert_raw(Qfalse, tbl, key, val);
+		hash_insert_raw(hv, tbl, key, val);
 	    }
 	}
-	return hash_alloc_from_st(klass, tbl);
+	return hv;
     }
 
     rb_raise(rb_eArgError, "odd number of arguments for Hash");

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

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