]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve GC+Cairo workaround
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 4 Apr 2018 17:59:09 +0000 (10:59 -0700)
committerEli Zaretskii <eliz@gnu.org>
Sat, 5 Jan 2019 09:53:04 +0000 (11:53 +0200)
Suggested by Eli Zaretskii (Bug#20890#31).
* src/font.h (font_data_structures_may_be_ill_formed): New function.
* src/ftfont.c (ftfont_close):
* src/ftcrfont.c (ftcrfont_close): Use it.

(cherry picked from commit d02fd482fbeaf6ed551e78223b538495cb0c3541)

src/font.h
src/ftcrfont.c
src/ftfont.c

index bb468333e8512e9796f24127e63f2927ab122e03..b6e43b0c9ca91070651a1fedefe7fb7af0314ec1 100644 (file)
@@ -948,6 +948,22 @@ extern void font_deferred_log (const char *, Lisp_Object, Lisp_Object);
       font_deferred_log ((ACTION), (ARG), (RESULT));   \
   } while (false)
 
+/* FIXME: This is for use in functions that can be called while
+   garbage-collecting, but which assume that Lisp data structures are
+   properly-formed.  This invalid assumption can lead to core dumps
+   (Bug#20890).  */
+INLINE bool
+font_data_structures_may_be_ill_formed (void)
+{
+#ifdef USE_CAIRO
+  /* Although this works around Bug#20890, it is probably not the
+     right thing to do.  */
+  return gc_in_progress;
+#else
+  return false;
+#endif
+}
+
 INLINE_HEADER_END
 
 #endif /* not EMACS_FONT_H */
index 0e3490c570e439cdd0b722c775ccb6b1fb52a4b7..62f44573a862e6843f6db7a470891e2ccfbeb1ee 100644 (file)
@@ -165,6 +165,9 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
 static void
 ftcrfont_close (struct font *font)
 {
+  if (font_data_structures_may_be_ill_formed ())
+    return;
+
   struct ftcrfont_info *ftcrfont_info = (struct ftcrfont_info *) font;
   int i;
 
index bdb1dff8cb94718bc0c9c47d3e68b49571a56bc4..823fb2095ce1963724feac63548681a790a099ca 100644 (file)
@@ -1243,15 +1243,8 @@ ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
 void
 ftfont_close (struct font *font)
 {
-  /* FIXME: Although this function can be called while garbage-collecting,
-     the function assumes that Lisp data structures are properly-formed.
-     This invalid assumption can lead to core dumps (Bug#20890).  */
-#ifdef USE_CAIRO
-  /* Although this works around Bug#20890, it is probably not the
-     right thing to do.  */
-  if (gc_in_progress)
+  if (font_data_structures_may_be_ill_formed ())
     return;
-#endif
 
   struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
   Lisp_Object val, cache;