Subject: bug#73752: 29.4; Ligatures are randomly rendered with extra spaces

From: Visuwesh <[email-masked]>
Date: Sat, 02 Nov 2024 18:59:03 +0530

[சனி நவம்பர் 02, 2024] Eli Zaretskii wrote:

>> But just loading a file that contains
>> 
>>     (set-face-attribute 'default nil
>>                 :family "Cascadia Code"
>>                 :height 110
>>                 :weight 'bold)
>> 
>>     (load "/tmp/ligature.el")
>> 
>>     (ligature-set-ligatures 'prog-mode '("--" "---" "==" "===" "!=" "!==" "=!="
>>                                          "=:=" "=/=" "<=" ">=" "&&" "&&&" "&=" "++" "+++" "***" ";;" "!!"
>>                                          "??" "???" "?:" "?." "?=" "<:" ":<" ":>" ">:" "<:<" "<>" "<<<" ">>>"
>>                                          "<<" ">>" "||" "-|" "_|_" "|-" "||-" "|=" "||=" "##" "###" "####"
>>                                          "#{" "#[" "]#" "#(" "#?" "#_" "#_(" "#:" "#!" "#=" "^=" "<$>" "<$"
>>                                          "$>" "<+>" "<+" "+>" "<*>" "<*" "*>" "</" "</>" "/>" "<!--" "<#--"
>>                                          "-->" "->" "->>" "<<-" "<-" "<=<" "=<<" "<<=" "<==" "<=>" "<==>"
>>                                          "==>" "=>" "=>>" ">=>" ">>=" ">>-" ">-" "-<" "-<<" ">->" "<-<" "<-|"
>>                                          "<=|" "|=>" "|->" "<->" "<~~" "<~" "<~>" "~~" "~~>" "~>" "~-" "-~"
>>                                          "~@" "[||]" "|]" "[|" "|}" "{|" "[<" ">]" "|>" "<|" "||>" "<||"
>>                                          "|||>" "<|||" "<|>" "..." ".." ".=" "..<" ".?" "::" ":::" ":=" "::="
>>                                          ":?" ":?>" "//" "///" "/*" "*/" "/=" "//=" "/==" "@_" "__" "???"
>>                                          "<:<" ";;;"))
>>     (global-ligature-mode t)
>> 
>> was enough to trigger the breakpoint for me.  This is, of course, before
>> I got a chance to even reproduce the misalignment.
>> 
>> Here's what the gdb buffer looks like:
>> 
>>     (gdb) source .gdbinit
>>     SIGINT is used by the debugger.
>>     Are you sure you want to change it? (y or n) [answered Y; input not from terminal]
>>     DISPLAY = :0.0
>>     TERM = dumb
>>     Breakpoint 1 at 0x20b4b7: file emacs.c, line 432.
>>     Breakpoint 2 at 0x1cfa8a: file xterm.c, line 27102.
>>     (gdb) break hbfont.c:598 if xoff == 0 && yoff == 0 && wadjust == metrics.width && LGLYPH_ADJUSTMENT(lglyph) != Qnil
>>     Breakpoint 3 at 0x3c3ad7: file hbfont.c, line 598.
>>     (gdb) run -Q
>>     Starting program: /home/viz/lib/ports/emacs/src/emacs -Q
>>     [Thread debugging using libthread_db enabled]
>>     Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
>>     [New Thread 0x7ffff1b8f6c0 (LWP 198125)]
>>     [New Thread 0x7ffff118f6c0 (LWP 198126)]
>>     [New Thread 0x7fffebf8f6c0 (LWP 198127)]
>>     [New Thread 0x7fffeb58f6c0 (LWP 198128)]
>>     Error in testing condition for breakpoint 3:
>>     Attempt to take address of value not located in memory.
>> 
>>     Thread 1 "emacs" hit Breakpoint 3, hbfont_shape (lgstring=XIL(0x7ffff2a9c745), direction=XIL(0x33c0)) at hbfont.c:598
>>     598	      if (xoff || yoff || wadjust != metrics.width)
>
> Good.  Now please do this:
>
>   (gdb) pp lgstring
>   (gdb) p wadjust
>   (gdb) p metrics.width
>   (gdb) bt
>
> And post the results here.

    (gdb) pp lgstring
    [[#<font-object "-SAJA-Cascadia Code-bold-normal-normal-*-15-*-*-*-m-0-iso10646-1"> 59 59] nil [0 0 59 1935 9 4 14 8 4 nil] [1 1 59 1865 9 2 6 8 4 nil] nil nil nil nil nil nil]
    (gdb) p wadjust
    $1 = 9
    (gdb) p metrics.width
    $2 = 9
    (gdb) bt
    #0  hbfont_shape (lgstring=XIL(0x7ffff2a9c745), direction=XIL(0x33c0)) at hbfont.c:598
    #1  0x00005555558795a7 in Ffont_shape_gstring (gstring=XIL(0x7ffff2a9c745), direction=XIL(0x33c0)) at font.c:4617
    #2  0x000055555584b330 in funcall_subr (subr=0x5555560333a0 <Sfont_shape_gstring>, numargs=2, args=0x7ffff1c00070) at eval.c:3149
    #3  0x00005555558a95f3 in exec_byte_code (fun=XIL(0x7ffff2934d8d), args_template=1542, nargs=6, args=0x7fffffff6d68) at bytecode.c:813
    #4  0x000055555584b978 in funcall_lambda (fun=XIL(0x7ffff2934d8d), nargs=6, arg_vector=0x7fffffff6d38) at eval.c:3238
    #5  0x000055555584ad18 in funcall_general (fun=XIL(0x7ffff2934d8d), numargs=6, args=0x7fffffff6d38) at eval.c:3030
    #6  0x000055555584afd9 in Ffuncall (nargs=7, args=0x7fffffff6d30) at eval.c:3079
    #7  0x00005555558473bc in internal_condition_case_n (bfun=0x55555584ae63 <Ffuncall>, nargs=7, args=0x7fffffff6d30, handlers=XIL(0x30), hfun=0x55555584b059 <safe_eval_handler>) at eval.c:1687
    #8  0x000055555584b117 in safe_funcall (nargs=7, args=0x7fffffff6d30) at eval.c:3107
    #9  0x00005555558f1047 in autocmp_chars (rule=XIL(0x5555561300ed), charpos=1, bytepos=1, limit=3, win=0x55555628c3f8, face=0x5555566b7780, string=XIL(0), direction=XIL(0x33c0), ch=59) at composite.c:979
    #10 0x00005555558f1fb3 in composition_reseat_it (cmp_it=0x7fffffff8e80, charpos=1, bytepos=1, endpos=148, w=0x55555628c3f8, bidi_level=0 '\000', face=0x5555566b7780, string=XIL(0)) at composite.c:1346
    #11 0x00005555555ea807 in next_element_from_buffer (it=0x7fffffff85c0) at xdisp.c:9808
    #12 0x00005555555e6324 in get_next_display_element (it=0x7fffffff85c0) at xdisp.c:8306
    #13 0x0000555555620630 in display_line (it=0x7fffffff85c0, cursor_vpos=3) at xdisp.c:25443
    #14 0x0000555555610972 in try_window (window=XIL(0x55555628c3fd), pos=..., flags=1) at xdisp.c:21261
    #15 0x000055555560d30b in redisplay_window (window=XIL(0x55555628c3fd), just_this_one_p=false) at xdisp.c:20641
    #16 0x0000555555603eea in redisplay_window_0 (window=XIL(0x55555628c3fd)) at xdisp.c:18124
    #17 0x00005555558471d8 in internal_condition_case_1 (bfun=0x555555603ea8 <redisplay_window_0>, arg=XIL(0x55555628c3fd), handlers=XIL(0x7ffff2a75de3), hfun=0x555555603d85 <redisplay_window_error>) at eval.c:1631
    #18 0x0000555555603d57 in redisplay_windows (window=XIL(0x55555628c3fd)) at xdisp.c:18093
    #19 0x0000555555602430 in redisplay_internal () at xdisp.c:17492
    #20 0x00005555555fff75 in redisplay () at xdisp.c:16667
    #21 0x000055555576bffb in read_char (commandflag=1, map=XIL(0x7ffff5109073), prev_event=XIL(0), used_mouse_menu=0x7fffffffdcaf, end_time=0x0) at keyboard.c:2673
    #22 0x0000555555780075 in read_key_sequence (keybuf=0x7fffffffde60, prompt=XIL(0), dont_downcase_last=false, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=false, disable_text_conversion_p=false) at keyboard.c:10747
    #23 0x0000555555768380 in command_loop_1 () at keyboard.c:1424
    #24 0x00005555558470f7 in internal_condition_case (bfun=0x555555767f51 <command_loop_1>, handlers=XIL(0x90), hfun=0x5555557673d2 <cmd_error>) at eval.c:1607
    #25 0x0000555555767b18 in command_loop_2 (handlers=XIL(0x90)) at keyboard.c:1163
    #26 0x000055555584654d in internal_catch (tag=XIL(0x12330), func=0x555555767aee <command_loop_2>, arg=XIL(0x90)) at eval.c:1286
    #27 0x0000555555767aaa in command_loop () at keyboard.c:1141
    #28 0x0000555555766e74 in recursive_edit_1 () at keyboard.c:749
    #29 0x00005555557670a0 in Frecursive_edit () at keyboard.c:832
    #30 0x0000555555762937 in main (argc=2, argv=0x7fffffffe498) at emacs.c:2625

    Lisp Backtrace:
    "font-shape-gstring" (0xf1c00070)
    "auto-compose-chars" (0xffff6d38)
    "redisplay_internal (C function)" (0x0)