MAINT/TST: refactor and test packbits/unpackbits

Pushes the GIL release one loop outward. First test for these functions (!).

Incorporates suggestions by @jaimefrio and @charris.
ENH ensure np.packbits works on np.bool dtype
Merge pull request #5319 from larsmans/c-fixes

MAINT: refactor packbits/unpackbits