diff options
| author | Eli Zaretskii | 2018-09-15 12:21:12 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2018-09-15 12:21:12 +0300 |
| commit | e133b630625d6e5791c8b491c1cf3252cdb97080 (patch) | |
| tree | 60821cda0ecd1ee76e5f5ae044471d48c19a8dfd | |
| parent | cc8f334d2da736be8935f5abae51f7b1f992b343 (diff) | |
| download | emacs-e133b630625d6e5791c8b491c1cf3252cdb97080.tar.gz emacs-e133b630625d6e5791c8b491c1cf3252cdb97080.zip | |
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)
| -rw-r--r-- | src/buffer.c | 24 | ||||
| -rw-r--r-- | test/src/buffer-tests.el | 19 |
2 files changed, 25 insertions, 18 deletions
diff --git a/src/buffer.c b/src/buffer.c index b0cee717036..179360c5622 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -4543,23 +4543,6 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, | |||
| 4543 | Lisp_Object *copy; | 4543 | Lisp_Object *copy; |
| 4544 | ptrdiff_t i; | 4544 | ptrdiff_t i; |
| 4545 | 4545 | ||
| 4546 | if (size) | ||
| 4547 | { | ||
| 4548 | Lisp_Object ovl | ||
| 4549 | = XVECTOR (last_overlay_modification_hooks)->contents[1]; | ||
| 4550 | |||
| 4551 | /* If the buffer of the first overlay in the array doesn't | ||
| 4552 | match the current buffer, then these modification hooks | ||
| 4553 | should not be run in this buffer. This could happen when | ||
| 4554 | some code calls some insdel functions, such as del_range_1, | ||
| 4555 | with the PREPARE argument false -- in that case this | ||
| 4556 | function is never called to record the overlay modification | ||
| 4557 | hook functions in the last_overlay_modification_hooks | ||
| 4558 | array, so anything we find there is not ours. */ | ||
| 4559 | if (XMARKER (OVERLAY_START (ovl))->buffer != current_buffer) | ||
| 4560 | return; | ||
| 4561 | } | ||
| 4562 | |||
| 4563 | USE_SAFE_ALLOCA; | 4546 | USE_SAFE_ALLOCA; |
| 4564 | SAFE_ALLOCA_LISP (copy, size); | 4547 | SAFE_ALLOCA_LISP (copy, size); |
| 4565 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, | 4548 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, |
| @@ -4570,7 +4553,12 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, | |||
| 4570 | Lisp_Object prop_i, overlay_i; | 4553 | Lisp_Object prop_i, overlay_i; |
| 4571 | prop_i = copy[i++]; | 4554 | prop_i = copy[i++]; |
| 4572 | overlay_i = copy[i++]; | 4555 | overlay_i = copy[i++]; |
| 4573 | call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3); | 4556 | /* It is possible that the recorded overlay has been deleted |
| 4557 | (which makes it's markers' buffers be nil), or that (due to | ||
| 4558 | some bug) it belongs to a different buffer. Only run this | ||
| 4559 | hook if the overlay belongs to the current buffer. */ | ||
| 4560 | if (XMARKER (OVERLAY_START (overlay_i))->buffer == current_buffer) | ||
| 4561 | call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3); | ||
| 4574 | } | 4562 | } |
| 4575 | 4563 | ||
| 4576 | SAFE_FREE (); | 4564 | SAFE_FREE (); |
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index f9c477fbfd7..8479bbdda0b 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el | |||
| @@ -45,6 +45,25 @@ with parameters from the *Messages* buffer modification." | |||
| 45 | (should (eq buf (current-buffer)))) | 45 | (should (eq buf (current-buffer)))) |
| 46 | (when msg-ov (delete-overlay msg-ov)))))) | 46 | (when msg-ov (delete-overlay msg-ov)))))) |
| 47 | 47 | ||
| 48 | (ert-deftest overlay-modification-hooks-deleted-overlay () | ||
| 49 | "Test for bug#30823." | ||
| 50 | (let ((check-point nil) | ||
| 51 | (ov-delete nil) | ||
| 52 | (ov-set nil)) | ||
| 53 | (with-temp-buffer | ||
| 54 | (insert "abc") | ||
| 55 | (setq ov-set (make-overlay 1 3)) | ||
| 56 | (overlay-put ov-set 'modification-hooks | ||
| 57 | (list (lambda (_o after &rest _args) | ||
| 58 | (and after (setq check-point t))))) | ||
| 59 | (setq ov-delete (make-overlay 1 3)) | ||
| 60 | (overlay-put ov-delete 'modification-hooks | ||
| 61 | (list (lambda (o after &rest _args) | ||
| 62 | (and (not after) (delete-overlay o))))) | ||
| 63 | (goto-char 2) | ||
| 64 | (insert "1") | ||
| 65 | (should (eq check-point t))))) | ||
| 66 | |||
| 48 | (ert-deftest test-generate-new-buffer-name-bug27966 () | 67 | (ert-deftest test-generate-new-buffer-name-bug27966 () |
| 49 | (should-not (string-equal "nil" | 68 | (should-not (string-equal "nil" |
| 50 | (progn (get-buffer-create "nil") | 69 | (progn (get-buffer-create "nil") |