Subject: Re: bug#71176: 30.0.50; Segmentation fault (SIGSEGV) in TTY+emacsclient, default_face is nil

From: Eli Zaretskii <[email-masked]>
Date: Sat, 25 May 2024 20:48:07 +0300

> Cc: [email-masked]
> Date: Sat, 25 May 2024 20:25:51 +0300
> From: Eli Zaretskii <[email-masked]>
> 
> > From: Daniel Clemente <[email-masked]>
> > Date: Sat, 25 May 2024 16:22:12 +0000
> > Cc: Eli Zaretskii <[email-masked]>
> > 
> > With those changes (on top of the 2 weeks old commit I was using) it still fails in the same way.
> 
> OK.  Please show the output of the following GDB commands:
> 
>  (gdb) p f->face_cache->used
>  (gdb) p Vface_remapping_alist

And also, please try the patch below.

diff --git a/src/xfaces.c b/src/xfaces.c
index 5192b22..4f7214e 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4246,12 +4246,19 @@ DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face,
       /* This can be NULL (e.g., in batch mode).  */
       if (oldface)
 	{
+	  /* In some cases, realize_face below can call Lisp, which could
+             trigger redisplay.  But we are in the process of realizing
+             the default face, and therefore are not ready to do display.  */
+	  specpdl_ref count = SPECPDL_INDEX ();
+	  specbind (Qinhibit_redisplay, Qt);
+
 	  /* Ensure that the face vector is fully specified by merging
 	     the previously-cached vector.  */
 	  memcpy (attrs, oldface->lface, sizeof attrs);
 
 	  merge_face_vectors (NULL, f, lvec, attrs, 0);
 	  vcopy (local_lface, 0, attrs, LFACE_VECTOR_SIZE);
+
 	  newface = realize_face (c, lvec, DEFAULT_FACE_ID);
 
 	  if ((! UNSPECIFIEDP (gvec[LFACE_FAMILY_INDEX])
@@ -4291,6 +4298,8 @@ DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face,
 			      gvec[LFACE_BACKGROUND_INDEX]);
 	      Fmodify_frame_parameters (frame, arg);
 	    }
+
+	  unbind_to (count, Qnil);
 	}
     }