backport r48268 from ruby/ruby trunk