Vincent Torri
2009-Apr-20 05:39 UTC
[Fontconfig] [patch] using ref count in FcInit() and FcFinit()
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. regards Vincent Torri -------------- next part -------------- A non-text attachment was scrubbed... Name: fc_init.diff Type: text/x-diff Size: 1300 bytes Desc: Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20090420/8813cb8c/attachment.diff
Behdad Esfahbod
2009-Apr-20 15:33 UTC
[Fontconfig] [patch] using ref count in FcInit() and FcFinit()
On 04/20/2009 01:39 AM, Vincent Torri wrote:> > HeyHey,> 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 :). behdad
Vincent Torri
2009-Apr-20 21:03 UTC
[Fontconfig] [patch] using ref count in FcInit() and FcFinit()
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) regards Vincent Torri
Behdad Esfahbod
2009-Apr-21 01:36 UTC
[Fontconfig] [patch] using ref count in FcInit() and FcFinit()
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