From 78e0b35c45892995da596c65759fdece3e67129d Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 25 Oct 2013 10:55:36 +0400 Subject: [PATCH] Omit unused frame argument of font API's close function. * font.h (struct font): Drop frame argument. Adjust comment. * font.c (font_clear_cache, font_close_object): Adjust users. * ftfont.c (ftfont_close): * ftxfont.c (ftxfont_close): * macfont.m (macfont_close): * nsfont.m (nsfont_close): * w32font.c (w32font_close): * xfont.c (xfont_close): * xftfont.c (xftfont_close): Adjust driver-specific close functions, tweak comments and make functions safe if called more than once for the same font object. --- src/ChangeLog | 15 +++++++++++++++ src/font.c | 4 ++-- src/font.h | 4 ++-- src/ftfont.c | 4 ++-- src/ftxfont.c | 4 ++-- src/macfont.m | 35 ++++++++++++++++++++--------------- src/nsfont.m | 37 +++++++++++++++++++------------------ src/w32font.c | 30 +++++++++++++++--------------- src/xfont.c | 16 +++++++++++----- src/xftfont.c | 20 ++++++++++++++------ 10 files changed, 102 insertions(+), 67 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6da470c38ee..cd31196a15a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2013-10-25 Dmitry Antipov + + Omit unused frame argument of font API's close function. + * font.h (struct font): Drop frame argument. Adjust comment. + * font.c (font_clear_cache, font_close_object): Adjust users. + * ftfont.c (ftfont_close): + * ftxfont.c (ftxfont_close): + * macfont.m (macfont_close): + * nsfont.m (nsfont_close): + * w32font.c (w32font_close): + * xfont.c (xfont_close): + * xftfont.c (xftfont_close): Adjust driver-specific close + functions, tweak comments and make functions safe if called + more than once for the same font object. + 2013-10-24 Glenn Morris * Makefile.in (abs_top_srcdir): New, set by configure. diff --git a/src/font.c b/src/font.c index 68db9f2ef2d..aaa02c20e48 100644 --- a/src/font.c +++ b/src/font.c @@ -2591,7 +2591,7 @@ font_clear_cache (struct frame *f, Lisp_Object cache, struct font_driver *driver if (! NILP (AREF (val, FONT_TYPE_INDEX))) { eassert (font && driver == font->driver); - driver->close (f, font); + driver->close (font); } } if (driver->free_entity) @@ -2892,7 +2892,7 @@ font_close_object (struct frame *f, Lisp_Object font_object) /* Already closed. */ return; FONT_ADD_LOG ("close", font_object, Qnil); - font->driver->close (f, font); + font->driver->close (font); #ifdef HAVE_WINDOW_SYSTEM eassert (FRAME_DISPLAY_INFO (f)->n_fonts); FRAME_DISPLAY_INFO (f)->n_fonts--; diff --git a/src/font.h b/src/font.h index 0ec56590916..9285330ce54 100644 --- a/src/font.h +++ b/src/font.h @@ -545,8 +545,8 @@ struct font_driver Lisp_Object (*open) (struct frame *f, Lisp_Object font_entity, int pixel_size); - /* Close FONT on frame F. */ - void (*close) (struct frame *f, struct font *font); + /* Close FONT. */ + void (*close) (struct font *font); /* Optional (if FACE->extra is not used). Prepare FACE for displaying characters by FONT on frame F by diff --git a/src/ftfont.c b/src/ftfont.c index eeee56891ec..224b8e82500 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -498,7 +498,7 @@ static Lisp_Object ftfont_list (struct frame *, Lisp_Object); static Lisp_Object ftfont_match (struct frame *, Lisp_Object); static Lisp_Object ftfont_list_family (struct frame *); static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); -static void ftfont_close (struct frame *, struct font *); +static void ftfont_close (struct font *); static int ftfont_has_char (Lisp_Object, int); static unsigned ftfont_encode_char (struct font *, int); static int ftfont_text_extents (struct font *, unsigned *, int, @@ -1317,7 +1317,7 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) } static void -ftfont_close (struct frame *f, struct font *font) +ftfont_close (struct font *font) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; Lisp_Object val, cache; diff --git a/src/ftxfont.c b/src/ftxfont.c index 63d03b0e244..8050f292600 100644 --- a/src/ftxfont.c +++ b/src/ftxfont.c @@ -260,9 +260,9 @@ ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size) } static void -ftxfont_close (struct frame *f, struct font *font) +ftxfont_close (struct font *font) { - ftfont_driver.close (f, font); + ftfont_driver.close (font); } static int diff --git a/src/macfont.m b/src/macfont.m index b3bf96d8c4e..150aca07651 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -1518,7 +1518,7 @@ static Lisp_Object macfont_match (struct frame *, Lisp_Object); static Lisp_Object macfont_list_family (struct frame *); static void macfont_free_entity (Lisp_Object); static Lisp_Object macfont_open (struct frame *, Lisp_Object, int); -static void macfont_close (struct frame *, struct font *); +static void macfont_close (struct font *); static int macfont_has_char (Lisp_Object, int); static unsigned macfont_encode_char (struct font *, int); static int macfont_text_extents (struct font *, unsigned int *, int, @@ -2580,23 +2580,28 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) } static void -macfont_close (struct frame * f, struct font *font) +macfont_close (struct font *font) { struct macfont_info *macfont_info = (struct macfont_info *) font; - int i; - block_input (); - CFRelease (macfont_info->macfont); - CGFontRelease (macfont_info->cgfont); - if (macfont_info->screen_font) - CFRelease (macfont_info->screen_font); - macfont_release_cache (macfont_info->cache); - for (i = 0; i < macfont_info->metrics_nrows; i++) - if (macfont_info->metrics[i]) - xfree (macfont_info->metrics[i]); - if (macfont_info->metrics) - xfree (macfont_info->metrics); - unblock_input (); + if (macfont_info->cache) + { + int i; + + block_input (); + CFRelease (macfont_info->macfont); + CGFontRelease (macfont_info->cgfont); + if (macfont_info->screen_font) + CFRelease (macfont_info->screen_font); + macfont_release_cache (macfont_info->cache); + macfont_info->cache = NULL; + for (i = 0; i < macfont_info->metrics_nrows; i++) + if (macfont_info->metrics[i]) + xfree (macfont_info->metrics[i]); + if (macfont_info->metrics) + xfree (macfont_info->metrics); + unblock_input (); + } } static int diff --git a/src/nsfont.m b/src/nsfont.m index bd9a2acc983..58663804a2f 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -624,7 +624,7 @@ static Lisp_Object nsfont_match (struct frame *, Lisp_Object); static Lisp_Object nsfont_list_family (struct frame *); static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size); -static void nsfont_close (struct frame *f, struct font *font); +static void nsfont_close (struct font *font); static int nsfont_has_char (Lisp_Object entity, int c); static unsigned int nsfont_encode_char (struct font *font, int c); static int nsfont_text_extents (struct font *font, unsigned int *code, @@ -929,29 +929,30 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size) } -/* Close FONT on frame F. */ +/* Close FONT. */ static void -nsfont_close (struct frame *f, struct font *font) +nsfont_close (struct font *font) { - struct nsfont_info *font_info = (struct nsfont_info *)font; - int i; - - /* FIXME: this occurs apparently due to same failure to detect same font - that causes need for cache in nsfont_open () */ - if (!font_info) - return; + struct nsfont_info *font_info = (struct nsfont_info *) font; - for (i =0; i<0x100; i++) + /* FIXME: font_info may be NULL due to same failure to detect + same font that causes need for cache in nsfont_open. */ + if (font_info && font_info->name) { - xfree (font_info->glyphs[i]); - xfree (font_info->metrics[i]); - } - [font_info->nsfont release]; + int i; + + for (i = 0; i < 0x100; i++) + { + xfree (font_info->glyphs[i]); + xfree (font_info->metrics[i]); + } + [font_info->nsfont release]; #ifdef NS_IMPL_COCOA - CGFontRelease (font_info->cgfont); + CGFontRelease (font_info->cgfont); #endif - xfree (font_info->name); - xfree (font_info); + xfree (font_info->name); + font_info->name = NULL; + } } diff --git a/src/w32font.c b/src/w32font.c index 845df68f09d..dd21aca2fa1 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -376,26 +376,26 @@ w32font_open (struct frame *f, Lisp_Object font_entity, int pixel_size) return font_object; } -/* w32 implementation of close for font_backend. - Close FONT on frame F. */ +/* w32 implementation of close for font_backend. */ void -w32font_close (struct frame *f, struct font *font) +w32font_close (struct font *font) { - int i; struct w32font_info *w32_font = (struct w32font_info *) font; - /* Delete the GDI font object. */ - DeleteObject (w32_font->hfont); - - /* Free all the cached metrics. */ - if (w32_font->cached_metrics) + if (w32_font->hfont) { - for (i = 0; i < w32_font->n_cache_blocks; i++) - { - xfree (w32_font->cached_metrics[i]); - } - xfree (w32_font->cached_metrics); - w32_font->cached_metrics = NULL; + /* Delete the GDI font object. */ + DeleteObject (w32_font->hfont); + w32_font->hfont = NULL; + + /* Free all the cached metrics. */ + if (w32_font->cached_metrics) + { + for (i = 0; i < w32_font->n_cache_blocks; i++) + xfree (w32_font->cached_metrics[i]); + xfree (w32_font->cached_metrics); + w32_font->cached_metrics = NULL; + } } } diff --git a/src/xfont.c b/src/xfont.c index c5b8db3830c..1f87fb8783e 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -119,7 +119,7 @@ static Lisp_Object xfont_list (struct frame *, Lisp_Object); static Lisp_Object xfont_match (struct frame *, Lisp_Object); static Lisp_Object xfont_list_family (struct frame *); static Lisp_Object xfont_open (struct frame *, Lisp_Object, int); -static void xfont_close (struct frame *, struct font *); +static void xfont_close (struct font *); static int xfont_prepare_face (struct frame *, struct face *); static int xfont_has_char (Lisp_Object, int); static unsigned xfont_encode_char (struct font *, int); @@ -890,11 +890,17 @@ xfont_open (struct frame *f, Lisp_Object entity, int pixel_size) } static void -xfont_close (struct frame *f, struct font *font) +xfont_close (struct font *font) { - block_input (); - XFreeFont (FRAME_X_DISPLAY (f), ((struct xfont_info *) font)->xfont); - unblock_input (); + struct xfont_info *xfi = (struct xfont_info *) font; + + if (xfi->xfont) + { + block_input (); + XFreeFont (xfi->display, xfi->xfont); + unblock_input (); + xfi->xfont = NULL; + } } static int diff --git a/src/xftfont.c b/src/xftfont.c index f2b4c2abe2b..1e03dd320fe 100644 --- a/src/xftfont.c +++ b/src/xftfont.c @@ -486,18 +486,26 @@ xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size) } static void -xftfont_close (struct frame *f, struct font *font) +xftfont_close (struct font *font) { struct xftfont_info *xftfont_info = (struct xftfont_info *) font; #ifdef HAVE_LIBOTF if (xftfont_info->otf) - OTF_close (xftfont_info->otf); + { + OTF_close (xftfont_info->otf); + xftfont_info->otf = NULL; + } #endif - block_input (); - XftUnlockFace (xftfont_info->xftfont); - XftFontClose (xftfont_info->display, xftfont_info->xftfont); - unblock_input (); + + if (xftfont_info->xftfont) + { + block_input (); + XftUnlockFace (xftfont_info->xftfont); + XftFontClose (xftfont_info->display, xftfont_info->xftfont); + unblock_input (); + xftfont_info->xftfont = NULL; + } } static int -- 2.39.2