summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-02-05 23:45:21 +0100
committerRichard Braun <rbraun@sceen.net>2017-02-05 23:45:21 +0100
commit628ff302ccec58d9a34d50894a5eb3d05826c342 (patch)
tree9cbb4b80d75b56db78a9f1360588129cf2292d95
parent90d0cce04025f766992b90d760bc5a5abbaa9ca9 (diff)
hash: replace unsigned long with uintptr_t for integer/pointer conversions
-rw-r--r--hash.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/hash.h b/hash.h
index bcd2ecb..215b738 100644
--- a/hash.h
+++ b/hash.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Richard Braun.
+ * Copyright (c) 2010-2017 Richard Braun.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,12 +50,14 @@
#ifndef _HASH_H
#define _HASH_H
+#include <assert.h>
#include <stdint.h>
#ifdef __LP64__
#define HASH_ALLBITS 64
#define hash_long(n, bits) hash_int64(n, bits)
#else /* __LP64__ */
+static_assert(sizeof(long) == 4, "unsupported data model");
#define HASH_ALLBITS 32
#define hash_long(n, bits) hash_int32(n, bits)
#endif
@@ -93,10 +95,14 @@ hash_int64(uint64_t n, unsigned int bits)
return hash >> (64 - bits);
}
-static inline unsigned long
+static inline uintptr_t
hash_ptr(const void *ptr, unsigned int bits)
{
- return hash_long((unsigned long)ptr, bits);
+ if (sizeof(uintptr_t) == 8) {
+ return hash_int64((uintptr_t)ptr, bits);
+ } else {
+ return hash_int32((uintptr_t)ptr, bits);
+ }
}
static inline unsigned long