backport r48279 from ruby/ruby trunk