summaryrefslogtreecommitdiff
path: root/libguile/hashtab.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-09-23 11:51:28 +0200
committerLudovic Courtès <ludo@gnu.org>2010-09-23 22:02:11 +0200
commit5a99a574e43a08817f21bdeebe1c302051ffb237 (patch)
treec4ca87956c543979881552854de8c9999ca9e88f /libguile/hashtab.c
parentcb2d8076effd1b3f0a01a7148af5a97b64f4c29d (diff)
downloadguile-5a99a574e43a08817f21bdeebe1c302051ffb237.tar.gz
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.
Diffstat (limited to 'libguile/hashtab.c')
-rw-r--r--libguile/hashtab.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libguile/hashtab.c b/libguile/hashtab.c
index 9cb75f234..78a265ded 100644
--- a/libguile/hashtab.c
+++ b/libguile/hashtab.c
@@ -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;
}