backport r48370 from ruby/ruby trunk
backport r48371 from ruby/ruby trunk