Re: Using static types from a GTypeModule



On Mon, 18 Jun 2007, Alberto Mardegan wrote:

Hello everybody,
  I have an application using some plugins which define some dynamic
types by means of the GTypeModule API. So far, so good.
But if one of this plugins is dynamically linked to a library (say,
Gtk+) that registers static types, then the plugin cannot be unloaded
and loaded again or GType will report the infamous "cannot register
existing type [type]" error message.
I work around this problem by calling g_type_module_use() to prevent the
plugin from being unloaded, but obviously this is not a solution.

How can I allow the plugin to be unloaded and reloaded properly? I'm
afraid there is nothing I can do from the application side.

I've looked a bit into the GType source code, and I wonder if it could
be possible to have GType forget everything about a type when its
reference count gets back to 0, so that it could be registered again
from scratch (yes, I can see that this conflicts with the "static"
keyword in the name itself, but I believe that static types should'n be
used at all, inside a dynamic library).

Comments?

Gtk+ is a library that cannot be unloaded, this is so by design and
cannot and will not be changed. also, libgobject type ids are not
unregisterable by design, this cannot and will not be changed.

in your case, it sounds like your plugin loads the gtk library
on demand, so it gets unloaded once your plugin is unloaded.
if that is the case, fix your code so Gtk+ never gets unloaded
(usually it's best to have the application link against Gtk+,
so dynamic plugins can rely on it being present instead of
pulling it in).

Ciao,
  Alberto

---
ciaoTJ



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