5 tmpcore
=$TEST_FILESTEM.core
7 # Regression test for https://bugs.launchpad.net/sbcl/+bug/1857920
8 # saving a finalizer would crash you into ldb.
9 # (Sadly, saved finalizers mean nothing to gencgc since it will never
10 # actually free the object which the finalizer watches)
13 (defvar *x* (cons 1 2))
14 (finalize *x* (lambda () (print 'ran)))
15 (save-lisp-and-die "$tmpcore" :executable t)
18 .
/"$tmpcore" --disable-ldb --no-userinit --no-sysinit --noprint
19 echo "Saved finalizer smoke test: PASS"
21 # Assert that >1 finalizer on an object are correctly saved/restored.
24 (defun a () (print 1))
25 (defun b () (print 2))
26 (defun c () (print 3))
28 (finalize *x* #'b :dont-save t)
30 (save-lisp-and-die "$tmpcore")
32 # this would crash in finalizers-reinit
33 run_sbcl_with_core
"$tmpcore" --noinform --disable-ldb --no-userinit --no-sysinit --noprint <<EOF
34 (sb-sys:with-pinned-objects (*x*)
35 (let ((list (sb-lockless:so-data
36 (sb-lockless:so-find sb-impl::**finalizer-store**
37 (sb-kernel:%make-lisp-obj
38 (logandc2 (sb-kernel:get-lisp-obj-address *x*)
39 sb-vm:lowtag-mask))))))
40 (assert (= (length list) 2))
41 (assert (find #'a list))
42 (assert (find #'c list))))
45 echo "One obj, three finalizers: PASS"
47 # Assert that :DONT-SAVE finalizers which were triggered during the DEINITIALIZE flow
48 # and placed in the triggered list do not act as though they were saved.
49 # i.e. They're ineligible for running on restart, but also - as a design choice -
50 # not run during saving of the core even when the object died.
52 (progn (sb-ext:finalize (make-array 1) (lambda () (format t "RAN~%")) :dont-save t) nil)
53 (save-lisp-and-die "$tmpcore" :executable t)
55 result
=`./"$tmpcore" --disable-ldb --no-userinit --no-sysinit --noprint \
56 --eval '(sleep .0125)' --eval '(quit)'`
57 if [ "x$result" = "x" ]
59 echo "Triggered DONT-SAVE finalizer: PASS"
61 echo "Triggered DONT-SAVE finalizer: FAIL"