Fix portability problems on Darwin.
Add some helpful debug code.
Other minor fixes (e.g. remove redundant newlines in debug messages).
Bump to 4.1 TRUNK