GNU bug report logs - #6593
emacs-23.2 crashes in get_glyph_face_and_encoding with a null face returned by FACE_FROM_ID(0)

Previous Next

Package: emacs;

Reported by: John Lumby <johnlumby <at> hotmail.com>

Date: Fri, 9 Jul 2010 16:03:02 UTC

Severity: normal

Done: Chong Yidong <cyd <at> stupidchicken.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 6593 in the body.
You can then email your comments to 6593 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 owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6593; Package emacs. (Fri, 09 Jul 2010 16:03:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to John Lumby <johnlumby <at> hotmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 09 Jul 2010 16:03:03 GMT) Full text and rfc822 format available.

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

From: John Lumby <johnlumby <at> hotmail.com>
To: <bug-gnu-emacs <at> gnu.org>
Subject: emacs-23.2 crashes in get_glyph_face_and_encoding with a null face
	returned by FACE_FROM_ID(0)
Date: Fri, 9 Jul 2010 09:54:55 -0400
[Message part 1 (text/plain, inline)]
 paste this text into any lisp-interaction buffer e.g. *scratch*,  position cursor at end, and press Ctl-X Ctl-E


(progn (modify-frame-parameters (selected-frame) '((menu-bar-lines . 0)))
(set-face-font 'modeline "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
 (face-set-after-frame-default (selected-frame)) (set-face-background 'default (cdr (assoc 'background-color (frame-parameters (selected-frame))))) (set-face-background 'fringe (cdr (assoc 'background-color (frame-parameters (selected-frame))))) (set-face-foreground 'default (cdr (assoc 'foreground-color (frame-parameters (selected-frame))))) (server-start))



I get a crash in get_glyph_face_and_encoding. 


It did not happen in 23.1

I started emacs with something like
emacs --name=sawlist --title=sawlist -ms "#14892b" -cr red -fn "-Misc-Fixed-bold-R-*--15-*-*-*-C-90-ISO8859-1" -bg "#E0EDED" -fg "#751503" -q -load sawlist.el

I can send my sawlist.el  if needed

I obtained a core file after rebuilding to get the debugging information and here is the relevant piece
(gdb) bt
#0  0x00d57424 in __kernel_vsyscall ()
#1  0x00876006 in kill () at ../sysdeps/unix/syscall-template.S:82
#2  0x0810fe76 in fatal_error_signal (sig=11) at emacs.c:402
#3  <signal handler called>
#4  get_glyph_face_and_encoding (f=0x920c4f0, glyph=0x946b9a0, char2b=0xbfbeb890, two_byte_p=0xbfbeb85c) at xdisp.c:19511
#5  0x0806bc58 in fill_glyph_string (s=0xbfbeb8b0, face_id=0, start=<value optimized out>, end=1, overlaps=0) at xdisp.c:19681
#6  0x0806c68b in draw_glyphs (w=0x920c670, x=27, row=0x93fa530, area=TEXT_AREA, start=0, end=1, hl=DRAW_NORMAL_TEXT, overlaps=0)
    at xdisp.c:20297



This patch (below) fixes one obvious mistake (but not the cause) and also works around the problem.  This mistake is that the assert is located after the dereference of the face pointer  - should be before.   But that just changes the crash to an assert failure.   The workaround to is to try all other faces cached on the frame.    I don't know what the correct fix is for the default face being null.


John Lumby


--- src/dispextern.h.orig	2010-04-03 18:26:13.000000000 -0400
+++ src/dispextern.h	2010-07-08 11:17:41.000000000 -0400
@@ -1664,12 +1664,19 @@ struct face_cache
      else					\
        (void) 0
 
+/* search for the first usable cached face on frame F,
+   or null if such a face doesn't exist.  */
+
+struct face *try_all_cached_faces(struct frame *f);
+
 /* Return a pointer to the face with ID on frame F, or null if such a
-   face doesn't exist.  */
+   face doesn't exist.   But try *all* faces cached for this frame before giving up  */
 
 #define FACE_FROM_ID(F, ID)				\
      (((unsigned) (ID) < FRAME_FACE_CACHE (F)->used)	\
-      ? FRAME_FACE_CACHE (F)->faces_by_id[ID]		\
+         ? (FRAME_FACE_CACHE (F)->faces_by_id[ID] ? FRAME_FACE_CACHE (F)->faces_by_id[ID] : \
+            try_all_cached_faces(F) \
+           ) \
       : NULL)
 
 #ifdef HAVE_WINDOW_SYSTEM

--- src/xdisp.c.orig    2010-04-05 10:05:48.000000000 -0400
+++ src/xdisp.c    2010-07-08 11:23:35.000000000 -0400
@@ -19489,6 +19489,22 @@ get_char_face_and_encoding (f, c, face_i
 }
 
 
+/* search for the first usable cached face on frame F,
+   or null if such a face doesn't exist.  */
+
+struct face *try_all_cached_faces(struct frame *f)
+{
+  struct face *local_face = 0;
+  int ix, used;
+
+  used = FRAME_FACE_CACHE(f)->used;
+  for (ix=0; ((ix<used) && (local_face == (struct face *)0)); ix++) {
+     local_face =  FRAME_FACE_CACHE(f)->faces_by_id[ix];
+  }
+
+  return local_face;
+}
+
 /* Get face and two-byte form of character glyph GLYPH on frame F.
    The encoding of GLYPH->u.ch is returned in *CHAR2B.  Value is
    a pointer to a realized face that is ready for display.  */
@@ -19505,6 +19521,9 @@ get_glyph_face_and_encoding (f, glyph, c
   xassert (glyph->type == CHAR_GLYPH);
   face = FACE_FROM_ID (f, glyph->face_id);
 
+  /* Make sure X resources of the face are allocated.  */
+  xassert (face != NULL);
+
   if (two_byte_p)
     *two_byte_p = 0;
 
@@ -19518,8 +19537,6 @@ get_glyph_face_and_encoding (f, glyph, c
     STORE_XCHAR2B (char2b, 0, 0);
     }
 
-  /* Make sure X resources of the face are allocated.  */
-  xassert (face != NULL);
   PREPARE_FACE_FOR_DISPLAY (f, face);
   return face;
 }



 		 	   		  
Your Photo on Bing.ca: You Could WIN on Canada Day! Submit a Photo Now!  		 	   		  
_________________________________________________________________
Learn more ways to connect with your buddies now
http://go.microsoft.com/?linkid=9734388
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6593; Package emacs. (Sat, 10 Jul 2010 08:16:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: John Lumby <johnlumby <at> hotmail.com>
Cc: 6593 <at> debbugs.gnu.org
Subject: Re: bug#6593: emacs-23.2 crashes in get_glyph_face_and_encoding with
	a	null face returned by FACE_FROM_ID(0)
Date: Sat, 10 Jul 2010 11:13:33 +0300
> From: John Lumby <johnlumby <at> hotmail.com>
> Date: Fri, 9 Jul 2010 09:54:55 -0400
> Cc: 
> 
>  paste this text into any lisp-interaction buffer e.g. *scratch*,  position cursor at end, and press Ctl-X Ctl-E
> 
> 
> (progn (modify-frame-parameters (selected-frame) '((menu-bar-lines . 0)))
> (set-face-font 'modeline "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
>  (face-set-after-frame-default (selected-frame)) (set-face-background 'default (cdr (assoc 'background-color (frame-parameters (selected-frame))))) (set-face-background 'fringe (cdr (assoc 'background-color (frame-parameters (selected-frame))))) (set-face-foreground 'default (cdr (assoc 'foreground-color (frame-parameters (selected-frame))))) (server-start))
> 
> 
> 
> I get a crash in get_glyph_face_and_encoding. 

Thanks for your report.  It misses a few crucial details, though.

What system is that?  I couldn't reproduce the crash on my machine
(MS-Windows).

> I started emacs with something like
> emacs --name=sawlist --title=sawlist -ms "#14892b" -cr red -fn "-Misc-Fixed-bold-R-*--15-*-*-*-C-90-ISO8859-1" -bg "#E0EDED" -fg "#751503" -q -load sawlist.el
> 
> I can send my sawlist.el  if needed

Does the crash happen if you start Emacs with "emacs -Q"?  Without -Q,
your customizations on ~/.emacs also come into play.

> I obtained a core file after rebuilding to get the debugging information and here is the relevant piece
> (gdb) bt
> #0  0x00d57424 in __kernel_vsyscall ()
> #1  0x00876006 in kill () at ../sysdeps/unix/syscall-template.S:82
> #2  0x0810fe76 in fatal_error_signal (sig=11) at emacs.c:402
> #3  <signal handler called>
> #4  get_glyph_face_and_encoding (f=0x920c4f0, glyph=0x946b9a0, char2b=0xbfbeb890, two_byte_p=0xbfbeb85c) at xdisp.c:19511
> #5  0x0806bc58 in fill_glyph_string (s=0xbfbeb8b0, face_id=0, start=<value optimized out>, end=1, overlaps=0) at xdisp.c:19681
> #6  0x0806c68b in draw_glyphs (w=0x920c670, x=27, row=0x93fa530, area=TEXT_AREA, start=0, end=1, hl=DRAW_NORMAL_TEXT, overlaps=0)
>     at xdisp.c:20297

Please show the full backtrace, including the Lisp backtrace (shown if
you start GDB from the src directory).  The above only shows the top 6
stack frames.

Also, if you could rebuild without optimizations (-O0), it would help,
because the stack trace in an optimized build cannot be trusted and
too many variables have their values shown as ``optimized out'', which
doesn't really help debugging.

> This patch (below) fixes one obvious mistake (but not the cause) and also works around the problem.  This mistake is that the assert is located after the dereference of the face pointer  - should be before.   But that just changes the crash to an assert failure.   The workaround to is to try all other faces cached on the frame.    I don't know what the correct fix is for the default face being null.

Sorry, but I don't think this is the right fix.  The default face
should always be realized.  Looking up some face, any face, in the
face cache is not TRT.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6593; Package emacs. (Sat, 10 Jul 2010 17:59:02 GMT) Full text and rfc822 format available.

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

From: Chong Yidong <cyd <at> stupidchicken.com>
To: John Lumby <johnlumby <at> hotmail.com>
Cc: 6593 <at> debbugs.gnu.org
Subject: Re: bug#6593: emacs-23.2 crashes in get_glyph_face_and_encoding with
	a null face returned by FACE_FROM_ID(0)
Date: Sat, 10 Jul 2010 13:58:51 -0400
John Lumby <johnlumby <at> hotmail.com> writes:

> (progn (modify-frame-parameters (selected-frame) '((menu-bar-lines . 0)))
> (set-face-font 'modeline
> "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
> (face-set-after-frame-default (selected-frame)) (set-face-background 'default
> (cdr (assoc 'background-color (frame-parameters (selected-frame)))))
> (set-face-background 'fringe (cdr (assoc 'background-color (frame-parameters
> (selected-frame))))) (set-face-foreground 'default (cdr (assoc
> 'foreground-color (frame-parameters (selected-frame))))) (server-start))
>
> I get a crash in get_glyph_face_and_encoding.

Thanks; I've checked a fix into the branch.




bug closed, send any further explanations to John Lumby <johnlumby <at> hotmail.com> Request was from Chong Yidong <cyd <at> stupidchicken.com> to control <at> debbugs.gnu.org. (Sat, 10 Jul 2010 18:00:04 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. (Sun, 08 Aug 2010 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 14 years and 322 days ago.

Previous Next


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