backport r46890 from ruby/ruby trunk