Replace casts to remove constness by copying. (trema/trema#292)