Skip to content

Commit

Permalink
Work around ghci linker bug on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Dec 14, 2012
1 parent 9f8a923 commit 5977a21
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cbits/siphash.c
Expand Up @@ -117,13 +117,23 @@ static void maybe_use_sse()

#endif

/* On Windows, ghci's linker fails to call static initializers. */
static inline void ensure_sse_init()
{
#if defined(_WIN32) && defined(__i386)
if (_siphash24 == NULL)
maybe_use_sse();
#endif
}

u64 hashable_siphash(int c, int d, u64 k0, u64 k1, const u8 *str, size_t len)
{
return _siphash(c, d, k0, k1, str, len);
}

u64 hashable_siphash24(u64 k0, u64 k1, const u8 *str, size_t len)
{
ensure_sse_init();
return _siphash24(k0, k1, str, len);
}

Expand All @@ -133,6 +143,7 @@ u64 hashable_siphash24(u64 k0, u64 k1, const u8 *str, size_t len)
u64 hashable_siphash24_offset(u64 k0, u64 k1,
const u8 *str, size_t off, size_t len)
{
ensure_sse_init();
return _siphash24(k0, k1, str + off, len);
}

Expand Down

0 comments on commit 5977a21

Please sign in to comment.