summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2021-03-20 19:35:36 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-20 20:46:15 +0900
commit7954bb056be30e86c419fe3792064d28990a4999 (patch)
treee69e50ed25911633d8193872b4c62a12a919babd /hash.c
parent278522f0535d081ff6473f210cb45f923ff8810a (diff)
Some Hash destructive methods ensure the receiver modifiable [Bug #17736]
refs: * https://bugs.ruby-lang.org/issues/17736 * https://github.com/ruby/ruby/pull/4296 This commit aims to cover following methods * Hash#select! * Hash#filter! * Hash#keep_if * Hash#reject! * Hash#delete_if I think these are not all. --- * Ensure the receiver is modifiable or not * Assert the receiver is not modified
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4297
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index e9a3ca96d3..8f51f467c2 100644
--- a/hash.c
+++ b/hash.c
@@ -2476,6 +2476,7 @@ static int
delete_if_i(VALUE key, VALUE value, VALUE hash)
{
if (RTEST(rb_yield_values(2, key, value))) {
+ rb_hash_modify(hash);
return ST_DELETE;
}
return ST_CONTINUE;
@@ -2705,6 +2706,7 @@ static int
keep_if_i(VALUE key, VALUE value, VALUE hash)
{
if (!RTEST(rb_yield_values(2, key, value))) {
+ rb_hash_modify(hash);
return ST_DELETE;
}
return ST_CONTINUE;