1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 14:30:34 +02:00

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'.
This commit is contained in:
Ludovic Courtès 2010-12-16 17:06:52 +01:00
parent 183f784947
commit 3854d5fd23

View file

@ -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:
{