Backport changes from Emacs revs 115081 and 115082