Backport change in r117298 from Emacs trunk