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

ruby-changes:31981

From: tmm1 <ko1@a...>
Date: Sun, 8 Dec 2013 12:03:48 +0900 (JST)
Subject: [ruby-changes:31981] tmm1:r44060 (trunk): hash.c: fix WB miss issue in Hash#replace

tmm1	2013-12-08 12:03:42 +0900 (Sun, 08 Dec 2013)

  New Revision: 44060

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44060

  Log:
    hash.c: fix WB miss issue in Hash#replace
    
    * hash.c (rb_hash_replace): add a write barrier to fix GC mark miss on
      hashes using Hash#replace [Bug #9226] [ruby-core:58948]

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44059)
+++ ChangeLog	(revision 44060)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec  8 11:59:40 2013  Aman Gupta <ruby@t...>
+
+	* hash.c (rb_hash_replace): add a write barrier to fix GC mark miss on
+	  hashes using Hash#replace [Bug #9226] [ruby-core:58948]
+
 Sun Dec  8 11:21:00 2013  Aman Gupta <ruby@t...>
 
 	* include/ruby/ruby.h: add RGENGC_WB_PROTECTED_NODE_CREF setting
Index: hash.c
===================================================================
--- hash.c	(revision 44059)
+++ hash.c	(revision 44060)
@@ -1412,22 +1412,9 @@ rb_hash_replace(VALUE hash, VALUE hash2) https://github.com/ruby/ruby/blob/trunk/hash.c#L1412
 
     table2 = RHASH(hash2)->ntbl;
 
-    if (RHASH_EMPTY_P(hash2)) {
-	rb_hash_clear(hash);
-	if (table2) hash_tbl(hash)->type = table2->type;
-	return hash;
-    }
-
-    if (RHASH_ITER_LEV(hash) > 0) {
-	rb_hash_clear(hash);
-	hash_tbl(hash)->type = table2->type;
-	rb_hash_foreach(hash2, replace_i, hash);
-    }
-    else {
-	st_table *old_table = RHASH(hash)->ntbl;
-	if (old_table) st_free_table(old_table);
-	RHASH(hash)->ntbl = st_copy(table2);
-    }
+    rb_hash_clear(hash);
+    hash_tbl(hash)->type = table2->type;
+    rb_hash_foreach(hash2, replace_i, hash);
 
     return hash;
 }

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

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