summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2018-03-23 11:29:06 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2018-03-23 11:29:06 -0400
commit3ddff080341580eb6fc18d907181e9cc2301f62d (patch)
tree935d45325c27bea24ea660b83b50fa308bc6421a /src/buffer.c
parentcf3164523b32f01dbaad2c1364ecf2dcf8f22aa5 (diff)
downloademacs-3ddff080341580eb6fc18d907181e9cc2301f62d.tar.gz
Fix bug#30846, along with misc cleanups found along the way
* test/src/data-tests.el (data-tests-kill-all-local-variables): New test. * src/buffer.c (swap_out_buffer_local_variables): Remove. Fuse the body of its loop into that of reset_buffer_local_variables. (Fkill_buffer, Fkill_all_local_variables): Don't call it any more. (reset_buffer_local_variables): Make sure the buffer's local binding is swapped out before removing it from the alist (bug#30846). Call watchers before actually killing the var. * src/data.c (Fmake_local_variable): Simplify. Use swap_in_global_binding to swap out any local binding, instead of a mix of find_symbol_value followed by messing with where&found. Don't call swap_in_symval_forwarding since the currently swapped binding is never one we've modified. (Fkill_local_variable): Use swap_in_global_binding rather than messing with where&found to try and trick find_symbol_value into doing the same. * src/alloc.c (mark_localized_symbol): 'where' can't be a frame any more.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f8c57a74b4e..14837372d34 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -108,7 +108,6 @@ int last_per_buffer_idx;
static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
bool after, Lisp_Object arg1,
Lisp_Object arg2, Lisp_Object arg3);
-static void swap_out_buffer_local_variables (struct buffer *b);
static void reset_buffer_local_variables (struct buffer *, bool);
/* Alist of all buffer names vs the buffers. This used to be
@@ -991,10 +990,29 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
else
{
Lisp_Object tmp, last = Qnil;
+ Lisp_Object buffer;
+ XSETBUFFER (buffer, b);
+
for (tmp = BVAR (b, local_var_alist); CONSP (tmp); tmp = XCDR (tmp))
{
Lisp_Object local_var = XCAR (XCAR (tmp));
Lisp_Object prop = Fget (local_var, Qpermanent_local);
+ Lisp_Object sym = local_var;
+
+ /* Watchers are run *before* modifying the var. */
+ if (XSYMBOL (local_var)->u.s.trapped_write == SYMBOL_TRAPPED_WRITE)
+ notify_variable_watchers (local_var, Qnil,
+ Qmakunbound, Fcurrent_buffer ());
+
+ eassert (XSYMBOL (sym)->u.s.redirect == SYMBOL_LOCALIZED);
+ /* Need not do anything if some other buffer's binding is
+ now cached. */
+ if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer))
+ {
+ /* Symbol is set up for this buffer's old local value:
+ swap it out! */
+ swap_in_global_binding (XSYMBOL (sym));
+ }
if (!NILP (prop))
{
@@ -1034,10 +1052,6 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
bset_local_var_alist (b, XCDR (tmp));
else
XSETCDR (last, XCDR (tmp));
-
- if (XSYMBOL (local_var)->u.s.trapped_write == SYMBOL_TRAPPED_WRITE)
- notify_variable_watchers (local_var, Qnil,
- Qmakunbound, Fcurrent_buffer ());
}
}
@@ -1867,7 +1881,6 @@ cleaning up all windows currently displaying the buffer to be killed. */)
won't be protected from GC. They would be protected
if they happened to remain cached in their symbols.
This gets rid of them for certain. */
- swap_out_buffer_local_variables (b);
reset_buffer_local_variables (b, 1);
bset_name (b, Qnil);
@@ -2737,11 +2750,6 @@ the normal hook `change-major-mode-hook'. */)
{
run_hook (Qchange_major_mode_hook);
- /* Make sure none of the bindings in local_var_alist
- remain swapped in, in their symbols. */
-
- swap_out_buffer_local_variables (current_buffer);
-
/* Actually eliminate all local bindings of this buffer. */
reset_buffer_local_variables (current_buffer, 0);
@@ -2753,31 +2761,6 @@ the normal hook `change-major-mode-hook'. */)
return Qnil;
}
-/* Make sure no local variables remain set up with buffer B
- for their current values. */
-
-static void
-swap_out_buffer_local_variables (struct buffer *b)
-{
- Lisp_Object oalist, alist, buffer;
-
- XSETBUFFER (buffer, b);
- oalist = BVAR (b, local_var_alist);
-
- for (alist = oalist; CONSP (alist); alist = XCDR (alist))
- {
- Lisp_Object sym = XCAR (XCAR (alist));
- eassert (XSYMBOL (sym)->u.s.redirect == SYMBOL_LOCALIZED);
- /* Need not do anything if some other buffer's binding is
- now cached. */
- if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer))
- {
- /* Symbol is set up for this buffer's old local value:
- swap it out! */
- swap_in_global_binding (XSYMBOL (sym));
- }
- }
-}
/* Find all the overlays in the current buffer that contain position POS.
Return the number found, and store them in a vector in *VEC_PTR.