Re: [Vala] Unregister a GType
- From: Igor Azevedo <igor azevedo neticle pt>
- To: Vala-list <vala-list gnome org>
- Subject: Re: [Vala] Unregister a GType
- Date: Mon, 13 May 2013 12:14:49 +0000
Hi, I worked around this issue by modifying valac to change the code
generated for the <class>_get_type() function.
Originally it outputed something like this:
static volatile gsize test_module_type_id__volatile = 0;
if (g_once_init_enter (&test_module_type_id__volatile)) {
(...)
GType test_module_type_id;
test_module_type_id = g_type_register_fundamental (g_type_fundamental_next
(), "TestModule", &g_define_type_info, &g_define_type_fundamental_info, 0);
g_once_init_leave (&test_module_type_id__volatile, test_module_type_id);
}
return test_module_type_id__volatile;
I added a check before attempting to register the type:
static volatile gsize test_module_type_id__volatile = 0;
if (g_once_init_enter (&test_module_type_id__volatile)) {
(...)
GType test_module_type_id;
test_module_type_id = g_type_from_name ("TestModule");
if (test_module_type_id) {
g_once_init_leave (&test_module_type_id__volatile, test_module_type_id);
return test_module_type_id__volatile;
}
test_module_type_id = g_type_register_fundamental (g_type_fundamental_next
(), "TestModule", &g_define_type_info, &g_define_type_fundamental_info, 0);
g_once_init_leave (&test_module_type_id__volatile, test_module_type_id);
}
return test_module_type_id__volatile;
Are there any problems that can be caused due to this "workaround"?
Com os melhores cumprimentos,
Igor Azevedo
Neticle, serviços de webdesign e programação
Telm: 968 323 131
www.neticle.pt
2013/5/7 Igor Azevedo <igor azevedo neticle pt>
2013/5/5 PCMan <pcman tw gmail com>
On Sun, May 5, 2013 at 2:15 AM, Igor Azevedo <igor azevedo neticle pt>
wrote:
2013/5/4 Luca Bruno <lethalman88 gmail com>
On Sat, May 4, 2013 at 6:29 PM, Igor Azevedo <igor azevedo neticle pt
wrote:
Hello,
I'm developing an application that dynamically loads plugins using
GModule.
Each of the plugins registers it's own GTypes but if I load, unload,
and
finally reload them I get some errors and the modules don't load
properly.
Errors are:
(process:21259): GLib-GObject-WARNING **: cannot register existing
type
`NeticleInfinityModulesBaseBaseModule'
I understand why this happens, I'm registering a GType that was
already
registered previously when I first loaded the plugin and even after
unloading the module, the types remained registered, so it obviously
fails.
My question is if there is any way to unregister a GType so I can
reload
the plugin successfully?
Are you doing this way?
https://live.gnome.org/Vala/TypeModules
https://live.gnome.org/Vala/TypeModuleSample
My implementation was based on the first example you mentioned. Should I
use TypeModule (like in the second example)?
Thanks,
Igor Azevedo
You're not able to unregister a GType no matter it's a dynamic one or not.
Once registered, it should persist until the program terminates.
If you use type module, the type module objects and the types they
registered should not be freed until program termination.
The underlying modules used inside your type module implementation can
be unloaded when they're not needed, but the GType registered persist.
When someone referenced that GType again and GObject type system finds
that the module is not loaded, it tries to load your type module.
So the module can be unloaded, but the GType it registered cannot.
Unfortunately, this is hard to do correctly, and GTypeModule will be
deprecated later.
I talked with a gtk+ developer in #gtk+ channel last time and I'm
informed that GTypeModule will be moved.
So, don't waste your time trying to do that. Once you register a new
GType inside the module, you'd better make it persist and never unload
it.
What I'm really trying to accomplish here is reloading a certain external
plugin (as there might have been changes to it) without having to restart
my application. I don't really mind if the GTypes stay registered, as long
as it doesn't bother me when I'm reloading the lib. Is there absolutely no
way to do this?
TypeModule seems to be able to reload the library without having issues
regarding the registration of GTypes, how is this being done?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]