Commit e133b630 authored by Eli Zaretskii's avatar Eli Zaretskii

Avoid adverse side effects of fixing bug#21824

* test/src/buffer-tests.el
(overlay-modification-hooks-deleted-overlay): New test.

* src/buffer.c (report_overlay_modification): Don't bypass all
the overlay-modification hooks; instead, invoke each function
only if the buffer associated with the overlay is the current
buffer.  (Bug#30823)
parent cc8f334d
......@@ -4543,23 +4543,6 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after,
Lisp_Object *copy;
ptrdiff_t i;
if (size)
{
Lisp_Object ovl
= XVECTOR (last_overlay_modification_hooks)->contents[1];
/* If the buffer of the first overlay in the array doesn't
match the current buffer, then these modification hooks
should not be run in this buffer. This could happen when
some code calls some insdel functions, such as del_range_1,
with the PREPARE argument false -- in that case this
function is never called to record the overlay modification
hook functions in the last_overlay_modification_hooks
array, so anything we find there is not ours. */
if (XMARKER (OVERLAY_START (ovl))->buffer != current_buffer)
return;
}
USE_SAFE_ALLOCA;
SAFE_ALLOCA_LISP (copy, size);
memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
......@@ -4570,7 +4553,12 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after,
Lisp_Object prop_i, overlay_i;
prop_i = copy[i++];
overlay_i = copy[i++];
call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3);
/* It is possible that the recorded overlay has been deleted
(which makes it's markers' buffers be nil), or that (due to
some bug) it belongs to a different buffer. Only run this
hook if the overlay belongs to the current buffer. */
if (XMARKER (OVERLAY_START (overlay_i))->buffer == current_buffer)
call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3);
}
SAFE_FREE ();
......
......@@ -45,6 +45,25 @@ with parameters from the *Messages* buffer modification."
(should (eq buf (current-buffer))))
(when msg-ov (delete-overlay msg-ov))))))
(ert-deftest overlay-modification-hooks-deleted-overlay ()
"Test for bug#30823."
(let ((check-point nil)
(ov-delete nil)
(ov-set nil))
(with-temp-buffer
(insert "abc")
(setq ov-set (make-overlay 1 3))
(overlay-put ov-set 'modification-hooks
(list (lambda (_o after &rest _args)
(and after (setq check-point t)))))
(setq ov-delete (make-overlay 1 3))
(overlay-put ov-delete 'modification-hooks
(list (lambda (o after &rest _args)
(and (not after) (delete-overlay o)))))
(goto-char 2)
(insert "1")
(should (eq check-point t)))))
(ert-deftest test-generate-new-buffer-name-bug27966 ()
(should-not (string-equal "nil"
(progn (get-buffer-create "nil")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment