1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 496591de96: [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(-)
This commit is contained in:
NARUSE, Yui 2022-02-17 12:19:17 +09:00
parent 8a0dfd4a4d
commit 7fe0ebc4e7
3 changed files with 15 additions and 3 deletions

1
st.c
View file

@ -1363,7 +1363,6 @@ st_shift(st_table *tab, st_data_t *key, st_data_t *value)
return 1;
}
}
tab->entries_start = tab->entries_bound = 0;
if (value != 0) *value = 0;
return 0;
}

View file

@ -1069,6 +1069,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 })

View file

@ -11,11 +11,11 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 16
#define RUBY_PATCHLEVEL 17
#define RUBY_RELEASE_YEAR 2022
#define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 14
#define RUBY_RELEASE_DAY 17
#include "ruby/version.h"