aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2016-07-02 12:39:47 +0300
committerEli Zaretskii2016-07-02 12:39:47 +0300
commit55d38fc89f5aeb9a73c9a8e13914fbb8a9a6a1af (patch)
tree46a5bde90a8759582c0c3f7071b7a533056eaa75 /src
parenta5ec5c073a182aa014d9d753f14751248ea5c9a7 (diff)
downloademacs-55d38fc89f5aeb9a73c9a8e13914fbb8a9a6a1af.tar.gz
emacs-55d38fc89f5aeb9a73c9a8e13914fbb8a9a6a1af.zip
Rename FACE_OPT_FROM_ID to FACE_FROM_ID_OR_NULL
* src/dispextern.h (FACE_FROM_ID_OR_NULL): Renamed from FACE_OPT_FROM_ID; all callers changed. * src/xdisp.c (extend_face_to_end_of_line): Call FACE_FROM_ID, not FACE_FROM_ID_OR_NULL, as the resulting face is immediately dereferenced. (fill_gstring_glyph_string): Call FACE_FROM_ID, not FACE_FROM_ID_OR_NULL, as the resulting face will be dereferenced when the glyph string is drawn. (BUILD_COMPOSITE_GLYPH_STRING): Call FACE_FROM_ID, not FACE_FROM_ID_OR_NULL, as the resulting face will be dereferenced in fill_composite_glyph_string. (calc_line_height_property): Call FACE_FROM_ID_OR_NULL rather that FACE_FROM_ID, since the function and its caller can cope with that situation. Conflate 3 tests of missing face or font into just one. * src/xfaces.c (Fx_list_fonts, Fface_font, lookup_face): Call FACE_FROM_ID_OR_NULL rather that FACE_FROM_ID, since these functions can cope with that situation. (lookup_derived_face): Don't call FACE_FROM_ID if the result will not be used. * src/w32console.c (w32_face_attributes): Remove redundant 'eassert'.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c2
-rw-r--r--src/dispextern.h2
-rw-r--r--src/fontset.c4
-rw-r--r--src/fringe.c5
-rw-r--r--src/macfont.m4
-rw-r--r--src/msdos.c6
-rw-r--r--src/nsfont.m3
-rw-r--r--src/nsterm.h2
-rw-r--r--src/nsterm.m22
-rw-r--r--src/w32console.c2
-rw-r--r--src/w32term.c10
-rw-r--r--src/xdisp.c48
-rw-r--r--src/xfaces.c31
-rw-r--r--src/xterm.c10
14 files changed, 74 insertions, 77 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 5f9d6ada5a1..e25d91ff8aa 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6135,7 +6135,7 @@ mark_face_cache (struct face_cache *c)
6135 int i, j; 6135 int i, j;
6136 for (i = 0; i < c->used; ++i) 6136 for (i = 0; i < c->used; ++i)
6137 { 6137 {
6138 struct face *face = FACE_OPT_FROM_ID (c->f, i); 6138 struct face *face = FACE_FROM_ID_OR_NULL (c->f, i);
6139 6139
6140 if (face) 6140 if (face)
6141 { 6141 {
diff --git a/src/dispextern.h b/src/dispextern.h
index 08dcd89709a..1325ff9da28 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1821,7 +1821,7 @@ struct face_cache
1821/* Return a pointer to the face with ID on frame F, or null if such a 1821/* Return a pointer to the face with ID on frame F, or null if such a
1822 face doesn't exist. */ 1822 face doesn't exist. */
1823 1823
1824#define FACE_OPT_FROM_ID(F, ID) \ 1824#define FACE_FROM_ID_OR_NULL(F, ID) \
1825 (UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used) \ 1825 (UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used) \
1826 ? FRAME_FACE_CACHE (F)->faces_by_id[ID] \ 1826 ? FRAME_FACE_CACHE (F)->faces_by_id[ID] \
1827 : NULL) 1827 : NULL)
diff --git a/src/fontset.c b/src/fontset.c
index 81528de55a0..67696d0fead 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1305,7 +1305,7 @@ free_realized_fontsets (Lisp_Object base)
1305 { 1305 {
1306 struct frame *f = XFRAME (FONTSET_FRAME (this)); 1306 struct frame *f = XFRAME (FONTSET_FRAME (this));
1307 int face_id = XINT (XCDR (XCAR (tail))); 1307 int face_id = XINT (XCDR (XCAR (tail)));
1308 struct face *face = FACE_OPT_FROM_ID (f, face_id); 1308 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
1309 1309
1310 /* Face THIS itself is also freed by the following call. */ 1310 /* Face THIS itself is also freed by the following call. */
1311 free_realized_face (f, face); 1311 free_realized_face (f, face);
@@ -1637,7 +1637,7 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1637 continue; 1637 continue;
1638 if (fontset_id != FRAME_FONTSET (f)) 1638 if (fontset_id != FRAME_FONTSET (f))
1639 continue; 1639 continue;
1640 face = FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID); 1640 face = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
1641 if (face) 1641 if (face)
1642 font_object = font_load_for_lface (f, face->lface, font_spec); 1642 font_object = font_load_for_lface (f, face->lface, font_spec);
1643 else 1643 else
diff --git a/src/fringe.c b/src/fringe.c
index 87ec9d15c01..986bde16f09 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -620,8 +620,7 @@ draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int o
620 break; 620 break;
621 } 621 }
622 622
623 p.face = FACE_OPT_FROM_ID (f, face_id); 623 p.face = FACE_FROM_ID_OR_NULL (f, face_id);
624
625 if (p.face == NULL) 624 if (p.face == NULL)
626 { 625 {
627 /* This could happen after clearing face cache. 626 /* This could happen after clearing face cache.
@@ -1627,7 +1626,7 @@ If FACE is nil, reset face to default fringe face. */)
1627 { 1626 {
1628 struct frame *f = SELECTED_FRAME (); 1627 struct frame *f = SELECTED_FRAME ();
1629 1628
1630 if (FACE_OPT_FROM_ID (f, FRINGE_FACE_ID) 1629 if (FACE_FROM_ID_OR_NULL (f, FRINGE_FACE_ID)
1631 && lookup_derived_face (f, face, FRINGE_FACE_ID, 1) < 0) 1630 && lookup_derived_face (f, face, FRINGE_FACE_ID, 1) < 0)
1632 error ("No such face"); 1631 error ("No such face");
1633 } 1632 }
diff --git a/src/macfont.m b/src/macfont.m
index 79001344769..4e4daba0707 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -2856,8 +2856,8 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y,
2856 { 2856 {
2857 if (s->hl == DRAW_MOUSE_FACE) 2857 if (s->hl == DRAW_MOUSE_FACE)
2858 { 2858 {
2859 face = FACE_OPT_FROM_ID (s->f, 2859 face = FACE_FROM_ID_OR_NULL (s->f,
2860 MOUSE_HL_INFO (s->f)->mouse_face_face_id); 2860 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
2861 if (!face) 2861 if (!face)
2862 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 2862 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
2863 } 2863 }
diff --git a/src/msdos.c b/src/msdos.c
index c2b19a65173..73d755ae646 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -795,8 +795,8 @@ static void
795IT_set_face (int face) 795IT_set_face (int face)
796{ 796{
797 struct frame *sf = SELECTED_FRAME (); 797 struct frame *sf = SELECTED_FRAME ();
798 struct face *fp = FACE_OPT_FROM_ID (sf, face); 798 struct face *fp = FACE_FROM_ID_OR_NULL (sf, face);
799 struct face *dfp = FACE_OPT_FROM_ID (sf, DEFAULT_FACE_ID); 799 struct face *dfp = FACE_FROM_ID_OR_NULL (sf, DEFAULT_FACE_ID);
800 unsigned long fg, bg, dflt_fg, dflt_bg; 800 unsigned long fg, bg, dflt_fg, dflt_bg;
801 struct tty_display_info *tty = FRAME_TTY (sf); 801 struct tty_display_info *tty = FRAME_TTY (sf);
802 802
@@ -1076,7 +1076,7 @@ IT_clear_screen (struct frame *f)
1076 any valid faces and will abort. Instead, use the initial screen 1076 any valid faces and will abort. Instead, use the initial screen
1077 colors; that should mimic what a Unix tty does, which simply clears 1077 colors; that should mimic what a Unix tty does, which simply clears
1078 the screen with whatever default colors are in use. */ 1078 the screen with whatever default colors are in use. */
1079 if (FACE_OPT_FROM_ID (SELECTED_FRAME (), DEFAULT_FACE_ID) == NULL) 1079 if (FACE_FROM_ID_OR_NULL (SELECTED_FRAME (), DEFAULT_FACE_ID) == NULL)
1080 ScreenAttrib = (initial_screen_colors[0] << 4) | initial_screen_colors[1]; 1080 ScreenAttrib = (initial_screen_colors[0] << 4) | initial_screen_colors[1];
1081 else 1081 else
1082 IT_set_face (0); 1082 IT_set_face (0);
diff --git a/src/nsfont.m b/src/nsfont.m
index 7c97c6fd0ae..569a69f9fe8 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -1071,7 +1071,8 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1071 face = s->face; 1071 face = s->face;
1072 break; 1072 break;
1073 case NS_DUMPGLYPH_MOUSEFACE: 1073 case NS_DUMPGLYPH_MOUSEFACE:
1074 face = FACE_OPT_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id); 1074 face = FACE_FROM_ID_OR_NULL (s->f,
1075 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
1075 if (!face) 1076 if (!face)
1076 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 1077 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
1077 break; 1078 break;
diff --git a/src/nsterm.h b/src/nsterm.h
index c2285c90e62..862ff2ec646 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -1014,7 +1014,7 @@ struct x_output
1014#define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height) 1014#define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
1015#define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height) 1015#define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
1016 1016
1017#define FRAME_DEFAULT_FACE(f) FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID) 1017#define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1018 1018
1019#define FRAME_NS_VIEW(f) ((f)->output_data.ns->view) 1019#define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1020#define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color) 1020#define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
diff --git a/src/nsterm.m b/src/nsterm.m
index 4b887ec0b50..4027f5c4615 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2882,7 +2882,7 @@ ns_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
2882 ns_clip_to_row (w, glyph_row, TEXT_AREA, NO); /* do ns_focus(f, &r, 1); if remove */ 2882 ns_clip_to_row (w, glyph_row, TEXT_AREA, NO); /* do ns_focus(f, &r, 1); if remove */
2883 2883
2884 2884
2885 face = FACE_OPT_FROM_ID (f, phys_cursor_glyph->face_id); 2885 face = FACE_FROM_ID_OR_NULL (f, phys_cursor_glyph->face_id);
2886 if (face && NS_FACE_BACKGROUND (face) 2886 if (face && NS_FACE_BACKGROUND (face)
2887 == ns_index_color (FRAME_CURSOR_COLOR (f), f)) 2887 == ns_index_color (FRAME_CURSOR_COLOR (f), f))
2888 { 2888 {
@@ -2954,7 +2954,7 @@ ns_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
2954 2954
2955 NSTRACE ("ns_draw_vertical_window_border"); 2955 NSTRACE ("ns_draw_vertical_window_border");
2956 2956
2957 face = FACE_OPT_FROM_ID (f, VERTICAL_BORDER_FACE_ID); 2957 face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
2958 2958
2959 ns_focus (f, &r, 1); 2959 ns_focus (f, &r, 1);
2960 if (face) 2960 if (face)
@@ -2977,7 +2977,7 @@ ns_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
2977 2977
2978 NSTRACE ("ns_draw_window_divider"); 2978 NSTRACE ("ns_draw_window_divider");
2979 2979
2980 face = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_FACE_ID); 2980 face = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FACE_ID);
2981 2981
2982 ns_focus (f, &r, 1); 2982 ns_focus (f, &r, 1);
2983 if (face) 2983 if (face)
@@ -3311,9 +3311,10 @@ ns_dumpglyphs_box_or_relief (struct glyph_string *s)
3311 3311
3312 if (s->hl == DRAW_MOUSE_FACE) 3312 if (s->hl == DRAW_MOUSE_FACE)
3313 { 3313 {
3314 face = FACE_OPT_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id); 3314 face = FACE_FROM_ID_OR_NULL (s->f,
3315 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3315 if (!face) 3316 if (!face)
3316 face = FACE_OPT_FROM_ID (s->f, MOUSE_FACE_ID); 3317 face = FACE_FROM_ID_OR_NULL (s->f, MOUSE_FACE_ID);
3317 } 3318 }
3318 else 3319 else
3319 face = s->face; 3320 face = s->face;
@@ -3379,8 +3380,8 @@ ns_maybe_dumpglyphs_background (struct glyph_string *s, char force_p)
3379 if (s->hl == DRAW_MOUSE_FACE) 3380 if (s->hl == DRAW_MOUSE_FACE)
3380 { 3381 {
3381 face 3382 face
3382 = FACE_OPT_FROM_ID (s->f, 3383 = FACE_FROM_ID_OR_NULL (s->f,
3383 MOUSE_HL_INFO (s->f)->mouse_face_face_id); 3384 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3384 if (!face) 3385 if (!face)
3385 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 3386 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3386 } 3387 }
@@ -3446,7 +3447,8 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
3446 with its background color), we must clear just the image area. */ 3447 with its background color), we must clear just the image area. */
3447 if (s->hl == DRAW_MOUSE_FACE) 3448 if (s->hl == DRAW_MOUSE_FACE)
3448 { 3449 {
3449 face = FACE_OPT_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id); 3450 face = FACE_FROM_ID_OR_NULL (s->f,
3451 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3450 if (!face) 3452 if (!face)
3451 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 3453 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3452 } 3454 }
@@ -3563,8 +3565,8 @@ ns_dumpglyphs_stretch (struct glyph_string *s)
3563 3565
3564 if (s->hl == DRAW_MOUSE_FACE) 3566 if (s->hl == DRAW_MOUSE_FACE)
3565 { 3567 {
3566 face = FACE_OPT_FROM_ID (s->f, 3568 face = FACE_FROM_ID_OR_NULL (s->f,
3567 MOUSE_HL_INFO (s->f)->mouse_face_face_id); 3569 MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3568 if (!face) 3570 if (!face)
3569 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 3571 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3570 } 3572 }
diff --git a/src/w32console.c b/src/w32console.c
index 98343a6c4ff..c71afb6f888 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -611,8 +611,6 @@ w32_face_attributes (struct frame *f, int face_id)
611 WORD char_attr; 611 WORD char_attr;
612 struct face *face = FACE_FROM_ID (f, face_id); 612 struct face *face = FACE_FROM_ID (f, face_id);
613 613
614 eassert (face != NULL);
615
616 char_attr = char_attr_normal; 614 char_attr = char_attr_normal;
617 615
618 /* Reverse the default color if requested. If background and 616 /* Reverse the default color if requested. If background and
diff --git a/src/w32term.c b/src/w32term.c
index 7ef34079e30..5a11e2a871a 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -611,7 +611,7 @@ w32_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
611 r.bottom = y1; 611 r.bottom = y1;
612 612
613 hdc = get_frame_dc (f); 613 hdc = get_frame_dc (f);
614 face = FACE_OPT_FROM_ID (f, VERTICAL_BORDER_FACE_ID); 614 face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
615 if (face) 615 if (face)
616 w32_fill_rect (f, hdc, face->foreground, &r); 616 w32_fill_rect (f, hdc, face->foreground, &r);
617 else 617 else
@@ -628,11 +628,11 @@ w32_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
628{ 628{
629 struct frame *f = XFRAME (WINDOW_FRAME (w)); 629 struct frame *f = XFRAME (WINDOW_FRAME (w));
630 HDC hdc = get_frame_dc (f); 630 HDC hdc = get_frame_dc (f);
631 struct face *face = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_FACE_ID); 631 struct face *face = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FACE_ID);
632 struct face *face_first 632 struct face *face_first
633 = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID); 633 = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID);
634 struct face *face_last 634 struct face *face_last
635 = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID); 635 = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID);
636 unsigned long color = face ? face->foreground : FRAME_FOREGROUND_PIXEL (f); 636 unsigned long color = face ? face->foreground : FRAME_FOREGROUND_PIXEL (f);
637 unsigned long color_first = (face_first 637 unsigned long color_first = (face_first
638 ? face_first->foreground 638 ? face_first->foreground
@@ -991,7 +991,7 @@ x_set_mouse_face_gc (struct glyph_string *s)
991 991
992 /* What face has to be used last for the mouse face? */ 992 /* What face has to be used last for the mouse face? */
993 face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id; 993 face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id;
994 face = FACE_OPT_FROM_ID (s->f, face_id); 994 face = FACE_FROM_ID_OR_NULL (s->f, face_id);
995 if (face == NULL) 995 if (face == NULL)
996 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 996 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
997 997
diff --git a/src/xdisp.c b/src/xdisp.c
index 1289515d918..2d0d67784cc 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1813,7 +1813,7 @@ estimate_mode_line_height (struct frame *f, enum face_id face_id)
1813 cache and mode line face are not yet initialized. */ 1813 cache and mode line face are not yet initialized. */
1814 if (FRAME_FACE_CACHE (f)) 1814 if (FRAME_FACE_CACHE (f))
1815 { 1815 {
1816 struct face *face = FACE_OPT_FROM_ID (f, face_id); 1816 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
1817 if (face) 1817 if (face)
1818 { 1818 {
1819 if (face->font) 1819 if (face->font)
@@ -2918,7 +2918,7 @@ init_iterator (struct it *it, struct window *w,
2918 2918
2919 /* If we have a boxed mode line, make the first character appear 2919 /* If we have a boxed mode line, make the first character appear
2920 with a left box line. */ 2920 with a left box line. */
2921 face = FACE_OPT_FROM_ID (it->f, remapped_base_face_id); 2921 face = FACE_FROM_ID_OR_NULL (it->f, remapped_base_face_id);
2922 if (face && face->box != FACE_NO_BOX) 2922 if (face && face->box != FACE_NO_BOX)
2923 it->start_of_box_run_p = true; 2923 it->start_of_box_run_p = true;
2924 } 2924 }
@@ -3877,9 +3877,9 @@ handle_face_prop (struct it *it)
3877 { 3877 {
3878 struct face *new_face = FACE_FROM_ID (it->f, new_face_id); 3878 struct face *new_face = FACE_FROM_ID (it->f, new_face_id);
3879 /* If it->face_id is -1, old_face below will be NULL, see 3879 /* If it->face_id is -1, old_face below will be NULL, see
3880 the definition of FACE_OPT_FROM_ID. This will happen if this 3880 the definition of FACE_FROM_ID_OR_NULL. This will happen
3881 is the initial call that gets the face. */ 3881 if this is the initial call that gets the face. */
3882 struct face *old_face = FACE_OPT_FROM_ID (it->f, it->face_id); 3882 struct face *old_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
3883 3883
3884 /* If the value of face_id of the iterator is -1, we have to 3884 /* If the value of face_id of the iterator is -1, we have to
3885 look in front of IT's position and see whether there is a 3885 look in front of IT's position and see whether there is a
@@ -3888,7 +3888,7 @@ handle_face_prop (struct it *it)
3888 { 3888 {
3889 int prev_face_id = face_before_it_pos (it); 3889 int prev_face_id = face_before_it_pos (it);
3890 3890
3891 old_face = FACE_OPT_FROM_ID (it->f, prev_face_id); 3891 old_face = FACE_FROM_ID_OR_NULL (it->f, prev_face_id);
3892 } 3892 }
3893 3893
3894 /* If the new face has a box, but the old face does not, 3894 /* If the new face has a box, but the old face does not,
@@ -3988,7 +3988,7 @@ handle_face_prop (struct it *it)
3988 if (new_face_id != it->face_id) 3988 if (new_face_id != it->face_id)
3989 { 3989 {
3990 struct face *new_face = FACE_FROM_ID (it->f, new_face_id); 3990 struct face *new_face = FACE_FROM_ID (it->f, new_face_id);
3991 struct face *old_face = FACE_OPT_FROM_ID (it->f, it->face_id); 3991 struct face *old_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
3992 3992
3993 /* If new face has a box but old face hasn't, this is the 3993 /* If new face has a box but old face hasn't, this is the
3994 start of a run of characters with box, i.e. it has a 3994 start of a run of characters with box, i.e. it has a
@@ -6095,7 +6095,7 @@ pop_it (struct it *it)
6095 break; 6095 break;
6096 case GET_FROM_STRING: 6096 case GET_FROM_STRING:
6097 { 6097 {
6098 struct face *face = FACE_OPT_FROM_ID (it->f, it->face_id); 6098 struct face *face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
6099 6099
6100 /* Restore the face_box_p flag, since it could have been 6100 /* Restore the face_box_p flag, since it could have been
6101 overwritten by the face of the object that we just finished 6101 overwritten by the face of the object that we just finished
@@ -6776,7 +6776,8 @@ static next_element_function const get_next_element[NUM_IT_METHODS] =
6776 || ((IT)->cmp_it.stop_pos == (CHARPOS) \ 6776 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6777 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \ 6777 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6778 END_CHARPOS, (IT)->w, \ 6778 END_CHARPOS, (IT)->w, \
6779 FACE_OPT_FROM_ID ((IT)->f, (IT)->face_id), \ 6779 FACE_FROM_ID_OR_NULL ((IT)->f, \
6780 (IT)->face_id), \
6780 (IT)->string))) 6781 (IT)->string)))
6781 6782
6782 6783
@@ -7205,7 +7206,7 @@ get_next_display_element (struct it *it)
7205 if (it->method == GET_FROM_STRING && it->sp) 7206 if (it->method == GET_FROM_STRING && it->sp)
7206 { 7207 {
7207 int face_id = underlying_face_id (it); 7208 int face_id = underlying_face_id (it);
7208 struct face *face = FACE_OPT_FROM_ID (it->f, face_id); 7209 struct face *face = FACE_FROM_ID_OR_NULL (it->f, face_id);
7209 7210
7210 if (face) 7211 if (face)
7211 { 7212 {
@@ -7738,8 +7739,8 @@ next_element_from_display_vector (struct it *it)
7738 /* Glyphs in the display vector could have the box face, so we 7739 /* Glyphs in the display vector could have the box face, so we
7739 need to set the related flags in the iterator, as 7740 need to set the related flags in the iterator, as
7740 appropriate. */ 7741 appropriate. */
7741 this_face = FACE_OPT_FROM_ID (it->f, it->face_id); 7742 this_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
7742 prev_face = FACE_OPT_FROM_ID (it->f, prev_face_id); 7743 prev_face = FACE_FROM_ID_OR_NULL (it->f, prev_face_id);
7743 7744
7744 /* Is this character the first character of a box-face run? */ 7745 /* Is this character the first character of a box-face run? */
7745 it->start_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX 7746 it->start_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
@@ -7764,7 +7765,7 @@ next_element_from_display_vector (struct it *it)
7764 it->saved_face_id); 7765 it->saved_face_id);
7765 } 7766 }
7766 } 7767 }
7767 next_face = FACE_OPT_FROM_ID (it->f, next_face_id); 7768 next_face = FACE_FROM_ID_OR_NULL (it->f, next_face_id);
7768 it->end_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX 7769 it->end_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
7769 && (!next_face 7770 && (!next_face
7770 || next_face->box == FACE_NO_BOX)); 7771 || next_face->box == FACE_NO_BOX));
@@ -19675,14 +19676,15 @@ extend_face_to_end_of_line (struct it *it)
19675 return; 19676 return;
19676 19677
19677 /* The default face, possibly remapped. */ 19678 /* The default face, possibly remapped. */
19678 default_face = FACE_OPT_FROM_ID (f, lookup_basic_face (f, DEFAULT_FACE_ID)); 19679 default_face = FACE_FROM_ID_OR_NULL (f,
19680 lookup_basic_face (f, DEFAULT_FACE_ID));
19679 19681
19680 /* Face extension extends the background and box of IT->face_id 19682 /* Face extension extends the background and box of IT->face_id
19681 to the end of the line. If the background equals the background 19683 to the end of the line. If the background equals the background
19682 of the frame, we don't have to do anything. */ 19684 of the frame, we don't have to do anything. */
19683 face = FACE_OPT_FROM_ID (f, (it->face_before_selective_p 19685 face = FACE_FROM_ID (f, (it->face_before_selective_p
19684 ? it->saved_face_id 19686 ? it->saved_face_id
19685 : it->face_id)); 19687 : it->face_id));
19686 19688
19687 if (FRAME_WINDOW_P (f) 19689 if (FRAME_WINDOW_P (f)
19688 && MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row) 19690 && MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row)
@@ -24784,7 +24786,7 @@ fill_gstring_glyph_string (struct glyph_string *s, int face_id,
24784 s->cmp_id = glyph->u.cmp.id; 24786 s->cmp_id = glyph->u.cmp.id;
24785 s->cmp_from = glyph->slice.cmp.from; 24787 s->cmp_from = glyph->slice.cmp.from;
24786 s->cmp_to = glyph->slice.cmp.to + 1; 24788 s->cmp_to = glyph->slice.cmp.to + 1;
24787 s->face = FACE_OPT_FROM_ID (s->f, face_id); 24789 s->face = FACE_FROM_ID (s->f, face_id);
24788 lgstring = composition_gstring_from_id (s->cmp_id); 24790 lgstring = composition_gstring_from_id (s->cmp_id);
24789 s->font = XFONT_OBJECT (LGSTRING_FONT (lgstring)); 24791 s->font = XFONT_OBJECT (LGSTRING_FONT (lgstring));
24790 glyph++; 24792 glyph++;
@@ -25377,7 +25379,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
25377#define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \ 25379#define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25378 do { \ 25380 do { \
25379 int face_id = (row)->glyphs[area][START].face_id; \ 25381 int face_id = (row)->glyphs[area][START].face_id; \
25380 struct face *base_face = FACE_OPT_FROM_ID (f, face_id); \ 25382 struct face *base_face = FACE_FROM_ID (f, face_id); \
25381 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \ 25383 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
25382 struct composition *cmp = composition_table[cmp_id]; \ 25384 struct composition *cmp = composition_table[cmp_id]; \
25383 XChar2b *char2b; \ 25385 XChar2b *char2b; \
@@ -26694,12 +26696,8 @@ calc_line_height_property (struct it *it, Lisp_Object val, struct font *font,
26694 struct face *face; 26696 struct face *face;
26695 26697
26696 face_id = lookup_named_face (it->f, face_name, false); 26698 face_id = lookup_named_face (it->f, face_name, false);
26697 if (face_id < 0) 26699 face = FACE_FROM_ID_OR_NULL (it->f, face_id);
26698 return make_number (-1); 26700 if (face == NULL || ((font = face->font) == NULL))
26699
26700 face = FACE_FROM_ID (it->f, face_id);
26701 font = face->font;
26702 if (font == NULL)
26703 return make_number (-1); 26701 return make_number (-1);
26704 boff = font->baseline_offset; 26702 boff = font->baseline_offset;
26705 if (font->vertical_centering) 26703 if (font->vertical_centering)
diff --git a/src/xfaces.c b/src/xfaces.c
index 97a5ae01e36..0a1315d6f0d 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -1552,9 +1552,7 @@ the WIDTH times as wide as FACE on FRAME. */)
1552 /* This is of limited utility since it works with character 1552 /* This is of limited utility since it works with character
1553 widths. Keep it for compatibility. --gerd. */ 1553 widths. Keep it for compatibility. --gerd. */
1554 int face_id = lookup_named_face (f, face, false); 1554 int face_id = lookup_named_face (f, face, false);
1555 struct face *width_face = (face_id < 0 1555 struct face *width_face = FACE_FROM_ID_OR_NULL (f, face_id);
1556 ? NULL
1557 : FACE_FROM_ID (f, face_id));
1558 1556
1559 if (width_face && width_face->font) 1557 if (width_face && width_face->font)
1560 { 1558 {
@@ -3694,7 +3692,7 @@ Default face attributes override any local face attributes. */)
3694 if (EQ (face, Qdefault)) 3692 if (EQ (face, Qdefault))
3695 { 3693 {
3696 struct face_cache *c = FRAME_FACE_CACHE (f); 3694 struct face_cache *c = FRAME_FACE_CACHE (f);
3697 struct face *newface, *oldface = FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID); 3695 struct face *newface, *oldface = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
3698 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 3696 Lisp_Object attrs[LFACE_VECTOR_SIZE];
3699 3697
3700 /* This can be NULL (e.g., in batch mode). */ 3698 /* This can be NULL (e.g., in batch mode). */
@@ -3777,7 +3775,7 @@ return the font name used for CHARACTER. */)
3777 { 3775 {
3778 struct frame *f = decode_live_frame (frame); 3776 struct frame *f = decode_live_frame (frame);
3779 int face_id = lookup_named_face (f, face, true); 3777 int face_id = lookup_named_face (f, face, true);
3780 struct face *fface = FACE_OPT_FROM_ID (f, face_id); 3778 struct face *fface = FACE_FROM_ID_OR_NULL (f, face_id);
3781 3779
3782 if (! fface) 3780 if (! fface)
3783 return Qnil; 3781 return Qnil;
@@ -3786,9 +3784,9 @@ return the font name used for CHARACTER. */)
3786 { 3784 {
3787 CHECK_CHARACTER (character); 3785 CHECK_CHARACTER (character);
3788 face_id = FACE_FOR_CHAR (f, fface, XINT (character), -1, Qnil); 3786 face_id = FACE_FOR_CHAR (f, fface, XINT (character), -1, Qnil);
3789 fface = FACE_FROM_ID (f, face_id); 3787 fface = FACE_FROM_ID_OR_NULL (f, face_id);
3790 } 3788 }
3791 return (fface->font 3789 return ((fface && fface->font)
3792 ? fface->font->props[FONT_NAME_INDEX] 3790 ? fface->font->props[FONT_NAME_INDEX]
3793 : Qnil); 3791 : Qnil);
3794#else /* !HAVE_WINDOW_SYSTEM */ 3792#else /* !HAVE_WINDOW_SYSTEM */
@@ -4376,7 +4374,7 @@ lookup_face (struct frame *f, Lisp_Object *attr)
4376 face = realize_face (cache, attr, -1); 4374 face = realize_face (cache, attr, -1);
4377 4375
4378#ifdef GLYPH_DEBUG 4376#ifdef GLYPH_DEBUG
4379 eassert (face == FACE_FROM_ID (f, face->id)); 4377 eassert (face == FACE_FROM_ID_OR_NULL (f, face->id));
4380#endif /* GLYPH_DEBUG */ 4378#endif /* GLYPH_DEBUG */
4381 4379
4382 return face->id; 4380 return face->id;
@@ -4429,7 +4427,7 @@ lookup_named_face (struct frame *f, Lisp_Object symbol, bool signal_p)
4429{ 4427{
4430 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 4428 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4431 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; 4429 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
4432 struct face *default_face = FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID); 4430 struct face *default_face = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
4433 4431
4434 if (default_face == NULL) 4432 if (default_face == NULL)
4435 { 4433 {
@@ -4596,11 +4594,12 @@ lookup_derived_face (struct frame *f, Lisp_Object symbol, int face_id,
4596{ 4594{
4597 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 4595 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4598 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; 4596 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
4599 struct face *default_face = FACE_FROM_ID (f, face_id); 4597 struct face *default_face;
4600 4598
4601 if (!get_lface_attributes (f, symbol, symbol_attrs, signal_p, 0)) 4599 if (!get_lface_attributes (f, symbol, symbol_attrs, signal_p, 0))
4602 return -1; 4600 return -1;
4603 4601
4602 default_face = FACE_FROM_ID (f, face_id);
4604 memcpy (attrs, default_face->lface, sizeof attrs); 4603 memcpy (attrs, default_face->lface, sizeof attrs);
4605 merge_face_vectors (f, symbol_attrs, attrs, 0); 4604 merge_face_vectors (f, symbol_attrs, attrs, 0);
4606 return lookup_face (f, attrs); 4605 return lookup_face (f, attrs);
@@ -4701,7 +4700,7 @@ x_supports_face_attributes_p (struct frame *f,
4701 merge_face_vectors (f, attrs, merged_attrs, 0); 4700 merge_face_vectors (f, attrs, merged_attrs, 0);
4702 4701
4703 face_id = lookup_face (f, merged_attrs); 4702 face_id = lookup_face (f, merged_attrs);
4704 face = FACE_OPT_FROM_ID (f, face_id); 4703 face = FACE_FROM_ID_OR_NULL (f, face_id);
4705 4704
4706 if (! face) 4705 if (! face)
4707 error ("Cannot make face"); 4706 error ("Cannot make face");
@@ -4971,7 +4970,7 @@ face for italic. */)
4971 attrs[i] = Qunspecified; 4970 attrs[i] = Qunspecified;
4972 merge_face_ref (f, attributes, attrs, true, 0); 4971 merge_face_ref (f, attributes, attrs, true, 0);
4973 4972
4974 def_face = FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID); 4973 def_face = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
4975 if (def_face == NULL) 4974 if (def_face == NULL)
4976 { 4975 {
4977 if (! realize_basic_faces (f)) 4976 if (! realize_basic_faces (f))
@@ -5445,7 +5444,7 @@ realize_x_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE])
5445 5444
5446 /* Determine the font to use. Most of the time, the font will be 5445 /* Determine the font to use. Most of the time, the font will be
5447 the same as the font of the default face, so try that first. */ 5446 the same as the font of the default face, so try that first. */
5448 default_face = FACE_OPT_FROM_ID (f, DEFAULT_FACE_ID); 5447 default_face = FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID);
5449 if (default_face 5448 if (default_face
5450 && lface_same_font_attributes_p (default_face->lface, attrs)) 5449 && lface_same_font_attributes_p (default_face->lface, attrs))
5451 { 5450 {
@@ -6131,7 +6130,7 @@ merge_faces (struct frame *f, Lisp_Object face_name, int face_id,
6131 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 6130 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6132 struct face *base_face; 6131 struct face *base_face;
6133 6132
6134 base_face = FACE_OPT_FROM_ID (f, base_face_id); 6133 base_face = FACE_FROM_ID_OR_NULL (f, base_face_id);
6135 if (!base_face) 6134 if (!base_face)
6136 return base_face_id; 6135 return base_face_id;
6137 6136
@@ -6159,7 +6158,7 @@ merge_faces (struct frame *f, Lisp_Object face_name, int face_id,
6159 struct face *face; 6158 struct face *face;
6160 if (face_id < 0) 6159 if (face_id < 0)
6161 return base_face_id; 6160 return base_face_id;
6162 face = FACE_OPT_FROM_ID (f, face_id); 6161 face = FACE_FROM_ID_OR_NULL (f, face_id);
6163 if (!face) 6162 if (!face)
6164 return base_face_id; 6163 return base_face_id;
6165 merge_face_vectors (f, face->lface, attrs, 0); 6164 merge_face_vectors (f, face->lface, attrs, 0);
@@ -6279,7 +6278,7 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
6279 { 6278 {
6280 struct face *face; 6279 struct face *face;
6281 CHECK_NUMBER (n); 6280 CHECK_NUMBER (n);
6282 face = FACE_OPT_FROM_ID (SELECTED_FRAME (), XINT (n)); 6281 face = FACE_FROM_ID_OR_NULL (SELECTED_FRAME (), XINT (n));
6283 if (face == NULL) 6282 if (face == NULL)
6284 error ("Not a valid face"); 6283 error ("Not a valid face");
6285 dump_realized_face (face); 6284 dump_realized_face (face);
diff --git a/src/xterm.c b/src/xterm.c
index 9fb19a16f60..76b92dfb839 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1062,7 +1062,7 @@ x_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
1062 struct frame *f = XFRAME (WINDOW_FRAME (w)); 1062 struct frame *f = XFRAME (WINDOW_FRAME (w));
1063 struct face *face; 1063 struct face *face;
1064 1064
1065 face = FACE_OPT_FROM_ID (f, VERTICAL_BORDER_FACE_ID); 1065 face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
1066 if (face) 1066 if (face)
1067 XSetForeground (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc, 1067 XSetForeground (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc,
1068 face->foreground); 1068 face->foreground);
@@ -1081,11 +1081,11 @@ static void
1081x_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1) 1081x_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
1082{ 1082{
1083 struct frame *f = XFRAME (WINDOW_FRAME (w)); 1083 struct frame *f = XFRAME (WINDOW_FRAME (w));
1084 struct face *face = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_FACE_ID); 1084 struct face *face = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FACE_ID);
1085 struct face *face_first 1085 struct face *face_first
1086 = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID); 1086 = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID);
1087 struct face *face_last 1087 struct face *face_last
1088 = FACE_OPT_FROM_ID (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID); 1088 = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID);
1089 unsigned long color = face ? face->foreground : FRAME_FOREGROUND_PIXEL (f); 1089 unsigned long color = face ? face->foreground : FRAME_FOREGROUND_PIXEL (f);
1090 unsigned long color_first = (face_first 1090 unsigned long color_first = (face_first
1091 ? face_first->foreground 1091 ? face_first->foreground
@@ -1507,7 +1507,7 @@ x_set_mouse_face_gc (struct glyph_string *s)
1507 1507
1508 /* What face has to be used last for the mouse face? */ 1508 /* What face has to be used last for the mouse face? */
1509 face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id; 1509 face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id;
1510 face = FACE_OPT_FROM_ID (s->f, face_id); 1510 face = FACE_FROM_ID_OR_NULL (s->f, face_id);
1511 if (face == NULL) 1511 if (face == NULL)
1512 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); 1512 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
1513 1513