From: Noam Postavsky <npostavs@gmail.com>
To: 35264@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#35264: "Match data clobbered by buffer modification hooks" when hooks only shifted match-data's markers
Date: Sun, 14 Apr 2019 00:40:13 -0400 [thread overview]
Message-ID: <87h8b119oy.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2366 bytes --]
Version: 27.0.50 26.2 25.3
X-Debbugs-CC: Stefan Monnier <monnier@iro.umontreal.ca>
emacs -Q -l bug-xxxx-match-data-marker-clobber.el
Hit <f12>, gives
Debugger entered--Lisp error: (error "Match data clobbered by buffer modification hooks")
replace-match("ABCDEF" t t)
(let* ((after-change-functions (list (function (lambda (&rest _) (let (... ...) (save-excursion ...))))))) (search-backward "abcdef") (replace-match "ABCDEF" t t))
(save-current-buffer (set-buffer (get-buffer-create "*test*")) (display-buffer (current-buffer)) (erase-buffer) (insert "1234567890\n") (insert "abcdefghilk\n") (make-local-variable (quote after-change-functions)) (let* ((after-change-functions (list (function (lambda (&rest _) (let ... ...)))))) (search-backward "abcdef") (replace-match "ABCDEF" t t)))
bug-match-data-marker-clobber()
funcall-interactively(bug-match-data-marker-clobber)
call-interactively(bug-match-data-marker-clobber nil nil)
command-execute(bug-match-data-marker-clobber)
But the modification hook in question did call save-match-data. As far
as I can tell, the problem is that the match-data consists of markers,
whose position gets shifted by deletion of characters. The check for
this error uses simple integers, so there's no way it can account for
this.
I think this is a variant of Bug#23917, there was some talk there about
removing the check, perhaps that is the right solution.
DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
[...]
/* The functions below modify the buffer, so they could trigger
various modification hooks (see signal_before_change and
signal_after_change). If these hooks clobber the match data we
error out since otherwise this will result in confusing bugs. */
ptrdiff_t sub_start = search_regs.start[sub];
ptrdiff_t sub_end = search_regs.end[sub];
unsigned num_regs = search_regs.num_regs;
newpoint = search_regs.start[sub] + SCHARS (newtext);
/* Replace the old text with the new in the cleanest possible way. */
replace_range (search_regs.start[sub], search_regs.end[sub],
newtext, 1, 0, 1, 1);
[...]
if (search_regs.start[sub] != sub_start
|| search_regs.end[sub] != sub_end
|| search_regs.num_regs != num_regs)
error ("Match data clobbered by buffer modification hooks");
bug-xxxx-match-data-marker-clobber.el:
[-- Attachment #2: bug reproducer --]
[-- Type: text/plain, Size: 1183 bytes --]
(defun bug-match-data-marker-clobber ()
(interactive)
(with-current-buffer (get-buffer-create "*test*")
(display-buffer (current-buffer))
(erase-buffer)
(insert "1234567890\n")
(insert "abcdefghilk\n")
(make-local-variable 'after-change-functions)
(let* ((after-change-functions `
(,(lambda (&rest _)
(let ((inhibit-modification-hooks nil)
(after-change-functions nil))
(save-excursion
(save-match-data
(goto-char (point-min))
(looking-at "[0-9]")
(delete-char 1))
;; match-data is restored, but markers have a
;; different position now, because of the
;; deletion.
;;
;; (match-data) ;=> (#<marker@11> #<marker@17>)
))))))
(search-backward "abcdef")
;; (match-data) ;=> (#<marker@12> #<marker@18>)
(replace-match "ABCDEF" t t) ;; Triggers `after-change-functions'.
)))
(setq debug-on-error t)
(define-key global-map [f12] 'bug-match-data-marker-clobber)
next reply other threads:[~2019-04-14 4:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-14 4:40 Noam Postavsky [this message]
2019-05-30 23:03 ` bug#35264: "Match data clobbered by buffer modification hooks" when hooks only shifted match-data's markers Noam Postavsky
2020-10-02 4:47 ` Lars Ingebrigtsen
2021-05-12 14:35 ` Lars Ingebrigtsen
2021-05-12 14:55 ` Eli Zaretskii
2021-05-12 15:43 ` Lars Ingebrigtsen
2021-05-12 15:48 ` Eli Zaretskii
2021-05-12 15:57 ` Lars Ingebrigtsen
2021-05-12 16:03 ` Eli Zaretskii
2021-05-13 9:11 ` Lars Ingebrigtsen
2021-05-13 10:14 ` Eli Zaretskii
2021-05-13 16:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-13 17:09 ` Eli Zaretskii
2021-05-16 13:20 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h8b119oy.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=35264@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).