[Geany-Devel] Plugins which register new GType-s can be unloadable
dimitar.zhekov at xxxxx
Sat Sep 21 18:17:17 UTC 2013
I found a way to make plugin that registers a new GType unloadable.
That requires some work and is a bit hackish, so you'd better avoid
it for simple plugins.
First, replace g_intern_static_string() with g_intern_string(). Note
that G_DEFINE_TYPE_WITH_CODE() uses g_intern_static_string(), so you
have to expand and change it. Remove any G_PARAM_STATIC_NICK or
G_PARAM_STATIC_BLURB flags from the properties registration too.
Second, create a constructor and move your instance initialization
Third, each time your plugin is loaded:
- check if the class exists with g_type_from_name()
- if it does not, register it class normally and reference it at
least once, to make sure it's fully created; there is no need
to hold the reference
- if it exists, but your class_type_id_volatile is zero, get the
class info and fix type's constructor, finalizer and any other
virtual methods, fix the interface virtual methods, and set
class_type_id_volatile the g_type_from_name() value
See scp_tree_store_register_dynamic() for example.
That's all, folks! How does it work is left as an exercise for the
Obviously, the above is not possible if:
- your constructor properties, if any, depend on your instance
initialization code (glib/gtk+ ctor properties are ok, depend
on glib/gtk+ instance init is ok)
- your type has class finalization code (glib/gtk+ class
finalize is ok, your instance finalize is of course ok)
More information about the Devel