Big refactor of spatial.distance

Three patches for `scipy.spatial.distance`. The first refactors the code by generating a lot of boilerplate using macros, reducing the code by about a thousand lines, and leaving only one module to be compiled. The second fixes a few unchecked `malloc` calls. The third adds some more `static` declarations, re-indents a file and gets rid of an unused function.