Merging Ben's changes from trunk, changeset 1105 to changeset 1234. This breaks Python test suite TestExtFn, so will need investigation.