Re: [Builder] LibIDE Update



On Wed, Feb 18, 2015 at 2:27 PM, Christian Hergert <christian hergert me> wrote:
Indeed you are right! We use a bunch of gconstructor foo in libide, which I thought uses the same infrastructure as static constructors. Any insight on that?

Not a clue! You'd need to ask the GCC folks how it works in GCC and the Clang folks how it works with Clang. I suspect it could only possibly work on C compilers that support GNU C constructors (which are not standardized anywhere, but you know that), which are evidently the only compilers you care about for building Builder, but even then my guess would be "only possibly".

The flip side of static constructors is static destructors. Do those exist in GNU C? We can come up with hypothetical imaginary bugs that would be caused by a destructor that never runs at program termination, but it doesn't seem like a super practical worry.

So far, there haven't been any issues, but I haven't integrated things that deep yet. I really want to avoid anyone having to create a .cpp
when using LibIDE. Perhaps if ide.c (where we register all our types and have the gconstructor init code) was cpp it would wire that up?

HM. So I had actually never thought this through that far; I had only considered C programs that link statically with C++ code, not C programs that link dynamically with future shared library LibIDE. There has to be some magic that makes this work properly when the shared library is loaded; otherwise, how would anybody ever be able to use WebKitGTK+ or Harfbuzz? There is no way it could be a practical problem, or those would never work.

In WebKit we go out of our way to ensure static destructors never run (by ensuring that static objects are intentionally leaked) but I've never understood or asked why, and assumed it was a peculiarity with Windows or OS X, but maybe it has something to do with this.

Anyway I learned this rule from More Effective C++ (specifically pages 273-275) which was published in the 90s; maybe times have changed. My guess is that it's only needed for static linking (and even then, possibly not with our compilers), and that the constructors are run on shared library load. So I would not worry about it.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]