From 42be8aadff18c8b997e65c70541ac2c483bcf80f Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 8 Jul 2016 07:25:30 -0600 Subject: [PATCH] fix collision handling for `eq?`-based immutable hash with `#t`s When creating a collision node, make sure the "has a value" bit is set, since the "has a hash code" bit should imply it. This bug was made easier to trigger by 3fbb384604, but it was potentially a problem for scope sets before. Closes #1366 Merge to v6.6 --- racket/src/racket/src/hash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/racket/src/racket/src/hash.c b/racket/src/racket/src/hash.c index 05ed3e3586..cf2304f49f 100644 --- a/racket/src/racket/src/hash.c +++ b/racket/src/racket/src/hash.c @@ -2414,7 +2414,7 @@ intptr_t scheme_eqv_hash_key2(Scheme_Object *o) /* In a hash tree without HASHTR_HAS_VAL, all values are `#t`; we nodes without HASHTR_HAS_VAL to nodes with it on demand, but we don't go the other way */ -#define NOT_IMPLICIT_VALUE(v) (!SAME_OBJ(v, scheme_true)) +#define NOT_IMPLICIT_VALUE(v) ((v) && !SAME_OBJ(v, scheme_true)) #define HASHTR_SUBTREEP(o) SAME_TYPE(SCHEME_TYPE(o), scheme_hash_tree_subtree_type) #define HASHTR_COLLISIONP(o) SAME_TYPE(SCHEME_TYPE(o), scheme_hash_tree_collision_type) @@ -3340,7 +3340,7 @@ Scheme_Hash_Tree *scheme_hash_tree_set_w_key_wraps(Scheme_Hash_Tree *tree, Schem return tree; else { /* new hash collision */ - in_tree = hamt_make2(SCHEME_HASHTR_KIND(in_tree) | HASHTR_HAS_CODE, 0, + in_tree = hamt_make2(SCHEME_HASHTR_KIND(in_tree) | HASHTR_HAS_VAL | HASHTR_HAS_CODE, 0, 0, in_tree->els[pos], mzHAMT_VAL(in_tree, pos), 1, key, val); in_tree->iso.so.type = scheme_hash_tree_collision_type;