backport r48736 from ruby/ruby trunk