[HarfBuzz] Static initialization of C++ classes in harfbuzz
Petr Kobalíček
kobalicek.petr at gmail.com
Sat Jan 7 14:08:41 PST 2012
Hi Martin,
so you agree that it should be controlled/removed, right?
Thanks!
Petr
On Sat, Jan 7, 2012 at 10:16 PM, Evan Martin <evan at chromium.org> wrote:
> I know of one project (Chrome) that is trying to make it a
> compile-time error if you have any static initializers.
>
> http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html
> discusses more of the reasons why.
>
> On Sat, Jan 7, 2012 at 9:40 AM, Petr Kobalíček <kobalicek.petr at gmail.com> wrote:
>> Hi list,
>>
>> While porting harfbuzz to be used with Fog I encountered that the
>> static initialization of some C++ classes (global mutex and langs
>> list) happened before Fog and this caused runtime error which I'm
>> unable to fix without making changes to harfbuzz. Static
>> initialization is unpredictable and the behavior is different across
>> C++ compilers.
>>
>> There is no way how to fix this error without making changes to
>> harfbuzz and I fixed it using initialization functions called:
>>
>> - hb_init()
>> - hb_shutdown()
>>
>> These functions can be called from static class if the static
>> initialization behavior is preferred:
>>
>> class HbInitializer
>> {
>> HbInitializer() { hb_init(); }
>> ~HbInitializer() { hb_shutdown(); }
>> } hb_initializer;
>>
>> or separately by using my code.
>>
>> The question is: Is this good idea to include in harfbuzz or I should
>> keep my changes in Fog, making this change internal and not visible to
>> the master?
>>
>> Because if designed in such way, one can use something like:
>>
>> #if !defined(HB_NO_STATIC_INIT)
>> class HbInitializer
>> {
>> HbInitializer() { hb_init(); }
>> ~HbInitializer() { hb_shutdown(); }
>> } hb_initializer;
>> #endif /* HB_NO_STATIC_INIT */
>>
>> to have complete control of the initialization process.
>>
>> Best regards
>> Petr Kobalicek
>> _______________________________________________
>> HarfBuzz mailing list
>> HarfBuzz at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
More information about the HarfBuzz
mailing list