Subject: Re: bug#23386: Segfault when messing with font-backend

From: Dmitry Antipov <[email-masked]>
Date: Tue, 12 Jul 2016 18:20:41 +0300

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

diff --git a/src/dispextern.h b/src/dispextern.h
index c2fcca5..88b4077 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3605,6 +3605,7 @@ extern Lisp_Object x_default_parameter (struct frame *, Lisp_Object,
                                         Lisp_Object, Lisp_Object,
                                         const char *, const char *,
                                         enum resource_types);
+extern void x_default_font_parameter (struct frame *, Lisp_Object);
 extern char *x_get_string_resource (XrmDatabase, const char *,
 				    const char *);
 
diff --git a/src/frame.c b/src/frame.c
index 80e181f..40d2d32 100644
--- 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);
+    }
 
   new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
   if (NILP (new_value))
@@ -3726,10 +3730,8 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
 
   if (FRAME_FONT (f))
     {
-      Lisp_Object frame;
-
-      XSETFRAME (frame, f);
-      x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
+      /* Reconsider default font after backend(s) change (Bug#23386).  */
+      x_default_font_parameter (f, Qnil);
       face_change = true;
       windows_or_buffers_changed = 18;
     }
diff --git a/src/w32fns.c b/src/w32fns.c
index 0eb720e..cffa8c0 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -5249,7 +5249,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 w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
diff --git a/src/xfns.c b/src/xfns.c
index 16dbcfd..fcd3886 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3065,7 +3065,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);