diff options
| author | Daniel Colascione | 2015-03-02 02:23:09 -0800 |
|---|---|---|
| committer | Daniel Colascione | 2015-03-02 15:39:01 -0800 |
| commit | 9d8d0658147dfe5a90e2fb07ff666f35b1162d6e (patch) | |
| tree | 6d593ab42386348b1842688c75f892db45c5b59e /test | |
| parent | b149ecd8aa3aa9c179dd5496f64e1f50750414fa (diff) | |
| download | emacs-9d8d0658147dfe5a90e2fb07ff666f35b1162d6e.tar.gz emacs-9d8d0658147dfe5a90e2fb07ff666f35b1162d6e.zip | |
Add support for finalizers
+2015-03-02 Daniel Colascione <dancol@dancol.org>
+
+ * NEWS: Mention finalizers.
+
2015-02-09 Gareth Rees <gdr@garethrees.org> (tiny change)
* NEWS.24: Fix typo (bug#19820)
diff --git a/src/ChangeLog b/src/ChangeLog
index 4aa64c1..2f04d0b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,21 @@
+2015-03-02 Daniel Colascione <dancol@dancol.org>
+
+ * print.c (print_object): Print finalizers.
+
+ * alloc.c:
+ (finalizers, doomed_finalizers): New variables.
+ (init_finalizer_list, finalizer_insert, unchain_finalizer)
+ (mark_finalizer_list, queue_doomed_finalizers)
+ (run_finalizer_handler, run_finalizer_function, run_finalizers):
+ New functions.
+ (garbage_collect_1, mark_object, sweep_misc)
+ (init_alloc_once, syms_of_alloc): Support finalizers.
+ (gc-precise-p): New Lisp variable.
+
+ * lisp.h (Lisp_Misc_Type): New value Lisp_Misc_Finalizer.
+ (FINALIZERP, XFINALIZER): New functions.
+ (Lisp_Finalizer): New structure.
+
2015-02-28 Paul Eggert <eggert@cs.ucla.edu>
* character.c (alphabeticp, decimalnump): Avoid undefined behavior
diff --git a/test/ChangeLog b/test/ChangeLog
index cf1b2c1..684e98f 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-02 Daniel Colascione <dancol@dancol.org>
+
+ * automated/finalizer-tests.el (finalizer-basic)
+ (finalizer-circular-reference, finalizer-cross-reference)
+ (finalizer-error): New tests.
+
2015-03-01 Michael Albinus <michael.albinus@gmx.de>
* automated/vc-tests.el (vc-test--create-repo): Add check for
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 6 | ||||
| -rw-r--r-- | test/automated/finalizer-tests.el | 78 |
2 files changed, 84 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index cf1b2c13d7e..684e98f880e 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2015-03-02 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * automated/finalizer-tests.el (finalizer-basic) | ||
| 4 | (finalizer-circular-reference, finalizer-cross-reference) | ||
| 5 | (finalizer-error): New tests. | ||
| 6 | |||
| 1 | 2015-03-01 Michael Albinus <michael.albinus@gmx.de> | 7 | 2015-03-01 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 8 | ||
| 3 | * automated/vc-tests.el (vc-test--create-repo): Add check for | 9 | * automated/vc-tests.el (vc-test--create-repo): Add check for |
diff --git a/test/automated/finalizer-tests.el b/test/automated/finalizer-tests.el new file mode 100644 index 00000000000..5308f01085b --- /dev/null +++ b/test/automated/finalizer-tests.el | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | ;;; finalizer-tests.el --- Finalizer tests -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2015 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Daniel Colascione <dancol@dancol.org> | ||
| 6 | ;; Keywords: | ||
| 7 | |||
| 8 | ;; This program is free software; you can redistribute it and/or modify | ||
| 9 | ;; it under the terms of the GNU General Public License as published by | ||
| 10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 11 | ;; (at your option) any later version. | ||
| 12 | |||
| 13 | ;; This program is distributed in the hope that it will be useful, | ||
| 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | ;; GNU General Public License for more details. | ||
| 17 | |||
| 18 | ;; You should have received a copy of the GNU General Public License | ||
| 19 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | |||
| 21 | ;;; Commentary: | ||
| 22 | |||
| 23 | ;; | ||
| 24 | |||
| 25 | ;;; Code: | ||
| 26 | |||
| 27 | (require 'ert) | ||
| 28 | (require 'cl-lib) | ||
| 29 | |||
| 30 | (ert-deftest finalizer-basic () | ||
| 31 | "Test that finalizers run at all." | ||
| 32 | (skip-unless gc-precise-p) | ||
| 33 | (let* ((finalized nil) | ||
| 34 | (finalizer (make-finalizer (lambda () (setf finalized t))))) | ||
| 35 | (garbage-collect) | ||
| 36 | (should (equal finalized nil)) | ||
| 37 | (setf finalizer nil) | ||
| 38 | (garbage-collect) | ||
| 39 | (should (equal finalized t)))) | ||
| 40 | |||
| 41 | (ert-deftest finalizer-circular-reference () | ||
| 42 | "Test references from a callback to a finalizer." | ||
| 43 | (skip-unless gc-precise-p) | ||
| 44 | (let ((finalized nil)) | ||
| 45 | (let* ((value nil) | ||
| 46 | (finalizer (make-finalizer (lambda () (setf finalized value))))) | ||
| 47 | (setf value finalizer) | ||
| 48 | (setf finalizer nil)) | ||
| 49 | (garbage-collect) | ||
| 50 | (should finalized))) | ||
| 51 | |||
| 52 | (ert-deftest finalizer-cross-reference () | ||
| 53 | "Test that between-finalizer references do not prevent collection." | ||
| 54 | (skip-unless gc-precise-p) | ||
| 55 | (let ((d nil) (fc 0)) | ||
| 56 | (let* ((f1-data (cons nil nil)) | ||
| 57 | (f2-data (cons nil nil)) | ||
| 58 | (f1 (make-finalizer | ||
| 59 | (lambda () (cl-incf fc) (setf d f1-data)))) | ||
| 60 | (f2 (make-finalizer | ||
| 61 | (lambda () (cl-incf fc) (setf d f2-data))))) | ||
| 62 | (setcar f1-data f2) | ||
| 63 | (setcar f2-data f1)) | ||
| 64 | (garbage-collect) | ||
| 65 | (should (equal fc 2)))) | ||
| 66 | |||
| 67 | (ert-deftest finalizer-error () | ||
| 68 | "Test that finalizer errors are suppressed" | ||
| 69 | (skip-unless gc-precise-p) | ||
| 70 | (make-finalizer (lambda () (error "ABCDEF"))) | ||
| 71 | (garbage-collect) | ||
| 72 | (with-current-buffer "*Messages*" | ||
| 73 | (save-excursion | ||
| 74 | (goto-char (point-max)) | ||
| 75 | (forward-line -1) | ||
| 76 | (should (equal | ||
| 77 | (buffer-substring (point) (point-at-eol)) | ||
| 78 | "finalizer failed: (error \"ABCDEF\")"))))) | ||