Merge pull request #1 from bjz/master

Add upstream modifications.
Fixes to work with the new TLS api.

TLS keys are no longer functions but static variables.
TLS-related functions are no longer unsafe =)
Merge pull request #21 from sebcrozet/master

Fix TLS keys and safetyness.