Upstream commit r82 by Cheng Sun