diff options
author | Nobuyoshi Nakada <[email protected]> | 2025-05-13 22:34:18 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2025-05-13 23:16:58 +0900 |
commit | bb180b87b43c45e17ff49735a26d7a188d5c8396 () | |
tree | 18184ac323c3492f7da25a5002fd85aeec9fd835 | |
parent | 1e2a67e1b0d12b193f3d9b367ec6f1743fc70a13 (diff) |
[Bug #21331] Prohibit modification during stlike loop
Notes: Merged: https://.com/ruby/ruby/pull/13317
-rw-r--r-- | hash.c | 74 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 8 |
2 files changed, 74 insertions, 8 deletions
@@ -880,7 +880,7 @@ ar_general_foreach(VALUE hash, st_foreach_check_callback_func *func, st_update_c return 0; case ST_REPLACE: if (replace) { - retval = (*replace)(&key, &val, arg, TRUE); // TODO: pair should be same as pair before. pair = RHASH_AR_TABLE_REF(hash, i); @@ -1404,26 +1404,84 @@ hash_foreach_ensure(VALUE hash) return 0; } -int -rb_hash_stlike_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg) { if (RHASH_AR_TABLE_P(hash)) { - return ar_foreach(hash, func, arg); } else { - return st_foreach(RHASH_ST_TABLE(hash), func, arg); } } int -rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg) { if (RHASH_AR_TABLE_P(hash)) { - return ar_foreach_with_replace(hash, func, replace, arg); } else { - return st_foreach_with_replace(RHASH_ST_TABLE(hash), func, replace, arg); } } static VALUE @@ -1853,6 +1853,14 @@ class TestHash < Test::Unit::TestCase end end assert_equal(@cls[a: 2, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10], x) end def hrec h, n, &b |