Skip to content

Commit 334ca2d

Browse files
committed
merge revision(s) 496591d: [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(-)
1 parent 19fec93 commit 334ca2d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

st.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,6 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
14861486
}
14871487
}
14881488
st_assert(tab->num_entries == 0);
1489-
tab->entries_start = tab->entries_bound = 0;
14901489
if (value != 0) *value = 0;
14911490
return 0;
14921491
}

test/ruby/test_hash.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,19 @@ def h.default(k = nil)
983983
assert_equal("FOO", h.shift)
984984
end
985985

986+
def test_shift_for_empty_hash
987+
# [ruby-dev:51159]
988+
h = @cls[]
989+
100.times{|n|
990+
while h.size < n
991+
k = Random.rand 0..1<<30
992+
h[k] = 1
993+
end
994+
0 while h.shift
995+
assert_equal({}, h)
996+
}
997+
end
998+
986999
def test_reject_bang2
9871000
assert_equal({1=>2}, @cls[1=>2,3=>4].reject! {|k, v| k + v == 7 })
9881001
assert_nil(@cls[1=>2,3=>4].reject! {|k, v| k == 5 })

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
33
#define RUBY_VERSION_TEENY 6
44
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
5-
#define RUBY_PATCHLEVEL 217
5+
#define RUBY_PATCHLEVEL 218
66

77
#define RUBY_RELEASE_YEAR 2022
88
#define RUBY_RELEASE_MONTH 3

0 commit comments

Comments
 (0)