Giants beat Pirates 4-3 on Barmes' error in 9th