Re: GtkBuildable type resolver



On Mon, 2007-06-04 at 15:04 -0400, Johan Dahlin wrote:
> 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
> 51[2]:
> 
> - 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
> filesystem
>   and parse those at gtk_init() time - that might be the least evil option

Lets see how things will work when gobject-introspection is added.
Third-party libraries still need to register themselves somehow.  I
can't think of any solution not depending on __attribute__(constructor)
or RTLD_NEXT.

behdad


> 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?
> 
> [1]: http://bugzilla.gnome.org/show_bug.cgi?id=172535
> [2]: http://bugzilla.gnome.org/show_bug.cgi?id=172535#c51
> [3]: http://bugzilla.gnome.org/attachment.cgi?id=89349
> 
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759






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