Subject: bug#41445: 26.3; Query-replace triggers "match data clobbered by..."

From: [email-masked] (Ture Pålsson)
Date: Fri, 22 May 2020 07:07:24 +0200

1. Run macOS (Catalina, in my case, but I don't think it matters.)

2. Have a folder named "ä" (that's a single character, U+00E4)
   and a file in it.

3. Visit that file.

4. While the file is not modified, do a query-replace that will replace
   something.

5. When Emacs asks about the first replacement, type 'y'.

==> You get an error message, "Match data clobbered by buffer
modification hooks".

Setting before-change-functions, after-change-functions, and
first-change-hook all to nil does not make the problem go away.

However, setting inhibit-modification-hooks to t *does* make it go away.

Running Emacs in a debugger, I notice that the first modification of the
buffer calls lock_file, which calls code_convert_string which, through a
long series of Emacs Lisp calls end up calling re-search-forward. I have
not tried to unravel this call chain, but:

The function ucs-normalize-region calls re-search-forward. If I wrap
that call in save-match-data, the problem goes away!

In GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109))
 of 2019-09-02 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.1894
Recent messages:
Mark saved where search started
Mark set

Mark saved where search started
Mark set
Mark saved where search started
Making completion list...
Quit
Auto-saving...
Saving file /Users/ture/Desktop/emacs/lisp/international/ucs-normalize.el...
Wrote /Users/ture/Desktop/emacs/lisp/international/ucs-normalize.el
Quit
Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS

Important settings:
  value of $LC_CTYPE: sv_SE.UTF-8
  value of $LANG: en_SE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  shell-dirtrack-mode: t
  bug-reference-prog-mode: t
  diff-auto-refine-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny format-spec rfc822 mml
mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
completion pulse find-dired semantic/fw xref project dired-aux dired
dired-loaddefs ibuf-ext ibuffer ibuffer-loaddefs loadhist mode-local
find-func apropos shell pcomplete grep compile comint ring bug-reference
map cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs pp cl-print thingatpt help-fns radix-tree
jka-compr info misearch multi-isearch vc-git diff-mode easy-mmode view
elec-pair ansi-color iso-transl cl-extra help-mode cl finder-inf package
easymenu epg-config url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt
gv bytecomp byte-compile cconv cl-loaddefs cl-lib time-date tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
multi-tty make-network-process emacs)

Memory information:
((conses 16 411912 23871)
 (symbols 48 28246 5)
 (miscs 40 341 2088)
 (strings 32 61990 7915)
 (string-bytes 1 1687293)
 (vectors 16 52073)
 (vector-slots 8 1712291 139060)
 (floats 8 71 567)
 (intervals 56 32656 600)
 (buffers 992 37))