Fix for bug #4192:

New function to handle both calling FT_Done_Face on unscaled->face and decrementing font_map->num_open_faces.
Call new _font_map_release_face_lock_held as approporiate.
Assert that (font_map->num_open_faces == 0) when we're done, to help guarantee the bug is fixed.
Don't call FT_Done_Face anymore, instead assert that (unscaled->face == NULL) by the time this function is called.
Prefer TRUE/FALSE as values for cairo_bool_t have_scale.
This commit is contained in:
Carl Worth 2005-08-23 00:00:42 +00:00
parent dc907490e3
commit c0bbf9ac08
2 changed files with 62 additions and 14 deletions

View file

@ -1,3 +1,29 @@
2005-08-22 Carl Worth <cworth@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.
2005-08-22 Billy Biggs <vektor@dumbterm.net>
* doc/public/Makefile.am: Add version.xml to content_files

View file

@ -151,6 +151,19 @@ static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL;
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)
{
@ -210,10 +223,14 @@ _cairo_ft_unscaled_font_map_destroy (void)
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 (cairo_ft_unscaled_font_t *unscaled,
_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 @@ _cairo_unscaled_font_is_ft (cairo_unscaled_font_t *unscaled_font)
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_ft_unscaled_font_destroy (void *abstract_font)
_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 @@ _cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled)
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 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
scale->yy == unscaled->current_scale.yy)
return;
unscaled->have_scale = 1;
unscaled->have_scale = TRUE;
unscaled->current_scale = *scale;
_compute_transform (&sf, scale);