Subject: Re: bug#39865: 28.0.50; Emacs crash

From: Robert Pluim <[email-masked]>
Date: Thu, 12 Mar 2020 11:25:06 +0100

>>>>> On Thu, 12 Mar 2020 10:33:00 +0100, Robert Pluim <[email-masked]> said:
    Robert> Of course, what I should do is rebase
    Robert> <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23386#43>

    Robert> Yep, that fixes this for me. Of course it breaks the macOS build,
    Robert> since that doesnʼt have a gui_default_font_parameter function
    Robert> (yet :-) ).

Vinicius, the following patch should fix things for you. Iʼll have to
look at what's needed on the macOS side.

diff --git a/src/dispextern.h b/src/dispextern.h
index 6246c7c080..f08231f071 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3726,6 +3726,7 @@ #define IMAGE_BACKGROUND_TRANSPARENT(img, f, mask)			      \
                                           Lisp_Object, Lisp_Object,
                                           const char *, const char *,
                                           enum resource_types);
+extern void gui_default_font_parameter (struct frame *, Lisp_Object);
 
 #ifndef HAVE_NS /* These both used on W32 and X only.  */
 extern bool gui_mouse_grabbed (Display_Info *);
diff --git a/src/frame.c b/src/frame.c
index 51fc78ab70..45fed8420c 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -4565,7 +4565,11 @@ gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
     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))
@@ -4579,10 +4583,8 @@ gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
 
   if (FRAME_FONT (f))
     {
-      Lisp_Object frame;
-
-      XSETFRAME (frame, f);
-      gui_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
+      /* Reconsider default font after backend(s) change (Bug#23386).  */
+      gui_default_font_parameter (f, Qnil);
       face_change = true;
       windows_or_buffers_changed = 18;
     }
diff --git a/src/xfns.c b/src/xfns.c
index 5758bb7a18..ab013d85d8 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3555,8 +3555,8 @@ do_unwind_create_frame (Lisp_Object frame)
   unwind_create_frame (frame);
 }
 
-static void
-x_default_font_parameter (struct frame *f, Lisp_Object parms)
+void
+gui_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object font_param = gui_display_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
@@ -3894,7 +3894,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
-  x_default_font_parameter (f, parms);
+  gui_default_font_parameter (f, parms);
   if (!FRAME_FONT (f))
     {
       delete_frame (frame, Qnoelisp);
@@ -6378,7 +6378,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
 
   /* Extract the window parameters from the supplied values that are
      needed to determine window geometry.  */
-  x_default_font_parameter (f, parms);
+  gui_default_font_parameter (f, parms);
 
   gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
                          "borderWidth", "BorderWidth", RES_TYPE_NUMBER);