khash cleanup.

There are two patches. 
The one is fix an underlying bug.
The another is for portability improvement.