1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-20 18:50:21 +02:00

fix hash-set! on weak tables

* test-suite/tests/weaks.test: Add tests.
* libguile/hashtab.c (scm_hash_fn_set_x): Fix updates to weak-value hash
  tables to not deadlock inside the alloc lock.
This commit is contained in:
Andy Wingo 2011-06-16 12:06:43 +02:00
parent 589bc528bd
commit 636c99d42d
2 changed files with 55 additions and 24 deletions

View file

@ -1,5 +1,5 @@
;;;; weaks.test --- tests guile's weaks -*- scheme -*-
;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010 Free Software Foundation, Inc.
;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@ -208,6 +208,30 @@
(hash-ref z test-key)
#t))))
(pass-if "hash-set!, weak val, im -> im"
(let ((t (make-weak-value-hash-table)))
(hash-set! t "foo" 1)
(hash-set! t "foo" 2)
(equal? (hash-ref t "foo") 2)))
(pass-if "hash-set!, weak val, im -> nim"
(let ((t (make-weak-value-hash-table)))
(hash-set! t "foo" 1)
(hash-set! t "foo" "baz")
(equal? (hash-ref t "foo") "baz")))
(pass-if "hash-set!, weak val, nim -> nim"
(let ((t (make-weak-value-hash-table)))
(hash-set! t "foo" "bar")
(hash-set! t "foo" "baz")
(equal? (hash-ref t "foo") "baz")))
(pass-if "hash-set!, weak val, nim -> im"
(let ((t (make-weak-value-hash-table)))
(hash-set! t "foo" "bar")
(hash-set! t "foo" 1)
(equal? (hash-ref t "foo") 1)))
(pass-if "assoc can do anything"
;; Until 1.9.12, as hash table's custom ASSOC procedure was
;; called with the GC lock alloc held, which imposed severe