backport r48512 from ruby/ruby trunk.