backport r44018 from ruby/ruby