From 3854d5fd235c1c5f4a81e9e967cb3f12af9e6046 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 16 Dec 2010 17:06:52 +0100 Subject: [PATCH] Fix `hash' for pointer objects. Previously all pointer objects would hash to the same value. * libguile/hash.c (scm_hasher): Add case for `scm_tc7_pointer'. --- libguile/hash.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libguile/hash.c b/libguile/hash.c index d2ce57586..78a84a406 100644 --- a/libguile/hash.c +++ b/libguile/hash.c @@ -135,6 +135,17 @@ scm_hasher(SCM obj, unsigned long n, size_t d) } case scm_tc7_symbol: return scm_i_symbol_hash (obj) % n; + case scm_tc7_pointer: + { + /* Pointer objects are typically used to store addresses of heap + objects. On most platforms, these are at least 3-byte + aligned (on x86_64-*-gnu, `malloc' returns 4-byte aligned + addresses), so get rid of the least significant bits. */ + scm_t_uintptr significant_bits; + + significant_bits = (scm_t_uintptr) SCM_POINTER_VALUE (obj) >> 4UL; + return (size_t) significant_bits % n; + } case scm_tc7_wvect: case scm_tc7_vector: { -- 2.20.1