Subject: bug#77942: 31.0.50; replace-region-contents gets stuck

From: Gerd Möllmann <[email-masked]>
Date: Sun, 20 Apr 2025 17:28:51 +0200

To reproduce with emacs -Q, define this function

(defun elb-replace-region-contents-entry ()
  (with-temp-buffer
    (let ((step (apply #'concat (make-list 2000 "🙂été👶🏿 "))))
      (dotimes (_ (/ 10000000 (length step)))
        (insert step)))

    (dotimes (_ 100)
      (let* ((a (1+ (random (point-max))))
	     (b (1+ (random (point-max))))
	     (beg (min a b))
	     (end (max a b)))
	(replace-region-contents beg end "🙂été👶🏿 🙂été👶🏿 ")))))

and evaluate

  /elb-replace-region-contents-entry)

This enters an (infinite?) loop that cannot be interrupted with C-g in
the GUI version. If started with -nw, C-g eventually crashes Emacs,
without printing anything on stdout or stderr.

In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin24.4.0, NS
 appkit-2575.50 Version 15.4.1 (Build 24E263)) of 2025-04-20 built on
 pro2
Repository revision: 6fb2a4691f4d53473c0a326d3a6c23df9008b6e8
Repository branch: master
System Description:  macOS 15.4.1

Configured using:
 'configure --cache-file
 /var/folders/1d/k_6t25f94sl83szqbf8gpkrh0000gn/T//config.cache.master
 --enable-checking=yes --with-native-compilation=no CC=clang
 'CFLAGS=-Wgnu-imaginary-constant -Wunused-result -g -g -O0 -F
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 -Wno-ignored-attributes -Wno-flag-enum -Wno-missing-method-return-type
 -Wno-variadic-macros -Wno-strict-prototypes -Wno-availability
 -Wno-nullability-completeness''

Configured features:
ACL DBUS GLIB GNUTLS LCMS2 LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER PNG
RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM ZLIB

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