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

ruby-changes:60524

From: Alan <ko1@a...>
Date: Thu, 26 Mar 2020 23:59:28 +0900 (JST)
Subject: [ruby-changes:60524] 2a3027b7b5 (ruby_2_7): Add missing write barrier for Hash#transform_values{, !}

https://git.ruby-lang.org/ruby.git/commit/?id=2a3027b7b5

From 2a3027b7b54a3118731f70c9e88aabbd495bb9fe Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Fri, 13 Mar 2020 20:59:55 -0400
Subject: Add missing write barrier for Hash#transform_values{,!}

21994b7fd686f263544fcac1616ecf3189fb78b3 removed the write barrier that
was present in rb_hash_aset(). Re-insert it to not crash during GC.

[Bug #16689]

(cherry picked from commit 713dc619f5372a645b66bef9dacee217c4101cb4)

diff --git a/hash.c b/hash.c
index 85bcda3..66149ac 100644
--- a/hash.c
+++ b/hash.c
@@ -3156,7 +3156,8 @@ static int https://github.com/ruby/ruby/blob/trunk/hash.c#L3156
 transform_values_foreach_replace(st_data_t *key, st_data_t *value, st_data_t argp, int existing)
 {
     VALUE new_value = rb_yield((VALUE)*value);
-    *value = new_value;
+    VALUE hash = (VALUE)argp;
+    RB_OBJ_WRITE(hash, value, new_value);
     return ST_CONTINUE;
 }
 
@@ -3186,7 +3187,7 @@ rb_hash_transform_values(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3187
     result = hash_dup(hash, rb_cHash, 0);
 
     if (!RHASH_EMPTY_P(hash)) {
-        rb_hash_stlike_foreach_with_replace(result, transform_values_foreach_func, transform_values_foreach_replace, 0);
+        rb_hash_stlike_foreach_with_replace(result, transform_values_foreach_func, transform_values_foreach_replace, result);
     }
 
     return result;
@@ -3216,7 +3217,7 @@ rb_hash_transform_values_bang(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3217
     rb_hash_modify_check(hash);
 
     if (!RHASH_TABLE_EMPTY_P(hash)) {
-        rb_hash_stlike_foreach_with_replace(hash, transform_values_foreach_func, transform_values_foreach_replace, 0);
+        rb_hash_stlike_foreach_with_replace(hash, transform_values_foreach_func, transform_values_foreach_replace, hash);
     }
 
     return hash;
-- 
cgit v0.10.2


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

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