Ported 12a61343d283a7f463861271c9c12e046f71571f to the 1.10 branch.