summaryrefslogtreecommitdiff
path: root/pango/pangofc-font.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2012-08-29 09:54:19 -0400
committerBehdad Esfahbod <behdad@behdad.org>2012-08-29 09:54:37 -0400
commitaca468cdc2ea66ce6dc8cfc70424a2c5309354fa (patch)
treeadf450f5f8425b4e9ca5b1f4acbd932844a66a55 /pango/pangofc-font.c
parente6563310424563f60d8acebc093c7e1d7a2fa58b (diff)
downloadpango-aca468cdc2ea66ce6dc8cfc70424a2c5309354fa.tar.gz
Port pangofc-font.c to GWeakRef
Diffstat (limited to 'pango/pangofc-font.c')
-rw-r--r--pango/pangofc-font.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index f45298ab..9e0ea5d7 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -45,7 +45,6 @@ struct _PangoFcFontPrivate
PangoFcDecoder *decoder;
PangoFcFontKey *key;
PangoFcCmapCache *cmap_cache;
- gboolean has_weak_pointer; /* have set a weak_pointer from fontmap to us */
};
static gboolean pango_fc_font_real_has_char (PangoFcFont *font,
@@ -136,19 +135,17 @@ pango_fc_font_finalize (GObject *object)
{
PangoFcFont *fcfont = PANGO_FC_FONT (object);
PangoFcFontPrivate *priv = fcfont->priv;
+ PangoFcFontMap *fontmap;
g_slist_foreach (fcfont->metrics_by_lang, (GFunc)free_metrics_info, NULL);
g_slist_free (fcfont->metrics_by_lang);
- if (fcfont->fontmap)
+ fontmap = g_weak_ref_get ((GWeakRef *) &fcfont->fontmap);
+ if (fontmap)
{
_pango_fc_font_map_remove (PANGO_FC_FONT_MAP (fcfont->fontmap), fcfont);
- if (priv->has_weak_pointer)
- {
- priv->has_weak_pointer = FALSE;
- g_object_remove_weak_pointer (G_OBJECT (fcfont->fontmap), (gpointer *) (gpointer) &fcfont->fontmap);
- }
- fcfont->fontmap = NULL;
+ g_weak_ref_clear ((GWeakRef *) &fcfont->fontmap);
+ g_object_unref (fontmap);
}
FcPatternDestroy (fcfont->font_pattern);
@@ -227,13 +224,7 @@ pango_fc_font_set_property (GObject *object,
PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (g_value_get_object (value));
g_return_if_fail (fcfont->fontmap == NULL);
- fcfont->fontmap = (PangoFontMap *) fcfontmap;
- if (fcfont->fontmap)
- {
- PangoFcFontPrivate *priv = fcfont->priv;
- priv->has_weak_pointer = TRUE;
- g_object_add_weak_pointer (G_OBJECT (fcfont->fontmap), (gpointer *) (gpointer) &fcfont->fontmap);
- }
+ g_weak_ref_set ((GWeakRef *) &fcfont->fontmap, fcfontmap);
}
goto set_decoder;
@@ -267,7 +258,10 @@ pango_fc_font_get_property (GObject *object,
case PROP_FONTMAP:
{
PangoFcFont *fcfont = PANGO_FC_FONT (object);
- g_value_set_object (value, fcfont->fontmap);
+ PangoFontMap *fontmap = g_weak_ref_get ((GWeakRef *) &fcfont->fontmap);
+ g_value_set_object (value, fontmap);
+ if (fontmap)
+ g_object_unref (fontmap);
}
break;
default:
@@ -331,6 +325,8 @@ pango_fc_font_get_coverage (PangoFont *font,
PangoFcFont *fcfont = (PangoFcFont *)font;
PangoFcFontPrivate *priv = fcfont->priv;
FcCharSet *charset;
+ PangoFcFontMap *fontmap;
+ PangoCoverage *coverage;
if (priv->decoder)
{
@@ -338,11 +334,13 @@ pango_fc_font_get_coverage (PangoFont *font,
return _pango_fc_font_map_fc_to_coverage (charset);
}
- if (!fcfont->fontmap)
+ fontmap = g_weak_ref_get ((GWeakRef *) &fcfont->fontmap);
+ if (!fontmap)
return pango_coverage_new ();
- return _pango_fc_font_map_get_coverage (PANGO_FC_FONT_MAP (fcfont->fontmap),
- fcfont);
+ coverage = _pango_fc_font_map_get_coverage (fontmap, fcfont);
+ g_object_unref (fontmap);
+ return coverage;
}
/* For Xft, it would be slightly more efficient to simply to
@@ -540,11 +538,9 @@ pango_fc_font_get_metrics (PangoFont *font,
PangoFontMap *fontmap;
PangoContext *context;
- /* XXX this is racy. because weakref's are racy... */
- fontmap = fcfont->fontmap;
+ fontmap = g_weak_ref_get ((GWeakRef *) &fcfont->fontmap);
if (!fontmap)
return pango_font_metrics_new ();
- fontmap = g_object_ref (fontmap);
info = g_slice_new0 (PangoFcMetricsInfo);
@@ -591,6 +587,7 @@ pango_fc_font_get_font_map (PangoFont *font)
{
PangoFcFont *fcfont = PANGO_FC_FONT (font);
+ /* MT-unsafe. Oh well... The API is unsafe. */
return fcfont->fontmap;
}
@@ -621,8 +618,13 @@ pango_fc_font_real_get_glyph (PangoFcFont *font,
if (G_UNLIKELY (priv->cmap_cache == NULL))
{
- priv->cmap_cache = _pango_fc_font_map_get_cmap_cache ((PangoFcFontMap *) font->fontmap,
- font);
+ PangoFcFontMap *fontmap = g_weak_ref_get ((GWeakRef *) &font->fontmap);
+ if (G_UNLIKELY (!fontmap))
+ return 0;
+
+ priv->cmap_cache = _pango_fc_font_map_get_cmap_cache (fontmap, font);
+
+ g_object_unref (fontmap);
if (G_UNLIKELY (!priv->cmap_cache))
return 0;