summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2020-03-14 00:59:55 (GMT)
committerNARUSE, Yui <naruse@airemix.jp>2020-03-26 12:18:25 (GMT)
commit2a3027b7b54a3118731f70c9e88aabbd495bb9fe (patch)
treee5052daac22db646e80ef774f23a1fb935b6b1d1
parent95c3bb6c426a11253644a86137bb67c542fd5799 (diff)
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)
-rw-r--r--hash.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index 85bcda3..66149ac 100644
--- a/hash.c
+++ b/hash.c
@@ -3156,7 +3156,8 @@ static int
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)
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)
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;