]> git.eshelyaron.com Git - emacs.git/commitdiff
Omit unused frame argument of font API's close function.
authorDmitry Antipov <dmantipov@yandex.ru>
Fri, 25 Oct 2013 06:55:36 +0000 (10:55 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Fri, 25 Oct 2013 06:55:36 +0000 (10:55 +0400)
* 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
src/font.c
src/font.h
src/ftfont.c
src/ftxfont.c
src/macfont.m
src/nsfont.m
src/w32font.c
src/xfont.c
src/xftfont.c

index 6da470c38eec02d6e54a8afad2a7998df69aef3f..cd31196a15a5c5600416a7190afd404a96eb0321 100644 (file)
@@ -1,3 +1,18 @@
+2013-10-25  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       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  <rgm@gnu.org>
 
        * Makefile.in (abs_top_srcdir): New, set by configure.
index 68db9f2ef2dbdac1c47167042477066e95d80b92..aaa02c20e485ae8b802f6b75d64c43ca47fe76d5 100644 (file)
@@ -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--;
index 0ec56590916a590730dfb32fe01b0139ce3afffc..9285330ce545559a3ac5cbc131caf20173921a70 100644 (file)
@@ -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
index eeee56891ecc7b54e438a5feeae19be0926a9da7..224b8e82500be21e116093bc51be346e4138cd9e 100644 (file)
@@ -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;
index 63d03b0e2440fa7918045098b402353c5dee9c62..8050f292600a53474fadb2f0a5e6f6097056fc0d 100644 (file)
@@ -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
index b3bf96d8c4e0e864e0afec3248f5bc2a7b2e6629..150aca0765114f30d9ab1075b2ea44c386795d5f 100644 (file)
@@ -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
index bd9a2acc983eac2881dbd4c872be2115056c28db..58663804a2fe6a8aed58bfaf9ff08865e9adb8ac 100644 (file)
@@ -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;
+    }
 }
 
 
index 845df68f09db34612e859229097c79ecac512535..dd21aca2fa101fa2e56ec25b87e19575ca451c87 100644 (file)
@@ -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;
+       }
     }
 }
 
index c5b8db3830ccf88f46cfe0cf8a02e0ed79c23f47..1f87fb8783e05a172c219af334f244389cb6c492 100644 (file)
@@ -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
index f2b4c2abe2bcdfd511fa83a14aa0f6356f60a25a..1e03dd320fe337ecf80bf64fddf10006ad06e263 100644 (file)
@@ -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