diff options
| author | Daniel Colascione | 2015-03-02 19:08:06 -0800 |
|---|---|---|
| committer | Daniel Colascione | 2015-03-02 19:08:06 -0800 |
| commit | 2cc23f170f920cbfc9df4c28bce6ca9d82c4e6cd (patch) | |
| tree | ba2ba78402bf75eed26d3f20abeac5c02eb74694 | |
| parent | 8af3e1848cbdc570b6c173480c2988a552f3f74d (diff) | |
| download | emacs-2cc23f170f920cbfc9df4c28bce6ca9d82c4e6cd.tar.gz emacs-2cc23f170f920cbfc9df4c28bce6ca9d82c4e6cd.zip | |
Finalizer documentation, minor improvements
* doc/lispref/objects.texi (Finalizer Type): New section
(Type Predicates): Mention finalizers in `type-of' documentation.
* doc/lispref/elisp.texi (Top): Link to finalizer type.
* src/data.c (Ftype_of): Make `type-of' work with finalizers.
(syms_of_data): Register Qfinalizer.
* src/print.c (print_object): Print whether a finalizer has
been called.
* test/automated/finalizer-tests.el (finalizer-object-type): Test that
`type-of' works correctly for finalizers.
| -rw-r--r-- | doc/lispref/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/objects.texi | 37 | ||||
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/data.c | 5 | ||||
| -rw-r--r-- | src/print.c | 5 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/automated/finalizer-tests.el | 3 |
8 files changed, 63 insertions, 7 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index e7d79d55c7e..c27805b3d6e 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2015-03-03 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * objects.texi (Finalizer Type): New section for finalizer objects. | ||
| 4 | (Type Predicates): Mention finalizers in `type-of' documentation. | ||
| 5 | * elisp.texi (Top): Link to finalizer type. | ||
| 6 | |||
| 1 | 2015-03-02 Daniel Colascione <dancol@dancol.org> | 7 | 2015-03-02 Daniel Colascione <dancol@dancol.org> |
| 2 | 8 | ||
| 3 | * control.texi (Generators): New section | 9 | * control.texi (Generators): New section |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 3802e49ec3d..fc552be161b 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -316,6 +316,7 @@ Programming Types | |||
| 316 | * Byte-Code Type:: A function written in Lisp, then compiled. | 316 | * Byte-Code Type:: A function written in Lisp, then compiled. |
| 317 | * Autoload Type:: A type used for automatically loading seldom-used | 317 | * Autoload Type:: A type used for automatically loading seldom-used |
| 318 | functions. | 318 | functions. |
| 319 | * Finalizer Type:: Runs code when no longer reachable. | ||
| 319 | 320 | ||
| 320 | Character Type | 321 | Character Type |
| 321 | 322 | ||
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index ba28b63f0de..b28b3b00898 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi | |||
| @@ -156,6 +156,8 @@ latter are unique to Emacs Lisp. | |||
| 156 | * Byte-Code Type:: A function written in Lisp, then compiled. | 156 | * Byte-Code Type:: A function written in Lisp, then compiled. |
| 157 | * Autoload Type:: A type used for automatically loading seldom-used | 157 | * Autoload Type:: A type used for automatically loading seldom-used |
| 158 | functions. | 158 | functions. |
| 159 | * Finalizer Type:: Runs code when no longer reachable. | ||
| 160 | |||
| 159 | @end menu | 161 | @end menu |
| 160 | 162 | ||
| 161 | @node Integer Type | 163 | @node Integer Type |
| @@ -1361,6 +1363,31 @@ in the loaded file. | |||
| 1361 | @code{autoload}, which stores the object in the function cell of a | 1363 | @code{autoload}, which stores the object in the function cell of a |
| 1362 | symbol. @xref{Autoload}, for more details. | 1364 | symbol. @xref{Autoload}, for more details. |
| 1363 | 1365 | ||
| 1366 | @node Finalizer Type | ||
| 1367 | @subsection Finalizer Type | ||
| 1368 | |||
| 1369 | A @dfn{finalizer object} helps Lisp code clean up after objects that | ||
| 1370 | are no longer needed. A finalizer holds a Lisp function object. | ||
| 1371 | When a finalizer object becomes unreachable after a garbage collection | ||
| 1372 | pass, Emacs calls the finalizer's associated function object. | ||
| 1373 | When deciding whether a finalizer is reachable, Emacs does not count | ||
| 1374 | references from finalizer objects themselves, allowing you to use | ||
| 1375 | finalizers without having to worry about accidentally capturing | ||
| 1376 | references to finalized objects themselves. | ||
| 1377 | |||
| 1378 | Errors in finalizers are printed to @code{*Messages*}. Emacs runs | ||
| 1379 | a given finalizer object's associated function exactly once, even | ||
| 1380 | if that function fails. | ||
| 1381 | |||
| 1382 | @defun make-finalizer function | ||
| 1383 | Make a finalizer that will run @var{function}. @var{function} will be | ||
| 1384 | called after garbage collection when the returned finalizer object | ||
| 1385 | becomes unreachable. If the finalizer object is reachable only | ||
| 1386 | through references from finalizer objects, it does not count as | ||
| 1387 | reachable for the purpose of deciding whether to run @var{function}. | ||
| 1388 | @var{function} will be run once per finalizer object. | ||
| 1389 | @end defun | ||
| 1390 | |||
| 1364 | @node Editing Types | 1391 | @node Editing Types |
| 1365 | @section Editing Types | 1392 | @section Editing Types |
| 1366 | @cindex editing types | 1393 | @cindex editing types |
| @@ -1907,11 +1934,11 @@ types. In most cases, it is more convenient to use type predicates than | |||
| 1907 | This function returns a symbol naming the primitive type of | 1934 | This function returns a symbol naming the primitive type of |
| 1908 | @var{object}. The value is one of the symbols @code{bool-vector}, | 1935 | @var{object}. The value is one of the symbols @code{bool-vector}, |
| 1909 | @code{buffer}, @code{char-table}, @code{compiled-function}, | 1936 | @code{buffer}, @code{char-table}, @code{compiled-function}, |
| 1910 | @code{cons}, @code{float}, @code{font-entity}, @code{font-object}, | 1937 | @code{cons}, @code{finalizer}, @code{float}, @code{font-entity}, |
| 1911 | @code{font-spec}, @code{frame}, @code{hash-table}, @code{integer}, | 1938 | @code{font-object}, @code{font-spec}, @code{frame}, @code{hash-table}, |
| 1912 | @code{marker}, @code{overlay}, @code{process}, @code{string}, | 1939 | @code{integer}, @code{marker}, @code{overlay}, @code{process}, |
| 1913 | @code{subr}, @code{symbol}, @code{vector}, @code{window}, or | 1940 | @code{string}, @code{subr}, @code{symbol}, @code{vector}, |
| 1914 | @code{window-configuration}. | 1941 | @code{window}, or @code{window-configuration}. |
| 1915 | 1942 | ||
| 1916 | @example | 1943 | @example |
| 1917 | (type-of 1) | 1944 | (type-of 1) |
diff --git a/src/ChangeLog b/src/ChangeLog index 2f04d0b040a..930a33b277a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2015-03-03 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * print.c (print_object): Print whether a finalizer has | ||
| 4 | been called. | ||
| 5 | |||
| 6 | * data.c (Ftype_of): Make `type-of' work with finalizers. | ||
| 7 | (syms_of_data): Register Qfinalizer. | ||
| 8 | |||
| 1 | 2015-03-02 Daniel Colascione <dancol@dancol.org> | 9 | 2015-03-02 Daniel Colascione <dancol@dancol.org> |
| 2 | 10 | ||
| 3 | * print.c (print_object): Print finalizers. | 11 | * print.c (print_object): Print finalizers. |
diff --git a/src/data.c b/src/data.c index 47706584f5e..c96841aebbf 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -223,7 +223,9 @@ for example, (type-of 1) returns `integer'. */) | |||
| 223 | case Lisp_Misc_Overlay: | 223 | case Lisp_Misc_Overlay: |
| 224 | return Qoverlay; | 224 | return Qoverlay; |
| 225 | case Lisp_Misc_Float: | 225 | case Lisp_Misc_Float: |
| 226 | return Qfloat; | 226 | return Qfloat; |
| 227 | case Lisp_Misc_Finalizer: | ||
| 228 | return Qfinalizer; | ||
| 227 | } | 229 | } |
| 228 | emacs_abort (); | 230 | emacs_abort (); |
| 229 | 231 | ||
| @@ -3547,6 +3549,7 @@ syms_of_data (void) | |||
| 3547 | DEFSYM (Qcons, "cons"); | 3549 | DEFSYM (Qcons, "cons"); |
| 3548 | DEFSYM (Qmarker, "marker"); | 3550 | DEFSYM (Qmarker, "marker"); |
| 3549 | DEFSYM (Qoverlay, "overlay"); | 3551 | DEFSYM (Qoverlay, "overlay"); |
| 3552 | DEFSYM (Qfinalizer, "finalizer"); | ||
| 3550 | DEFSYM (Qfloat, "float"); | 3553 | DEFSYM (Qfloat, "float"); |
| 3551 | DEFSYM (Qwindow_configuration, "window-configuration"); | 3554 | DEFSYM (Qwindow_configuration, "window-configuration"); |
| 3552 | DEFSYM (Qprocess, "process"); | 3555 | DEFSYM (Qprocess, "process"); |
diff --git a/src/print.c b/src/print.c index d391fd5f7a3..838d03666d4 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -2046,7 +2046,10 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) | |||
| 2046 | break; | 2046 | break; |
| 2047 | 2047 | ||
| 2048 | case Lisp_Misc_Finalizer: | 2048 | case Lisp_Misc_Finalizer: |
| 2049 | strout ("#<finalizer>", -1, -1, printcharfun); | 2049 | strout ("#<finalizer", -1, -1, printcharfun); |
| 2050 | if (NILP (XFINALIZER (obj)->function)) | ||
| 2051 | strout (" used", -1, -1, printcharfun); | ||
| 2052 | strout (">", -1, -1, printcharfun); | ||
| 2050 | break; | 2053 | break; |
| 2051 | 2054 | ||
| 2052 | /* Remaining cases shouldn't happen in normal usage, but let's | 2055 | /* Remaining cases shouldn't happen in normal usage, but let's |
diff --git a/test/ChangeLog b/test/ChangeLog index 64ad85198af..3a311e97aa5 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2015-03-03 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * automated/finalizer-tests.el (finalizer-object-type): Test that | ||
| 4 | `type-of' works correctly for finalizers. | ||
| 5 | |||
| 1 | 2015-03-02 Daniel Colascione <dancol@dancol.org> | 6 | 2015-03-02 Daniel Colascione <dancol@dancol.org> |
| 2 | 7 | ||
| 3 | * automated/generator-tests.el: New tests | 8 | * automated/generator-tests.el: New tests |
diff --git a/test/automated/finalizer-tests.el b/test/automated/finalizer-tests.el index 5308f01085b..4746dbea9b7 100644 --- a/test/automated/finalizer-tests.el +++ b/test/automated/finalizer-tests.el | |||
| @@ -76,3 +76,6 @@ | |||
| 76 | (should (equal | 76 | (should (equal |
| 77 | (buffer-substring (point) (point-at-eol)) | 77 | (buffer-substring (point) (point-at-eol)) |
| 78 | "finalizer failed: (error \"ABCDEF\")"))))) | 78 | "finalizer failed: (error \"ABCDEF\")"))))) |
| 79 | |||
| 80 | (ert-deftest finalizer-object-type () | ||
| 81 | (should (equal (type-of (make-finalizer nil)) 'finalizer))) | ||