[Fontconfig] [patch] using ref count in FcInit() and FcFinit()

Behdad Esfahbod behdad at behdad.org
Mon Apr 20 18:36:38 PDT 2009


On 04/20/2009 05:03 PM, Vincent Torri wrote:
>
> Hey
>
>>> to allow FcFini to be called the same number of times than FcInit, here
>>> is a patch that uses a ref count in these 2 functions.
>>
>> Comments below.
>>
>>> @@ -119,14 +121,20 @@ FcInit (void)
>>> {
>>> FcConfig *config;
>>>
>>> + if (!_fcInitCount)
>>> + {
>>> + if (_fcConfig)
>>> + return FcTrue;
>>> + config = FcInitLoadConfigAndFonts ();
>>> + if (!config)
>>> + return FcFalse;
>>> + FcConfigSetCurrent (config);
>>> + if (FcDebug()& FC_DBG_MEMORY)
>>> + FcMemReport ();
>>> + }
>>> +
>>> + _fcInitCount++;
>>> return FcTrue;
>>> }
>>
>> Currently one can do FcConfigDestroy(FcConfigGetCurrent()) to use a
>> brand new configuration (ie. reset the default configuration).
>> However, everytime doing that causes an internal invocation of
>> FcInit() and increasing the refcount. That's wrong. I think we need a
>> separate bool and a non-ref'ing _FcInit for the implicit
>> initialization. The implicit initialization should add up to only one
>> reference. Which is the one the unpaired FcFini() releases.
>>
>> Also, the two return paths in the conditional do not increase the
>> refcount and are hence wrong. For example, if one does a
>> FcConfigSetCurrent(), then the ref count will never increase and stay
>> at zero.
>>
>> Fix those and I'll happily commit this :).
>
> i actually don't know all that internal code of fontconfig. If it's easy
> for you, then please add such refcounting. It will take me a lot of time
> (and i don't have a lot, as i already work on several projects)

Well, I'm busy with other projects too.  Please file a bug at 
bugs.freedesktop.org and attach the patch and my comments, and I'll eventually 
fix it.

behdad

> regards
>
> Vincent Torri


More information about the Fontconfig mailing list