backport r47199 from ruby/ruby trunk.
backport r47200 from ruby/ruby trunk.