niwibe/py-mhash — pull request #1 by kaithar (2013-06-06 10:27:13+00:00)
Title: Binding produces truncated hashes due to type mismatch

Hi, I just ran in to a really annoying bug with your code.

The problem specifically is this line in api.py:
lib.mhash_end.restype = ctypes.c_char_p

Ctypes transparently converts c_char_p returns to strings and blindly assumes them to be null terminated strings. Per the docs, c_char_p shouldn't be used for binary data.
This does, unfortunately, complicate things as you can't access c_void_p directly.

I can only assume that the len() > size check is there because the strings not being null terminated meant you were getting random string lengths back.