cherry-pick an upstream commit at Paul Eggert's suggestion