backport r47298 from ruby/ruby trunk