[cairo-commit] cairo/src cairo-ft-font.c,1.106,1.107

Carl Worth commit at pdx.freedesktop.org
Tue Aug 23 00:00:44 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv13899/src

Modified Files:
	cairo-ft-font.c 
Log Message:

2005-08-22  Carl Worth  <cworth at cworth.org>

        Fix for bug #4192:

        * src/cairo-ft-font.c: (_font_map_release_face_lock_held): New
        function to handle both calling FT_Done_Face on unscaled->face and
        decrementing font_map->num_open_faces.

        * src/cairo-ft-font.c:
        (_cairo_ft_unscaled_font_map_destroy),
        (_cairo_ft_unscaled_font_destroy),
        (_cairo_ft_unscaled_font_lock_face): Call new
        _font_map_release_face_lock_held as approporiate.

        * src/cairo-ft-font.c: (_cairo_ft_unscaled_font_map_destroy):
        Assert that (font_map->num_open_faces == 0) when we're done, to
        help guarantee the bug is fixed.

        * src/cairo-ft-font.c: (_cairo_ft_unscaled_font_fini): Don't call
        FT_Done_Face anymore, instead assert that (unscaled->face == NULL)
        by the time this function is called.

        * src/cairo-ft-font.c: (_cairo_ft_unscaled_font_init),
        (_cairo_ft_unscaled_font_set_scale): Prefer TRUE/FALSE as values
        for cairo_bool_t have_scale.


Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- cairo-ft-font.c	23 Aug 2005 03:43:23 -0000	1.106
+++ cairo-ft-font.c	23 Aug 2005 07:00:42 -0000	1.107
@@ -152,6 +152,19 @@
 CAIRO_MUTEX_DECLARE(cairo_ft_unscaled_font_map_mutex);
 
 static void
+_font_map_release_face_lock_held (cairo_ft_unscaled_font_map_t *font_map,
+				  cairo_ft_unscaled_font_t *unscaled)
+{
+    if (unscaled->face) {
+	FT_Done_Face (unscaled->face);
+	unscaled->face = NULL;
+	unscaled->have_scale = FALSE;
+
+	font_map->num_open_faces--;
+    }
+}
+
+static void
 _cairo_ft_unscaled_font_map_create (void)
 {
     cairo_ft_unscaled_font_map_t *font_map;
@@ -210,10 +223,14 @@
 		break;
 	    _cairo_hash_table_remove (font_map->hash_table,
 				      &unscaled->base.hash_entry);
+
+	    _font_map_release_face_lock_held (font_map, unscaled);
 	    _cairo_ft_unscaled_font_fini (unscaled);
 	    free (unscaled);
 	}
 
+	assert (font_map->num_open_faces == 0);
+
 	FT_Done_FreeType (font_map->ft_library);
 
 	_cairo_hash_table_destroy (font_map->hash_table);
@@ -315,7 +332,7 @@
 	_cairo_ft_unscaled_font_init_key (unscaled, filename_copy, id);
     }
 
-    unscaled->have_scale = 0;
+    unscaled->have_scale = FALSE;
     unscaled->lock = 0;
     
     unscaled->faces = NULL;
@@ -329,18 +346,26 @@
     return unscaled_font->backend == &cairo_ft_unscaled_font_backend;
 }
 
+/**
+ * _cairo_ft_unscaled_font_fini:
+ * 
+ * Free all data associated with a cairo_ft_unscaled_font_t.
+ *
+ * CAUTION: The unscaled->face field must be NULL before calling this
+ * function. This is because the cairo_ft_unscaled_font_map keeps a
+ * count of these faces (font_map->num_open_faces) so it maintains the
+ * unscaled->face field while it has its lock held. See
+ * _font_map_release_face_lock_held().
+ **/
 static void
 _cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled)
 {
+    assert (unscaled->face == NULL);
+
     if (unscaled->filename) {
 	free (unscaled->filename);
 	unscaled->filename = NULL;
     }
-
-    if (unscaled->face) {
-	FT_Done_Face (unscaled->face);
-	unscaled->face = NULL;
-    }
 }
 
 static int
@@ -460,9 +485,10 @@
 	_cairo_hash_table_remove (font_map->hash_table,
 				  &unscaled->base.hash_entry);
 
-	_cairo_ft_unscaled_font_map_unlock ();
-
+	_font_map_release_face_lock_held (font_map, unscaled);
 	_cairo_ft_unscaled_font_fini (unscaled);
+
+	_cairo_ft_unscaled_font_map_unlock ();
     }
 }
 
@@ -507,11 +533,7 @@
 	if (entry == NULL)
 	    break;
 
-	FT_Done_Face (entry->face);
-	entry->face = NULL;
-	entry->have_scale = 0;
-
-	font_map->num_open_faces--;
+	_font_map_release_face_lock_held (font_map, entry);
     }
 
     if (FT_New_Face (font_map->ft_library,
@@ -593,7 +615,7 @@
 	scale->yy == unscaled->current_scale.yy)
 	return;
 
-    unscaled->have_scale = 1;
+    unscaled->have_scale = TRUE;
     unscaled->current_scale = *scale;
 	
     _compute_transform (&sf, scale);



More information about the cairo-commit mailing list