Commit | Line | Data |
---|---|---|
53a53bd7 | 1 | ;;;; gc.test --- test guile's garbage collection -*- scheme -*- |
6e7d5622 | 2 | ;;;; Copyright (C) 2000, 2001, 2004, 2006 Free Software Foundation, Inc. |
53a53bd7 | 3 | ;;;; |
73be1d9e MV |
4 | ;;;; This library is free software; you can redistribute it and/or |
5 | ;;;; modify it under the terms of the GNU Lesser General Public | |
6 | ;;;; License as published by the Free Software Foundation; either | |
7 | ;;;; version 2.1 of the License, or (at your option) any later version. | |
8 | ;;;; | |
9 | ;;;; This library is distributed in the hope that it will be useful, | |
53a53bd7 | 10 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
11 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | ;;;; Lesser General Public License for more details. | |
13 | ;;;; | |
14 | ;;;; You should have received a copy of the GNU Lesser General Public | |
15 | ;;;; License along with this library; if not, write to the Free Software | |
92205699 | 16 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
53a53bd7 | 17 | |
155c14a0 KR |
18 | (use-modules (ice-9 documentation) |
19 | (test-suite lib)) | |
53a53bd7 DH |
20 | |
21 | ||
22 | ;;; | |
23 | ;;; miscellaneous | |
24 | ;;; | |
25 | ||
26 | ||
27 | (define (documented? object) | |
5c96bc39 | 28 | (not (not (object-documentation object)))) |
53a53bd7 | 29 | |
155c14a0 KR |
30 | ;; In guile 1.6.4 this test bombed, due to the record in h being collected |
31 | ;; by the gc, but not removed from h, leaving "x" as a freed cell. | |
32 | ;; The usual correct result here is for x to be #f, but there's always a | |
33 | ;; chance gc will mark something used when it isn't, so we allow x to be a | |
34 | ;; record too. | |
35 | (pass-if "weak-values versus records" | |
36 | (let ((rec-type (make-record-type "foo" '())) | |
37 | (h (make-weak-value-hash-table 61))) | |
38 | (hash-set! h "foo" ((record-constructor rec-type))) | |
39 | (gc) | |
40 | (let ((x (hash-ref h "foo"))) | |
41 | (or (not x) | |
42 | ((record-predicate rec-type) x))))) | |
43 | ||
53a53bd7 DH |
44 | |
45 | ;;; | |
46 | ;;; | |
47 | ;;; | |
48 | ||
49 | (with-test-prefix "gc" | |
50 | ||
51 | (pass-if "after-gc-hook gets called" | |
52 | (let* ((foo #f) | |
53 | (thunk (lambda () (set! foo #t)))) | |
54 | (add-hook! after-gc-hook thunk) | |
55 | (gc) | |
56 | (remove-hook! after-gc-hook thunk) | |
57 | foo))) | |
e4da0740 HWN |
58 | |
59 | ||
60 | (with-test-prefix "gc" | |
61 | (pass-if "Unused modules are removed" | |
62 | (let* | |
63 | ((dummy (gc)) | |
64 | (last-count (cdr (assoc | |
65 | "eval-closure" (gc-live-object-stats))))) | |
66 | ||
67 | (for-each (lambda (x) (make-module)) (iota 1000)) | |
68 | (gc) | |
69 | (gc) ;; twice: have to kill the weak vectors. | |
70 | (= last-count (cdr (assoc "eval-closure" (gc-live-object-stats))))) | |
71 | )) |