Subject: Re: bug#61514: 30.0.50; sadistically long xml line hangs emacs

From: Eli Zaretskii <[email-masked]>
Date: Mon, 20 Feb 2023 14:41:17 +0200

> Cc: [email-masked]
> Date: Sun, 19 Feb 2023 18:38:52 -0500
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> > After this, Emacs appears to hang and nothing else is displayed.
> 
> That's a second and separate bug (tho probably triggered by the first).
> These tend to be nastier to diagnose.

What happens here that causes the "hang" is clear: the problematic
regexp is used in a looking-at call that is called via
fontification-functions, so its being pathologically slow wedges
redisplay.  The backtrace is below:

  #2  0x0121ccc0 in re_match_2_internal (bufp=0x19c5a50 <searchbufs+5744>,
      string1=0x83207d0 "<id name=\"", 'n' <repeats 4193280 times>, "\">\n",
      size1=0,
      string2=0x83207d0 "<id name=\"", 'n' <repeats 4193280 times>, "\">\n",
      size2=250000, pos=10, regs=0x1870074 <main_thread+116>, stop=250000)
      at regex-emacs.c:4581
  #3  0x0121b22e in rpl_re_match_2 (bufp=0x19c5a50 <searchbufs+5744>,
      string1=0x83207d0 "<id name=\"", 'n' <repeats 4193280 times>, "\">\n",
      size1=0,
      string2=0x83207d0 "<id name=\"", 'n' <repeats 4193280 times>, "\">\n",
      size2=250000, pos=10, regs=0x1870074 <main_thread+116>, stop=250000)
      at regex-emacs.c:3861
  #4  0x01208bba in looking_at_1 (string=XIL(0x8000000007a39ed8), posix=false,
      modify_data=true) at search.c:314
  #5  0x01208db4 in Flooking_at (regexp=XIL(0x8000000007a39ed8),
      inhibit_modify=XIL(0)) at search.c:350
  #6  0x01279aad in funcall_subr (subr=0x187b8c0 <Slooking_at>, numargs=1,
      args=0x6c40448) at eval.c:3036
  #7  0x012ec2be in exec_byte_code (fun=XIL(0xa000000006c10520),
      args_template=769, nargs=2, args=0x6c40458) at bytecode.c:809
  #8  0x0127a046 in fetch_and_exec_byte_code (fun=XIL(0xa000000007ea04f8),
      args_template=257, nargs=1, args=0x6c401c8) at eval.c:3081
  #9  0x0127a5a5 in funcall_lambda (fun=XIL(0xa000000007ea04f8), nargs=1,
      arg_vector=0x6c401c8) at eval.c:3153
  #10 0x01279512 in funcall_general (fun=XIL(0xa000000007ea04f8), numargs=1,
      args=0x6c401c8) at eval.c:2945
  #11 0x01279897 in Ffuncall (nargs=2, args=0x6c401c0) at eval.c:2995
  #12 0x0127895a in run_hook_wrapped_funcall (nargs=2, args=0x6c401c0)
      at eval.c:2773
  #13 0x01278e11 in run_hook_with_args (nargs=2, args=0x6c401c0,
      funcall=0x1278912 <run_hook_wrapped_funcall>) at eval.c:2854
  #14 0x012789a9 in Frun_hook_wrapped (nargs=2, args=0x6c401c0) at eval.c:2788
  #15 0x01279ef7 in funcall_subr (subr=0x187ff80 <Srun_hook_wrapped>,
      numargs=2, args=0x6c401c0) at eval.c:3059
  #16 0x012ec2be in exec_byte_code (fun=XIL(0xa00000000615096c),
      args_template=514, nargs=2, args=0x6c400f8) at bytecode.c:809
  #17 0x0127a046 in fetch_and_exec_byte_code (fun=XIL(0xa00000000615043c),
      args_template=257, nargs=1, args=0x82ac08) at eval.c:3081
  #18 0x0127a5a5 in funcall_lambda (fun=XIL(0xa00000000615043c), nargs=1,
      arg_vector=0x82ac08) at eval.c:3153
  #19 0x01279512 in funcall_general (fun=XIL(0xa00000000615043c), numargs=1,
      args=0x82ac08) at eval.c:2945
  #20 0x01279897 in Ffuncall (nargs=2, args=0x82ac00) at eval.c:2995
  #21 0x0127394d in internal_condition_case_n (bfun=0x127974b <Ffuncall>,
      nargs=2, args=0x82ac00, handlers=XIL(0x30),
      hfun=0x10428ae <safe_eval_handler>) at eval.c:1558
  #22 0x01042ae1 in safe__call (inhibit_quit=false, nargs=2,
      func=XIL(0x477df6c), ap=0x82acc4 "") at xdisp.c:3024
  #23 0x01042b5a in safe_call (nargs=2, func=XIL(0x477df6c)) at xdisp.c:3039
  #24 0x01042bae in safe_call1 (fn=XIL(0x477df6c), arg=make_fixnum(1))
      at xdisp.c:3050
  #25 0x01046b6a in handle_fontified_prop (it=0x82af58) at xdisp.c:4445
  #26 0x0104554e in handle_stop (it=0x82af58) at xdisp.c:3978
  #27 0x01052103 in reseat (it=0x82af58, pos=..., force_p=true) at xdisp.c:7509
  #28 0x010444d5 in init_iterator (it=0x82af58, w=0x7967568, charpos=1,
      bytepos=1, row=0x7adeaf0, base_face_id=DEFAULT_FACE_ID) at xdisp.c:3488
  #29 0x0104484d in start_display (it=0x82af58, w=0x7967568, pos=...)
      at xdisp.c:3595
  #30 0x0107ccaa in try_window (window=XIL(0xa000000007967568), pos=...,
      flags=1) at xdisp.c:20568
  #31 0x01079885 in redisplay_window (window=XIL(0xa000000007967568),
      just_this_one_p=false) at xdisp.c:19960
  #32 0x01070924 in redisplay_window_0 (window=XIL(0xa000000007967568))
      at xdisp.c:17446
  #33 0x0127373a in internal_condition_case_1 (
      bfun=0x10708cc <redisplay_window_0>, arg=XIL(0xa000000007967568),
      handlers=XIL(0xc00000000648471c), hfun=0x107058e <redisplay_window_error>)
      at eval.c:1498
  #34 0x01070550 in redisplay_windows (window=XIL(0xa000000007967568))
      at xdisp.c:17416
  #35 0x0106ed14 in redisplay_internal () at xdisp.c:16866
  #36 0x0106c42e in redisplay () at xdisp.c:16049
  #37 0x0117570b in read_char (commandflag=1, map=XIL(0xc000000007e4f0f0),
      prev_event=XIL(0), used_mouse_menu=0x82f41f, end_time=0x0)
      at keyboard.c:2627
  #38 0x0118f671 in read_key_sequence (keybuf=0x82f6f8, prompt=XIL(0),
      dont_downcase_last=false, can_return_switch_frame=true,
      fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:10074
  #39 0x01170cf9 in command_loop_1 () at keyboard.c:1375
  #40 0x01273650 in internal_condition_case (bfun=0x1170698 <command_loop_1>,
      handlers=XIL(0x90), hfun=0x116f666 <cmd_error>) at eval.c:1474
  #41 0x01170105 in command_loop_2 (handlers=XIL(0x90)) at keyboard.c:1124
  #42 0x012724d7 in internal_catch (tag=XIL(0x10380),
      func=0x11700ce <command_loop_2>, arg=XIL(0x90)) at eval.c:1197
  #43 0x01170070 in command_loop () at keyboard.c:1102
  #44 0x0116f0c6 in recursive_edit_1 () at keyboard.c:711
  #45 0x0116f364 in Frecursive_edit () at keyboard.c:794
  #46 0x0116a10e in main (argc=2, argv=0xa428e0) at emacs.c:2529

  Lisp Backtrace:
  "looking-at" (0x6c40448)
  "xmltok-scan-attributes" (0x6c403f0)
  "xmltok-scan-after-lt" (0x6c403b8)
  "xmltok-forward" (0x6c40388)
  "nxml-tokenize-forward" (0x6c40350)
  "nxml-extend-region" (0x6c40308)
  "font-lock-default-fontify-region" (0x6c40298)
  "font-lock-fontify-region" (0x6c40230)
  0x7ea04f8 PVEC_COMPILED
  "run-hook-wrapped" (0x6c401c0)
  "jit-lock--run-functions" (0x6c400e8)
  "jit-lock-fontify-now" (0x6c40058)
  "jit-lock-function" (0x82ac08)
  "redisplay_internal (C function)" (0x0)