GtkBuildable type resolver

One of the problems pointed out by Matthias in the GtkBuilder bug[1] is how
a third-party library can define a type name mapping to get type function.

First, let me try explain a bit more about the problem;

The types inside a GtkBuilder ui definition files (eg, .glade) are currently
only referred by their name. This creates a problem since the type names
are not known until the first time you call the get_type function.
The long term solution to list problem is to export meta data inside the
gobject-introspection framework which will contain a list of all
types and their respective *_get_type function.

I initially solved this problem by having a hash table inside gtk+ where
all known types have their _get_type function defined.
For external libraries I added a public API by which a get_type function
could be registered. This will unfortunately not work for third party
libraries which doesn't export an _init() function.

Matthias suggested a couple of alternatives, which you can read in comment

- if you play games with __attribute__(constructor),
  that gets executed before main()

- if you try to heuristically guess the mapping from type name to get_type()
  function name, it is going to fail sometimes

- you could try to dump that mapping into some files somewhere in the
  and parse those at gtk_init() time - that might be the least evil option

I went ahead and implemented the second alternative using g_module_symbol),
that code can be found in this patch[3], inside _gtk_resolve_type_lazily.

Does anyone have any other suggestions on how to solve the
problem, or comments on my solution?


Johan Dahlin <jdahlin async com br>
Async Open Source

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