gobject对象不宜作为动态加载的插件
转载时请注明出处和作者联系方式
作者联系方式:李先静 <xianjimli at hotmail dot com>
前段时间对 syncmanager进行重构,为了减少不必要的开销,我决定在需要时才加SyncSource插件,不需要时就卸载它们。在测试时发现第一次运行时正 常,第二次运行时创建DbPersistance对象时失败了。仔细看了下调试信息,里面告诉我说注册DbPersistance类型失败,因为已经 DbPersistance类型注册了。不太可能啊,对象注册类型时一般都会防止重复注册的,比如:
gtk_button_get_type (void)
{
static GType button_type = 0;
if (!button_type)
{
static const GTypeInfo button_info =
{
sizeof (GtkButtonClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_button_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkButton),
16, /* n_preallocs */
(GInstanceInitFunc) gtk_button_init,
};
button_type = g_type_register_static (GTK_TYPE_BIN, "GtkButton",
&button_info, 0);
}
return button_type;
}
{
static GType button_type = 0;
if (!button_type)
{
static const GTypeInfo button_info =
{
sizeof (GtkButtonClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_button_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkButton),
16, /* n_preallocs */
(GInstanceInitFunc) gtk_button_init,
};
button_type = g_type_register_static (GTK_TYPE_BIN, "GtkButton",
&button_info, 0);
}
return button_type;
}