Fix clang warnings.

This fixes all compiler warnings under clang.
The major change is safely downcasting from
Py_ssize_t to int (BSON string lengths and document
size are signed int32). This change also includes
some code cleanup in the functions touched to fix
compiler warnings.