Fixed up a few compilation errors, which is fiddly since there's both C++ and C code in here.