From 4e6a86c633a4ca3084a7bc30101f8b4acdd38d28 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 15 Aug 2012 18:20:16 +0400 Subject: [PATCH] Generalize and cleanup font subsystem checks. * font.h (FONT_DEBUG, font_assert): Remove. * font.c, fontset.c, w32font.c, xfont.c, xftfont.c: Change font_assert to eassert. Use eassert where appropriate. --- src/ChangeLog | 7 +++++++ src/font.c | 48 ++++++++++++++++++++++-------------------------- src/font.h | 6 ------ src/fontset.c | 6 ++---- src/w32font.c | 9 +++------ src/xfont.c | 2 +- src/xftfont.c | 3 +-- 7 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e45b4de48d..eb19fad9ab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-08-15 Dmitry Antipov + + Generalize and cleanup font subsystem checks. + * font.h (FONT_DEBUG, font_assert): Remove. + * font.c, fontset.c, w32font.c, xfont.c, xftfont.c: Change + font_assert to eassert. Use eassert where appropriate. + 2012-08-15 Dmitry Antipov * gtkutil.c (xg_get_font): Use pango_units_to_double. diff --git a/src/font.c b/src/font.c index 4520d9bc9a..c3040b8aa3 100644 --- a/src/font.c +++ b/src/font.c @@ -290,7 +290,7 @@ font_pixel_size (FRAME_PTR f, Lisp_Object spec) return XINT (size); if (NILP (size)) return 0; - font_assert (FLOATP (size)); + eassert (FLOATP (size)); point_size = XFLOAT_DATA (size); val = AREF (spec, FONT_DPI_INDEX); if (INTEGERP (val)) @@ -354,8 +354,7 @@ font_style_to_value (enum font_property_index prop, Lisp_Object val, int noerror } if (! noerror) return -1; - if (len == 255) - abort (); + eassert (len < 255); elt = Fmake_vector (make_number (2), make_number (100)); ASET (elt, 1, val); args[0] = table; @@ -404,10 +403,10 @@ font_style_symbolic (Lisp_Object font, enum font_property_index prop, int for_fa table = AREF (font_style_table, prop - FONT_WEIGHT_INDEX); CHECK_VECTOR (table); i = XINT (val) & 0xFF; - font_assert (((i >> 4) & 0xF) < ASIZE (table)); + eassert (((i >> 4) & 0xF) < ASIZE (table)); elt = AREF (table, ((i >> 4) & 0xF)); CHECK_VECTOR (elt); - font_assert ((i & 0xF) + 1 < ASIZE (elt)); + eassert ((i & 0xF) + 1 < ASIZE (elt)); elt = (for_face ? AREF (elt, 1) : AREF (elt, (i & 0xF) + 1)); CHECK_SYMBOL (elt); return elt; @@ -1076,7 +1075,7 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) { double point_size = -1; - font_assert (FONT_SPEC_P (font)); + eassert (FONT_SPEC_P (font)); p = f[XLFD_POINT_INDEX]; if (*p == '[') point_size = parse_matrix (p); @@ -1197,7 +1196,7 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes) Lisp_Object val; int i, j, len; - font_assert (FONTP (font)); + eassert (FONTP (font)); for (i = FONT_FOUNDRY_INDEX, j = XLFD_FOUNDRY_INDEX; i <= FONT_REGISTRY_INDEX; i++, j++) @@ -1248,7 +1247,7 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes) } val = AREF (font, FONT_SIZE_INDEX); - font_assert (NUMBERP (val) || NILP (val)); + eassert (NUMBERP (val) || NILP (val)); if (INTEGERP (val)) { EMACS_INT v = XINT (val); @@ -1585,8 +1584,7 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes) } else { - if (! FLOATP (val)) - abort (); + eassert (FLOATP (val)); pixel_size = -1; point_size = (int) XFLOAT_DATA (val); } @@ -2540,7 +2538,7 @@ font_finish_cache (FRAME_PTR f, struct font_driver *driver) val = XCDR (cache); while (CONSP (val) && ! EQ (XCAR (XCAR (val)), driver->type)) cache = val, val = XCDR (val); - font_assert (! NILP (val)); + eassert (! NILP (val)); tmp = XCDR (XCAR (val)); XSETCAR (tmp, make_number (XINT (XCAR (tmp)) - 1)); if (XINT (XCAR (tmp)) == 0) @@ -2557,9 +2555,9 @@ font_get_cache (FRAME_PTR f, struct font_driver *driver) Lisp_Object val = driver->get_cache (f); Lisp_Object type = driver->type; - font_assert (CONSP (val)); + eassert (CONSP (val)); for (val = XCDR (val); ! EQ (XCAR (XCAR (val)), type); val = XCDR (val)); - font_assert (CONSP (val)); + eassert (CONSP (val)); /* VAL = ((DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...) ...) */ val = XCDR (XCAR (val)); return val; @@ -2596,7 +2594,7 @@ font_clear_cache (FRAME_PTR f, Lisp_Object cache, struct font_driver *driver) if (! NILP (AREF (val, FONT_TYPE_INDEX))) { - font_assert (font && driver == font->driver); + eassert (font && driver == font->driver); driver->close (f, font); num_fonts--; } @@ -2706,7 +2704,7 @@ font_list_entities (Lisp_Object frame, Lisp_Object spec) int need_filtering = 0; int i; - font_assert (FONT_SPEC_P (spec)); + eassert (FONT_SPEC_P (spec)); if (INTEGERP (AREF (spec, FONT_SIZE_INDEX))) size = XINT (AREF (spec, FONT_SIZE_INDEX)); @@ -2826,7 +2824,7 @@ font_open_entity (FRAME_PTR f, Lisp_Object entity, int pixel_size) int min_width, height; int scaled_pixel_size = pixel_size; - font_assert (FONT_ENTITY_P (entity)); + eassert (FONT_ENTITY_P (entity)); size = AREF (entity, FONT_SIZE_INDEX); if (XINT (size) != 0) scaled_pixel_size = pixel_size = XINT (size); @@ -2903,7 +2901,7 @@ font_close_object (FRAME_PTR f, Lisp_Object font_object) FONT_ADD_LOG ("close", font_object, Qnil); font->driver->close (f, font); #ifdef HAVE_WINDOW_SYSTEM - font_assert (FRAME_X_DISPLAY_INFO (f)->n_fonts); + eassert (FRAME_X_DISPLAY_INFO (f)->n_fonts); FRAME_X_DISPLAY_INFO (f)->n_fonts--; #endif num_fonts--; @@ -2933,7 +2931,7 @@ font_has_char (FRAME_PTR f, Lisp_Object font, int c) return driver_list->driver->has_char (font, c); } - font_assert (FONT_OBJECT_P (font)); + eassert (FONT_OBJECT_P (font)); fontp = XFONT_OBJECT (font); if (fontp->driver->has_char) { @@ -2953,7 +2951,7 @@ font_encode_char (Lisp_Object font_object, int c) { struct font *font; - font_assert (FONT_OBJECT_P (font_object)); + eassert (FONT_OBJECT_P (font_object)); font = XFONT_OBJECT (font_object); return font->driver->encode_char (font, c); } @@ -2964,7 +2962,7 @@ font_encode_char (Lisp_Object font_object, int c) Lisp_Object font_get_name (Lisp_Object font_object) { - font_assert (FONT_OBJECT_P (font_object)); + eassert (FONT_OBJECT_P (font_object)); return AREF (font_object, FONT_NAME_INDEX); } @@ -3250,10 +3248,8 @@ font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_O { struct face *def = FACE_FROM_ID (f, DEFAULT_FACE_ID); Lisp_Object height = def->lface[LFACE_HEIGHT_INDEX]; - if (INTEGERP (height)) - pt = XINT (height); - else - abort (); /* We should never end up here. */ + eassert (INTEGERP (height)); + pt = XINT (height); } pt /= 10; @@ -3728,7 +3724,7 @@ font_range (ptrdiff_t pos, ptrdiff_t *limit, struct window *w, struct face *face } else { - font_assert (face); + eassert (face); pos_byte = string_char_to_byte (string, pos); } @@ -4268,7 +4264,7 @@ DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0, while (! NILP (val) && ! EQ (XCAR (XCAR (val)), driver_list->driver->type)) val = XCDR (val); - font_assert (! NILP (val)); + eassert (! NILP (val)); tmp = XCDR (XCAR (val)); if (XINT (XCAR (tmp)) == 0) { diff --git a/src/font.h b/src/font.h index 2e374571c6..3e9af6df23 100644 --- a/src/font.h +++ b/src/font.h @@ -858,10 +858,4 @@ extern void font_deferred_log (const char *, Lisp_Object, Lisp_Object); font_deferred_log ((ACTION), (ARG), (RESULT)); \ } while (0) -#ifdef FONT_DEBUG -#define font_assert(X) do {if (!(X)) abort ();} while (0) -#else /* not FONT_DEBUG */ -#define font_assert(X) (void) 0 -#endif /* not FONT_DEBUG */ - #endif /* not EMACS_FONT_H */ diff --git a/src/fontset.c b/src/fontset.c index d4ce8b08ea..3c7e931d12 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -1027,8 +1027,7 @@ make_fontset_for_ascii_face (FRAME_PTR f, int base_fontset_id, struct face *face base_fontset = FONTSET_FROM_ID (base_fontset_id); if (!BASE_FONTSET_P (base_fontset)) base_fontset = FONTSET_BASE (base_fontset); - if (! BASE_FONTSET_P (base_fontset)) - abort (); + eassert (BASE_FONTSET_P (base_fontset)); } else base_fontset = Vdefault_fontset; @@ -1725,8 +1724,7 @@ fontset_from_font (Lisp_Object font_object) fontset_spec = copy_font_spec (font_spec); ASET (fontset_spec, FONT_REGISTRY_INDEX, alias); name = Ffont_xlfd_name (fontset_spec, Qnil); - if (NILP (name)) - abort (); + eassert (!NILP (name)); fontset = make_fontset (Qnil, name, Qnil); Vfontset_alias_alist = Fcons (Fcons (name, SYMBOL_NAME (alias)), Vfontset_alias_alist); diff --git a/src/w32font.c b/src/w32font.c index 59dab789ab..cfd453282d 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -234,8 +234,7 @@ get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw) s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc) GetProcAddress (hm_unicows, "GetOutlineTextMetricsW"); } - if (s_pfn_Get_Outline_Text_MetricsW == NULL) - abort (); /* cannot happen */ + eassert (s_pfn_Get_Outline_Text_MetricsW != NULL); return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw); } @@ -252,8 +251,7 @@ get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw) s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc) GetProcAddress (hm_unicows, "GetTextMetricsW"); } - if (s_pfn_Get_Text_MetricsW == NULL) - abort (); /* cannot happen */ + eassert (s_pfn_Get_Text_MetricsW != NULL); return s_pfn_Get_Text_MetricsW (hdc, lptmw); } @@ -271,8 +269,7 @@ get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc) GetProcAddress (hm_unicows, "GetGlyphOutlineW"); } - if (s_pfn_Get_Glyph_OutlineW == NULL) - abort (); /* cannot happen */ + eassert (s_pfn_Get_Glyph_OutlineW != NULL); return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer, lpmat2); } diff --git a/src/xfont.c b/src/xfont.c index e3e2eb18c2..9e929eed67 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -59,7 +59,7 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b) /* The result metric information. */ XCharStruct *pcm = NULL; - font_assert (xfont && char2b); + eassert (xfont && char2b); if (xfont->per_char != NULL) { diff --git a/src/xftfont.c b/src/xftfont.c index f999ac662c..2f8125393b 100644 --- a/src/xftfont.c +++ b/src/xftfont.c @@ -622,8 +622,7 @@ xftfont_get_xft_draw (FRAME_PTR f) FRAME_X_VISUAL (f), FRAME_X_COLORMAP (f)); UNBLOCK_INPUT; - if (! xft_draw) - abort (); + eassert (xft_draw != NULL); font_put_frame_data (f, &xftfont_driver, xft_draw); } return xft_draw; -- 2.20.1