backport r47624 from ruby/ruby trunk.