backport r48409 from ruby trunk