backport r47201 from ruby/ruby trunk.