GNU bug report logs - #23386
Segfault when messing with font-backend

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Date: Wed, 27 Apr 2016 13:14:01 UTC

Severity: normal

Tags: confirmed

Merged with 35803, 36835, 39865

Found in versions 25.0.95, 28.0.50, 25.0.50, 24.1, 24.5, 26.2, 27.0.50

Fixed in version 27.1

Done: Robert Pluim <rpluim <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23386 in the body.
You can then email your comments to 23386 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Wed, 27 Apr 2016 13:14:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 27 Apr 2016 13:14:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: bug-gnu-emacs <at> gnu.org
Subject: Segfault when messing with font-backend
Date: Wed, 27 Apr 2016 09:13:30 -0400
Package: Emacs
Version: 25.0.50


If I do

    % emacs -Q --eval "(push '(font-backend x) default-frame-alist)"

I get a segfault.  This is with the latest emacs-25.
See the backtrace below.


        Stefan


Program received signal SIGSEGV, Segmentation fault.
0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
(gdb) xbacktrace
(gdb) bt
#0  0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
#1  0x082d4d69 in xftfont_encode_char (font=0x8779b00, c=92) at xftfont.c:537
#2  0x08074145 in get_char_glyph_code (c=<optimized out>, 
    font=font <at> entry=0x8779b00, char2b=char2b <at> entry=0xffffbbbe)
    at xdisp.c:24681
#3  0x080bdbfd in x_produce_glyphs (it=0xffffbc08) at xdisp.c:27011
#4  0x0807d80c in produce_special_glyphs (it=it <at> entry=0xffffc718, 
    what=what <at> entry=IT_CONTINUATION) at xdisp.c:26643
#5  0x0809bcd6 in init_iterator (it=<optimized out>, w=<optimized out>, 
    charpos=<optimized out>, bytepos=<optimized out>, row=<optimized out>, 
    base_face_id=<optimized out>) at xdisp.c:2856
#6  0x080b0bb4 in resize_mini_window (w=0x8852930, exact_p=true)
    at xdisp.c:10970
#7  0x080b0fa9 in resize_mini_window_1 (a1=142944560, exactly=...)
    at xdisp.c:10912
#8  0x080828d4 in with_echo_area_buffer (w=0x8852930, which=which <at> entry=0, 
    fn=fn <at> entry=0x80b0f91 <resize_mini_window_1>, a1=142944560, a2=...)
    at xdisp.c:10642
#9  0x080b7082 in resize_echo_area_exactly () at xdisp.c:10890
#10 0x081ad0d6 in command_loop_1 () at keyboard.c:1274
#11 0x0823977d in internal_condition_case (bfun=0x81ad053 <command_loop_1>, 
    handlers=..., hfun=0x819da9e <cmd_error>) at eval.c:1309
#12 0x081963cd in command_loop_2 (ignore=...) at keyboard.c:1099
#13 0x082396f4 in internal_catch (tag=..., func=0x81963ac <command_loop_2>, 
    arg=...) at eval.c:1074
#14 0x0819635c in command_loop () at keyboard.c:1078
#15 0x0819d535 in recursive_edit_1 () at keyboard.c:684
#16 0x0819d9b9 in Frecursive_edit () at keyboard.c:755
#17 0x08195adc in main (argc=<optimized out>, argv=0xffffd514) at emacs.c:1605
(gdb) 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Wed, 27 Apr 2016 14:04:02 GMT) Full text and rfc822 format available.

Message #8 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Wed, 27 Apr 2016 17:02:38 +0300
> From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
> Date: Wed, 27 Apr 2016 09:13:30 -0400
> 
> If I do
> 
>     % emacs -Q --eval "(push '(font-backend x) default-frame-alist)"
> 
> I get a segfault.  This is with the latest emacs-25.

Not reproducible here, but then I cannot run an X version.  (I did try
an equivalent for Windows; it didn't crash.)

> See the backtrace below.
> 
> 
>         Stefan
> 
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
> (gdb) xbacktrace
> (gdb) bt
> #0  0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
> #1  0x082d4d69 in xftfont_encode_char (font=0x8779b00, c=92) at xftfont.c:537

Can you tell which arguments to XftCharIndex were invalid in this
case?

Also, is 'x' a valid font-backend symbol?  It's strange that Emacs
uses xftfont when it should have been using xfont instead (AFAIU).
But I'm far from being an expert in this area.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Wed, 27 Apr 2016 14:23:02 GMT) Full text and rfc822 format available.

Message #11 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Wed, 27 Apr 2016 10:23:00 -0400
>> % emacs -Q --eval "(push '(font-backend x) default-frame-alist)"
>> I get a segfault.  This is with the latest emacs-25.
> Not reproducible here, but then I cannot run an X version.  (I did try
> an equivalent for Windows; it didn't crash.)

Not surprised: it seems specific to the X11 code.

>> Program received signal SIGSEGV, Segmentation fault.
>> 0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
>> (gdb) xbacktrace
>> (gdb) bt
>> #0  0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
>> #1  0x082d4d69 in xftfont_encode_char (font=0x8779b00, c=92) at xftfont.c:537
> Can you tell which arguments to XftCharIndex were invalid in this
> case?

I guess it's the second arg (xftfont_info->xftfont), which is NULL.

    Program received signal SIGSEGV, Segmentation fault.
    0xf70b3b36 in XftCharIndex () from /usr/lib/i386-linux-gnu/libXft.so.2
    (gdb) up
    #1  0x082d4d69 in xftfont_encode_char (font=0x8779af0, c=92) at xftfont.c:537
    (gdb) p xftfont_info->display
    $1 = (Display *) 0x86f2368
    (gdb) p xftfont_info->xftfont
    $2 = (XftFont *) 0x0
    (gdb) p c
    $3 = 92
    (gdb)

> Also, is 'x' a valid font-backend symbol?

AFAIK yes.

> It's strange that Emacs uses xftfont when it should have been using
> xfont instead (AFAIU).

Indeed, that seems to be a big part of the problem.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sat, 09 Jul 2016 19:12:01 GMT) Full text and rfc822 format available.

Message #14 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sat, 09 Jul 2016 15:11:42 -0400
[Message part 1 (text/plain, inline)]
found 23386 24.1
found 23386 24.5
found 23386 25.0.95
tags 23386 confirmed
quit

- Emacs versions 24.1, 24.2, 24.4, 24.5 all segfault this case.
- Emacs versions 23.4 and 24.3 don't segfault, but the first frame
  shows boxes for the characters in the modeline, and still seems to
  be using the Xft font in the initial frame (subsequently created
  frames use a font from the X backend).

In all cases this error is triggerred on startup:
"frame-notice-user-settings: Font `-PfEd-DejaVu Sans
Mono-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1' is not defined",
although only in the latter case is Emacs able to display it, otherwise
it segfaults first.

AFAICT, this it's the same bug in all versions, some happen not to
segfault by accident.

The segfault happens when using font with

  (font->driver == &xftfont_driver) &&
  ((struct xftfont_info *)font)->xftfont == NULL

Passing NULL xftfont to Xft library triggers a segfault.

The way we end up with this kind of bad font object, is that
x_set_font_backend calls font_update_drivers which eventually calls
xftfont_close which sets the xftfont field of the frame's font to NULL,
but the frame still refers to this closed object.  The chosen font is
not updated, because it's set in the frame-parameters, so when
x_set_font_backend tries to honour this choice, it gets the error "Font
... is not defined" mentioned above (the font was defined only for the
xft backend, not the remaining x backend), and leaves the invalid font
object as the frame's default font.

Here is a patch that attempts to fix the issue by resetting the font
after the backend is changed.  It does let Emacs successfully open the
frame with the new font (no funny box characters in the modeline), but
I'm not sure if it's the best way of marking the font object invalid.

[v1-0001-Don-t-segfault-on-font-backend-change-Bug-23386.patch (text/x-diff, inline)]
From 190e70acf940ad7678812e069e74fce93668a8a8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sat, 9 Jul 2016 14:20:53 -0400
Subject: [PATCH v1] Don't segfault on font backend change (Bug #23386)

* src/font.c (font_finish_cache): Kill frame's font if it used the
driver we just turned off.
* src/frame.c (x_set_font_backend): Reset the frame's font if it's been
killed.
---
 src/font.c  |  7 +++++++
 src/frame.c | 16 ++++++++++++++--
 src/frame.h |  1 +
 src/xfns.c  |  2 +-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/font.c b/src/font.c
index 2519599..e48b566 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2587,6 +2587,13 @@ font_finish_cache (struct frame *f, struct font_driver *driver)
       font_clear_cache (f, XCAR (val), driver);
       XSETCDR (cache, XCDR (val));
     }
+
+  if (FRAME_FONT (f)->driver == driver)
+    {
+      /* Don't leave the frame's font pointing to a closed driver. */
+      store_frame_param(f, Qfont, Qnil);
+      FRAME_FONT (f) = NULL;
+    }
 }
 
 
diff --git a/src/frame.c b/src/frame.c
index 00f25f7..d7454d9 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3677,6 +3677,8 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 void
 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
+  Lisp_Object frame;
+
   if (! NILP (new_value)
       && !CONSP (new_value))
     {
@@ -3718,11 +3720,21 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
     }
   store_frame_param (f, Qfont_backend, new_value);
 
+  XSETFRAME (frame, f);
+
+  /* If closing the font driver killed the frame's font, we need to
+     get a new one.  */
+  if (!FRAME_FONT (f))
+    x_default_font_parameter (f, Fframe_parameters (frame));
+  if (!FRAME_FONT (f))
+    {
+      delete_frame (frame, Qnoelisp);
+      error ("Invalid frame font");
+    }
+
   if (FRAME_FONT (f))
     {
-      Lisp_Object frame;
 
-      XSETFRAME (frame, f);
       x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
       face_change = true;
       windows_or_buffers_changed = 18;
diff --git a/src/frame.h b/src/frame.h
index f0cdcd4..5b5349e 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1356,6 +1356,7 @@ extern void x_set_scroll_bar_default_height (struct frame *);
 extern void x_set_offset (struct frame *, int, int, int);
 extern void x_wm_set_size_hint (struct frame *f, long flags, bool user_position);
 extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
+extern void x_default_font_parameter (struct frame *f, Lisp_Object parms);
 extern void x_set_frame_parameters (struct frame *, Lisp_Object);
 extern void x_set_fullscreen (struct frame *, Lisp_Object, Lisp_Object);
 extern void x_set_line_spacing (struct frame *, Lisp_Object, Lisp_Object);
diff --git a/src/xfns.c b/src/xfns.c
index 7c1bb1c..1b9dd48 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3071,7 +3071,7 @@ do_unwind_create_frame (Lisp_Object frame)
   unwind_create_frame (frame);
 }
 
-static void
+void
 x_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
-- 
2.8.0


bug Marked as found in versions 24.1. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 09 Jul 2016 19:12:02 GMT) Full text and rfc822 format available.

bug Marked as found in versions 24.5. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 09 Jul 2016 19:12:02 GMT) Full text and rfc822 format available.

bug Marked as found in versions 25.0.95. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 09 Jul 2016 19:12:02 GMT) Full text and rfc822 format available.

Added tag(s) confirmed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 09 Jul 2016 19:12:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sat, 09 Jul 2016 20:03:02 GMT) Full text and rfc822 format available.

Message #25 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sat, 09 Jul 2016 16:02:30 -0400
npostavs <at> users.sourceforge.net writes:

> Here is a patch that attempts to fix the issue by resetting the font
> after the backend is changed.  It does let Emacs successfully open the
> frame with the new font (no funny box characters in the modeline), but
> I'm not sure if it's the best way of marking the font object invalid.

Definitely not the best way: it causes segfault on delete-frame.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sun, 10 Jul 2016 14:19:02 GMT) Full text and rfc822 format available.

Message #28 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: npostavs <at> users.sourceforge.net
Cc: monnier <at> IRO.UMontreal.CA, 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sun, 10 Jul 2016 17:18:02 +0300
> From: npostavs <at> users.sourceforge.net
> Cc: 23386 <at> debbugs.gnu.org,  Eli Zaretskii <eliz <at> gnu.org>
> Date: Sat, 09 Jul 2016 16:02:30 -0400
> 
> > Here is a patch that attempts to fix the issue by resetting the font
> > after the backend is changed.  It does let Emacs successfully open the
> > frame with the new font (no funny box characters in the modeline), but
> > I'm not sure if it's the best way of marking the font object invalid.
> 
> Definitely not the best way: it causes segfault on delete-frame.

Backtrace from that segfault?

I think one idea that could be useful is to trace the creation of
relevant objects when Emacs starts up, starting with the call to
font_update_drivers, and then compare that with what happens in this
case.  That could delineate the missing parts and the differences
which could point the way to solving this cleanly.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sun, 10 Jul 2016 17:31:02 GMT) Full text and rfc822 format available.

Message #31 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Antipov <dmantipov <at> yandex.ru>
To: npostavs <at> users.sourceforge.net, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sun, 10 Jul 2016 20:29:59 +0300
On 07/09/2016 10:11 PM, npostavs <at> users.sourceforge.net wrote:

> Here is a patch that attempts to fix the issue by resetting the font
> after the backend is changed.  It does let Emacs successfully open the
> frame with the new font (no funny box characters in the modeline), but
> I'm not sure if it's the best way of marking the font object invalid.

IMHO the original trick (request to drop font backend when there is a font
opened by using this backend) is practically meaningless, so why just not
prohibit it explicitly? For example, with:

diff --git a/src/frame.c b/src/frame.c
index 22143ab..d8f89ed 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3708,7 +3708,19 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
     return;

   if (FRAME_FONT (f))
-    free_all_realized_faces (Qnil);
+    {
+      if (!NILP (new_value))
+	{
+	  Lisp_Object backend = FRAME_FONT (f)->props[FONT_TYPE_INDEX];
+
+	  /* Do not release the backend used by F's default font.  */
+	  if (NILP (Fmemq (backend, new_value)))
+	    error ("Font backend '%s' is in use by font '%s'",
+		   SDATA (SYMBOL_NAME (backend)),
+		   SDATA (FRAME_FONT (f)->props[FONT_NAME_INDEX]));
+	}
+      free_all_realized_faces (Qnil);
+    }

   new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
   if (NILP (new_value))

Dmitry




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sun, 10 Jul 2016 20:16:02 GMT) Full text and rfc822 format available.

Message #34 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23386 <at> debbugs.gnu.org, monnier <at> IRO.UMontreal.CA
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sun, 10 Jul 2016 16:15:07 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: npostavs <at> users.sourceforge.net
>> Cc: 23386 <at> debbugs.gnu.org,  Eli Zaretskii <eliz <at> gnu.org>
>> Date: Sat, 09 Jul 2016 16:02:30 -0400
>> 
>> > Here is a patch that attempts to fix the issue by resetting the font
>> > after the backend is changed.  It does let Emacs successfully open the
>> > frame with the new font (no funny box characters in the modeline), but
>> > I'm not sure if it's the best way of marking the font object invalid.
>> 
>> Definitely not the best way: it causes segfault on delete-frame.
>
> Backtrace from that segfault?

Hmm, looks like I just tried to kill the font twice, adding a NULL check
fixes it.

[v2-0001-Don-t-segfault-on-font-backend-change-Bug-23386.patch (text/x-diff, inline)]
From f405410bf424b0a24a0eac54d12eeed758af95e9 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sat, 9 Jul 2016 14:20:53 -0400
Subject: [PATCH v2] Don't segfault on font backend change (Bug #23386)

* src/font.c (font_finish_cache): Kill frame's font if it used the
driver we just turned off.
* src/frame.c (x_set_font_backend): Reset the frame's font if it's been
killed.
---
 src/font.c  |  7 +++++++
 src/frame.c | 16 ++++++++++++++--
 src/frame.h |  1 +
 src/xfns.c  |  2 +-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/font.c b/src/font.c
index 2519599..21eb95a 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2587,6 +2587,13 @@ font_finish_cache (struct frame *f, struct font_driver *driver)
       font_clear_cache (f, XCAR (val), driver);
       XSETCDR (cache, XCDR (val));
     }
+
+  if (FRAME_FONT (f) && FRAME_FONT (f)->driver == driver)
+    {
+      /* Don't leave the frame's font pointing to a closed driver. */
+      store_frame_param(f, Qfont, Qnil);
+      FRAME_FONT (f) = NULL;
+    }
 }
 
 
diff --git a/src/frame.c b/src/frame.c
index 00f25f7..d7454d9 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3677,6 +3677,8 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 void
 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
+  Lisp_Object frame;
+
   if (! NILP (new_value)
       && !CONSP (new_value))
     {
@@ -3718,11 +3720,21 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
     }
   store_frame_param (f, Qfont_backend, new_value);
 
+  XSETFRAME (frame, f);
+
+  /* If closing the font driver killed the frame's font, we need to
+     get a new one.  */
+  if (!FRAME_FONT (f))
+    x_default_font_parameter (f, Fframe_parameters (frame));
+  if (!FRAME_FONT (f))
+    {
+      delete_frame (frame, Qnoelisp);
+      error ("Invalid frame font");
+    }
+
   if (FRAME_FONT (f))
     {
-      Lisp_Object frame;
 
-      XSETFRAME (frame, f);
       x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
       face_change = true;
       windows_or_buffers_changed = 18;
diff --git a/src/frame.h b/src/frame.h
index f0cdcd4..5b5349e 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1356,6 +1356,7 @@ extern void x_set_scroll_bar_default_height (struct frame *);
 extern void x_set_offset (struct frame *, int, int, int);
 extern void x_wm_set_size_hint (struct frame *f, long flags, bool user_position);
 extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
+extern void x_default_font_parameter (struct frame *f, Lisp_Object parms);
 extern void x_set_frame_parameters (struct frame *, Lisp_Object);
 extern void x_set_fullscreen (struct frame *, Lisp_Object, Lisp_Object);
 extern void x_set_line_spacing (struct frame *, Lisp_Object, Lisp_Object);
diff --git a/src/xfns.c b/src/xfns.c
index 7c1bb1c..1b9dd48 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3071,7 +3071,7 @@ do_unwind_create_frame (Lisp_Object frame)
   unwind_create_frame (frame);
 }
 
-static void
+void
 x_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
-- 
2.8.0

[bug-23386-patch-v1-backtrace.txt (text/plain, attachment)]
[Message part 4 (text/plain, inline)]
>
> I think one idea that could be useful is to trace the creation of
> relevant objects when Emacs starts up, starting with the call to
> font_update_drivers, and then compare that with what happens in this
> case.  That could delineate the missing parts and the differences
> which could point the way to solving this cleanly.

Yeah, I'm still having trouble seeing the forest for the trees.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Sun, 10 Jul 2016 20:18:02 GMT) Full text and rfc822 format available.

Message #37 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Dmitry Antipov <dmantipov <at> yandex.ru>
Cc: Stefan Monnier <monnier <at> IRO.UMontreal.CA>, 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Sun, 10 Jul 2016 16:17:00 -0400
Dmitry Antipov <dmantipov <at> yandex.ru> writes:

> On 07/09/2016 10:11 PM, npostavs <at> users.sourceforge.net wrote:
>
>> Here is a patch that attempts to fix the issue by resetting the font
>> after the backend is changed.  It does let Emacs successfully open the
>> frame with the new font (no funny box characters in the modeline), but
>> I'm not sure if it's the best way of marking the font object invalid.
>
> IMHO the original trick (request to drop font backend when there is a font
> opened by using this backend) is practically meaningless, so why just not
> prohibit it explicitly? For example, with:

Maybe that is a better idea; it does prevent the segfault, and it's
certainly simpler.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Mon, 11 Jul 2016 14:35:01 GMT) Full text and rfc822 format available.

Message #40 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: npostavs <at> users.sourceforge.net
Cc: dmantipov <at> yandex.ru, monnier <at> IRO.UMontreal.CA, 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Mon, 11 Jul 2016 17:33:29 +0300
> From: npostavs <at> users.sourceforge.net
> Date: Sun, 10 Jul 2016 16:17:00 -0400
> Cc: Stefan Monnier <monnier <at> IRO.UMontreal.CA>, 23386 <at> debbugs.gnu.org
> 
> Dmitry Antipov <dmantipov <at> yandex.ru> writes:
> 
> > IMHO the original trick (request to drop font backend when there is a font
> > opened by using this backend) is practically meaningless, so why just not
> > prohibit it explicitly? For example, with:
> 
> Maybe that is a better idea; it does prevent the segfault, and it's
> certainly simpler.

But it doesn't do what the user asked for.

I don't see why it would be meaningless to evict a backend and start
using another one, if all it takes is re-open a bunch of fonts.

So I'm in favor of Noam's proposal, assuming that it works.

Noam, I encourage you to dig some more into this "forest", until you
convince yourself that the patch is sound.  While at that, please
consider adding comments where you learn useful things that are not
trivial to understand from the code alone, as this area of Emacs
sources is notoriously under-documented.

One issue that bothers me is this: what if additional fonts were
already opened for non-default faces?  Should they also get some
treatment?  (This is relevant to Dmitry's suggestion as well.)

I have one comment about your patch:

> diff --git a/src/xfns.c b/src/xfns.c
> index 7c1bb1c..1b9dd48 100644
> --- a/src/xfns.c
> +++ b/src/xfns.c
> @@ -3071,7 +3071,7 @@ do_unwind_create_frame (Lisp_Object frame)
>    unwind_create_frame (frame);
>  }
>  
> -static void
> +void
>  x_default_font_parameter (struct frame *f, Lisp_Object parms)
>  {
>    struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);

This cannot be done only in xfns.c, as it will then break the other
platforms, because x_set_font_backend is not specific to X.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Tue, 12 Jul 2016 15:21:01 GMT) Full text and rfc822 format available.

Message #43 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Antipov <dmantipov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>, npostavs <at> users.sourceforge.net
Cc: 23386 <at> debbugs.gnu.org
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Tue, 12 Jul 2016 18:20:41 +0300
[Message part 1 (text/plain, inline)]
On 07/11/2016 05:33 PM, Eli Zaretskii wrote:

> But it doesn't do what the user asked for.
>
> I don't see why it would be meaningless to evict a backend and start
> using another one, if all it takes is re-open a bunch of fonts.

OK, the following patch basically works for me (not tested too much, BTW).

Dmitry


[bug23386.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Tue, 12 Jul 2016 17:47:01 GMT) Full text and rfc822 format available.

Message #46 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dmitry Antipov <dmantipov <at> yandex.ru>
Cc: 23386 <at> debbugs.gnu.org, npostavs <at> users.sourceforge.net
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Tue, 12 Jul 2016 20:45:30 +0300
> Cc: 23386 <at> debbugs.gnu.org
> From: Dmitry Antipov <dmantipov <at> yandex.ru>
> Date: Tue, 12 Jul 2016 18:20:41 +0300
> 
> > But it doesn't do what the user asked for.
> >
> > I don't see why it would be meaningless to evict a backend and start
> > using another one, if all it takes is re-open a bunch of fonts.
> 
> OK, the following patch basically works for me (not tested too much, BTW).

Thanks.

> --- a/src/frame.c
> +++ b/src/frame.c
> @@ -3712,7 +3712,11 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
>      return;
>  
>    if (FRAME_FONT (f))
> -    free_all_realized_faces (Qnil);
> +    {
> +      Lisp_Object frame;
> +      XSETFRAME (frame, f);
> +      free_all_realized_faces (frame);
> +    }

Since free_all_realized_faces with a nil argument will free faces on
all frames, can you tell why this hunk was needed?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Tue, 12 Jul 2016 17:59:01 GMT) Full text and rfc822 format available.

Message #49 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Antipov <dmantipov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 23386 <at> debbugs.gnu.org, npostavs <at> users.sourceforge.net
Subject: Re: bug#23386: Segfault when messing with font-backend
Date: Tue, 12 Jul 2016 20:58:05 +0300
On 07/12/2016 08:45 PM, Eli Zaretskii wrote:

>> --- a/src/frame.c
>> +++ b/src/frame.c
>> @@ -3712,7 +3712,11 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
>>      return;
>>
>>    if (FRAME_FONT (f))
>> -    free_all_realized_faces (Qnil);
>> +    {
>> +      Lisp_Object frame;
>> +      XSETFRAME (frame, f);
>> +      free_all_realized_faces (frame);
>> +    }
>
> Since free_all_realized_faces with a nil argument will free faces on
> all frames, can you tell why this hunk was needed?

Hmm...hopefully there are no reasons to disturb other frames when we change
font backend(s) on the only one.

Dmitry







Merged 23386 35803. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 20 May 2019 01:19:02 GMT) Full text and rfc822 format available.

Merged 23386 35803 36835. Request was from YAMAMOTO Mitsuharu <mituharu <at> math.s.chiba-u.ac.jp> to control <at> debbugs.gnu.org. (Mon, 29 Jul 2019 23:56:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Tue, 30 Jul 2019 07:25:02 GMT) Full text and rfc822 format available.

Message #56 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Štěpán Němec <stepnem <at> gmail.com>
To: YAMAMOTO Mitsuharu <mituharu <at> math.s.chiba-u.ac.jp>
Cc: 23386 <at> debbugs.gnu.org, 36835 <at> debbugs.gnu.org
Subject: Re: bug#36835: 27.0.50;
 Segmentation fault on Cairo build (ftcrfont_glyph_extents at
 ftcrfont.c:77)
Date: Tue, 30 Jul 2019 09:24:33 +0200
> The .emacs.desktop file contains (font-backend xft x).  This triggers
> Bug#23386 (Segfault when messing with font-backend) on the cairo build.

Thank you. I guess I could have searched more, longer and/or better than
I did to find the other reports, but given how long this has been an
issue, could this please be mentioned in etc/PROBLEMS?

-- 
Štěpán




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Fri, 02 Aug 2019 09:28:02 GMT) Full text and rfc822 format available.

Message #59 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Štěpán Němec <stepnem <at> gmail.com>
Cc: 36835 <at> debbugs.gnu.org, 23386 <at> debbugs.gnu.org, mituharu <at> math.s.chiba-u.ac.jp
Subject: Re: bug#23386: bug#36835: 27.0.50;
 Segmentation fault on Cairo build (ftcrfont_glyph_extents at
 ftcrfont.c:77)
Date: Fri, 02 Aug 2019 12:27:08 +0300
> From: Štěpán Němec
>  <stepnem <at> gmail.com>
> Date: Tue, 30 Jul 2019 09:24:33 +0200
> Cc: 23386 <at> debbugs.gnu.org, 36835 <at> debbugs.gnu.org
> 
> > The .emacs.desktop file contains (font-backend xft x).  This triggers
> > Bug#23386 (Segfault when messing with font-backend) on the cairo build.
> 
> Thank you. I guess I could have searched more, longer and/or better than
> I did to find the other reports, but given how long this has been an
> issue, could this please be mentioned in etc/PROBLEMS?

We don't normally describe our bugs in PROBLEMS, but since this bug is
unlikely to be solved soon, and since this is a startup-time crash, I
did add this particular manifestation of the bug to PROBLEMS.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23386; Package emacs. (Fri, 02 Aug 2019 10:40:02 GMT) Full text and rfc822 format available.

Message #62 received at 23386 <at> debbugs.gnu.org (full text, mbox):

From: Štěpán Němec <stepnem <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 36835 <at> debbugs.gnu.org, 23386 <at> debbugs.gnu.org, mituharu <at> math.s.chiba-u.ac.jp
Subject: Re: bug#23386: bug#36835: 27.0.50; Segmentation fault on Cairo
 build (ftcrfont_glyph_extents at ftcrfont.c:77)
Date: Fri, 02 Aug 2019 12:39:38 +0200
On Fri, 02 Aug 2019 12:27:08 +0300
Eli Zaretskii wrote:

> We don't normally describe our bugs in PROBLEMS, but since this bug is
> unlikely to be solved soon, and since this is a startup-time crash, I
> did add this particular manifestation of the bug to PROBLEMS.
>
> Thanks.

Thank you!

-- 
Štěpán




Forcibly Merged 23386 35803 36835 39865. Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 12 Mar 2020 09:40:02 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 27.1. Request was from Robert Pluim <rpluim <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 17 Mar 2020 16:07:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 15 Apr 2020 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 64 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.