ruby-changes:60421
From: Alan <ko1@a...>
Date: Mon, 16 Mar 2020 07:12:10 +0900 (JST)
Subject: [ruby-changes:60421] 713dc619f5 (master): Add missing write barrier for Hash#transform_values{, !}
https://git.ruby-lang.org/ruby.git/commit/?id=713dc619f5 From 713dc619f5372a645b66bef9dacee217c4101cb4 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] diff --git a/hash.c b/hash.c index 62383a6..5bbb3da 100644 --- a/hash.c +++ b/hash.c @@ -3257,7 +3257,8 @@ static int https://github.com/ruby/ruby/blob/trunk/hash.c#L3257 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; } @@ -3287,7 +3288,7 @@ rb_hash_transform_values(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3288 result = hash_copy(hash_alloc(rb_cHash), hash); 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; @@ -3317,7 +3318,7 @@ rb_hash_transform_values_bang(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3318 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/