Skip to content

Commit 7fe0ebc

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 8a0dfd4 commit 7fe0ebc

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

st.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,6 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
13631363
return 1;
13641364
}
13651365
}
1366-
tab->entries_start = tab->entries_bound = 0;
13671366
if (value != 0) *value = 0;
13681367
return 0;
13691368
}

test/ruby/test_hash.rb

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

1072+
def test_shift_for_empty_hash
1073+
# [ruby-dev:51159]
1074+
h = @cls[]
1075+
100.times{|n|
1076+
while h.size < n
1077+
k = Random.rand 0..1<<30
1078+
h[k] = 1
1079+
end
1080+
0 while h.shift
1081+
assert_equal({}, h)
1082+
}
1083+
end
1084+
10721085
def test_reject_bang2
10731086
assert_equal({1=>2}, @cls[1=>2,3=>4].reject! {|k, v| k + v == 7 })
10741087
assert_nil(@cls[1=>2,3=>4].reject! {|k, v| k == 5 })

version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 0
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 16
14+
#define RUBY_PATCHLEVEL 17
1515

1616
#define RUBY_RELEASE_YEAR 2022
1717
#define RUBY_RELEASE_MONTH 2
18-
#define RUBY_RELEASE_DAY 14
18+
#define RUBY_RELEASE_DAY 17
1919

2020
#include "ruby/version.h"
2121

0 commit comments

Comments
 (0)