1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-14 15:40:19 +02:00

Fix weak-value hash tables.

* libguile/hashtab.c (scm_hash_fn_set_x): Register a disappearing link
  to VAL when TABLE is weak-value.

* test-suite/tests/weaks.test ("weak-hash")["weak-key dies", "weak-value
  dies", "doubly-weak dies"]: Use `hash-set!' and `hash-ref', not
  `hashq-set!' and `hashq-ref', otherwise these tests would always
  succeed because (eq? "this" "this") => #f.
  ["lives"]: Use `hash-ref' and `hash-set!' too for consistency.
This commit is contained in:
Ludovic Courtès 2010-09-23 11:51:28 +02:00
parent cb2d8076ef
commit 5a99a574e4
2 changed files with 62 additions and 50 deletions

View file

@ -623,6 +623,13 @@ scm_hash_fn_set_x (SCM table, SCM obj, SCM val,
it = scm_hash_fn_create_handle_x (table, obj, SCM_BOOL_F, hash_fn, assoc_fn, closure);
SCM_SETCDR (it, val);
if (SCM_HASHTABLE_P (table) && SCM_HASHTABLE_WEAK_VALUE_P (table)
&& SCM_NIMP (val))
/* IT is a weak-cdr pair. Register a disappearing link from IT's
cdr to VAL like `scm_weak_cdr_pair' does. */
SCM_I_REGISTER_DISAPPEARING_LINK ((void *) SCM_CDRLOC (it), SCM2PTR (val));
return val;
}