From 334ca2dc06931ec7da93787635a00ec0f1aad086 Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Sat, 19 Mar 2022 22:50:51 +0900 Subject: merge revision(s) 496591de96b261b8789332c7f8b2bfbd17658955: [Backport #18578] st.c: Do not clear entries_bound when calling Hash#shift for empty hash tab->entries_bound is used to check if the bins are full in rebuild_table_if_necessary. Hash#shift against an empty hash assigned 0 to tab->entries_bound, but didn't clear the bins. Thus, the table is not rebuilt even when the bins are full. Attempting to add a new element into full-bin hash gets stuck. This change stops clearing tab->entries_bound in Hash#shift. [Bug #18578] --- st.c | 1 - test/ruby/test_hash.rb | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) --- st.c | 1 - test/ruby/test_hash.rb | 13 +++++++++++++ version.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/st.c b/st.c index 4258f93ffc..599f93a463 100644 --- a/st.c +++ b/st.c @@ -1486,7 +1486,6 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value) } } st_assert(tab->num_entries == 0); - tab->entries_start = tab->entries_bound = 0; if (value != 0) *value = 0; return 0; } diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 046ea40f5d..d4af130a07 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -983,6 +983,19 @@ class TestHash < Test::Unit::TestCase assert_equal("FOO", h.shift) end + def test_shift_for_empty_hash + # [ruby-dev:51159] + h = @cls[] + 100.times{|n| + while h.size < n + k = Random.rand 0..1<<30 + h[k] = 1 + end + 0 while h.shift + assert_equal({}, h) + } + end + def test_reject_bang2 assert_equal({1=>2}, @cls[1=>2,3=>4].reject! {|k, v| k + v == 7 }) assert_nil(@cls[1=>2,3=>4].reject! {|k, v| k == 5 }) diff --git a/version.h b/version.h index 944a877c76..23d557496e 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 217 +#define RUBY_PATCHLEVEL 218 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 3 -- cgit v1.2.3