[HarfBuzz] Static initialization of C++ classes in harfbuzz

Petr Kobalíček kobalicek.petr at gmail.com
Sat Jan 7 09:40:47 PST 2012


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



More information about the HarfBuzz mailing list