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 /src/lisp.h | |
| 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 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lisp.h b/src/lisp.h index fb436776121..37f3b28242b 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -488,6 +488,7 @@ enum Lisp_Misc_Type | |||
| 488 | Lisp_Misc_Marker, | 488 | Lisp_Misc_Marker, |
| 489 | Lisp_Misc_Overlay, | 489 | Lisp_Misc_Overlay, |
| 490 | Lisp_Misc_Save_Value, | 490 | Lisp_Misc_Save_Value, |
| 491 | Lisp_Misc_Finalizer, | ||
| 491 | /* Currently floats are not a misc type, | 492 | /* Currently floats are not a misc type, |
| 492 | but let's define this in case we want to change that. */ | 493 | but let's define this in case we want to change that. */ |
| 493 | Lisp_Misc_Float, | 494 | Lisp_Misc_Float, |
| @@ -600,6 +601,7 @@ INLINE bool OVERLAYP (Lisp_Object); | |||
| 600 | INLINE bool PROCESSP (Lisp_Object); | 601 | INLINE bool PROCESSP (Lisp_Object); |
| 601 | INLINE bool PSEUDOVECTORP (Lisp_Object, int); | 602 | INLINE bool PSEUDOVECTORP (Lisp_Object, int); |
| 602 | INLINE bool SAVE_VALUEP (Lisp_Object); | 603 | INLINE bool SAVE_VALUEP (Lisp_Object); |
| 604 | INLINE bool FINALIZERP (Lisp_Object); | ||
| 603 | INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, | 605 | INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, |
| 604 | Lisp_Object); | 606 | Lisp_Object); |
| 605 | INLINE bool STRINGP (Lisp_Object); | 607 | INLINE bool STRINGP (Lisp_Object); |
| @@ -610,6 +612,7 @@ INLINE bool (VECTORLIKEP) (Lisp_Object); | |||
| 610 | INLINE bool WINDOWP (Lisp_Object); | 612 | INLINE bool WINDOWP (Lisp_Object); |
| 611 | INLINE bool TERMINALP (Lisp_Object); | 613 | INLINE bool TERMINALP (Lisp_Object); |
| 612 | INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object); | 614 | INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object); |
| 615 | INLINE struct Lisp_Finalizer *XFINALIZER (Lisp_Object); | ||
| 613 | INLINE struct Lisp_Symbol *(XSYMBOL) (Lisp_Object); | 616 | INLINE struct Lisp_Symbol *(XSYMBOL) (Lisp_Object); |
| 614 | INLINE void *(XUNTAG) (Lisp_Object, int); | 617 | INLINE void *(XUNTAG) (Lisp_Object, int); |
| 615 | 618 | ||
| @@ -2183,6 +2186,21 @@ XSAVE_OBJECT (Lisp_Object obj, int n) | |||
| 2183 | return XSAVE_VALUE (obj)->data[n].object; | 2186 | return XSAVE_VALUE (obj)->data[n].object; |
| 2184 | } | 2187 | } |
| 2185 | 2188 | ||
| 2189 | /* A finalizer sentinel. We run FUNCTION when this value becomes | ||
| 2190 | unreachable. We treat these values specially in the GC to ensure | ||
| 2191 | that we still run the finalizer even if FUNCTION contains a | ||
| 2192 | reference to the finalizer; i.e., we run a finalizer's function | ||
| 2193 | when FUNCTION is reachable _only_ through finalizers. */ | ||
| 2194 | struct Lisp_Finalizer | ||
| 2195 | { | ||
| 2196 | struct Lisp_Misc_Any base; | ||
| 2197 | /* Circular list of all active weak references */ | ||
| 2198 | struct Lisp_Finalizer *prev; | ||
| 2199 | struct Lisp_Finalizer *next; | ||
| 2200 | /* Called when this object becomes unreachable */ | ||
| 2201 | Lisp_Object function; | ||
| 2202 | }; | ||
| 2203 | |||
| 2186 | /* A miscellaneous object, when it's on the free list. */ | 2204 | /* A miscellaneous object, when it's on the free list. */ |
| 2187 | struct Lisp_Free | 2205 | struct Lisp_Free |
| 2188 | { | 2206 | { |
| @@ -2202,6 +2220,7 @@ union Lisp_Misc | |||
| 2202 | struct Lisp_Marker u_marker; | 2220 | struct Lisp_Marker u_marker; |
| 2203 | struct Lisp_Overlay u_overlay; | 2221 | struct Lisp_Overlay u_overlay; |
| 2204 | struct Lisp_Save_Value u_save_value; | 2222 | struct Lisp_Save_Value u_save_value; |
| 2223 | struct Lisp_Finalizer u_finalizer; | ||
| 2205 | }; | 2224 | }; |
| 2206 | 2225 | ||
| 2207 | INLINE union Lisp_Misc * | 2226 | INLINE union Lisp_Misc * |
| @@ -2243,6 +2262,14 @@ XSAVE_VALUE (Lisp_Object a) | |||
| 2243 | eassert (SAVE_VALUEP (a)); | 2262 | eassert (SAVE_VALUEP (a)); |
| 2244 | return & XMISC (a)->u_save_value; | 2263 | return & XMISC (a)->u_save_value; |
| 2245 | } | 2264 | } |
| 2265 | |||
| 2266 | INLINE struct Lisp_Finalizer * | ||
| 2267 | XFINALIZER (Lisp_Object a) | ||
| 2268 | { | ||
| 2269 | eassert (FINALIZERP (a)); | ||
| 2270 | return & XMISC (a)->u_finalizer; | ||
| 2271 | } | ||
| 2272 | |||
| 2246 | 2273 | ||
| 2247 | /* Forwarding pointer to an int variable. | 2274 | /* Forwarding pointer to an int variable. |
| 2248 | This is allowed only in the value cell of a symbol, | 2275 | This is allowed only in the value cell of a symbol, |
| @@ -2490,6 +2517,12 @@ SAVE_VALUEP (Lisp_Object x) | |||
| 2490 | } | 2517 | } |
| 2491 | 2518 | ||
| 2492 | INLINE bool | 2519 | INLINE bool |
| 2520 | FINALIZERP (Lisp_Object x) | ||
| 2521 | { | ||
| 2522 | return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Finalizer; | ||
| 2523 | } | ||
| 2524 | |||
| 2525 | INLINE bool | ||
| 2493 | AUTOLOADP (Lisp_Object x) | 2526 | AUTOLOADP (Lisp_Object x) |
| 2494 | { | 2527 | { |
| 2495 | return CONSP (x) && EQ (Qautoload, XCAR (x)); | 2528 | return CONSP (x) && EQ (Qautoload, XCAR (x)); |