Problem:
When using dl functions under linux, dynamic load shared library,which depends on libglib-2.0 & libgobject-2.0, and close it, everything is ok now; But after dlopen the library again, error happened, just as follows:
(app:15420): GLib-GObject-WARNING **: cannot register existing type `WebKitWebView'
(app:15420): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed.
Solution:
where “cannot register existing type***” happened?
@ gtype.c
static gboolean check_type_name_I (const gchar * type_name) {....}
---> g_type_from_name(type_name))
error occured if type_name already exists in static_type_node_ht, but glib don’t give any method to unregister the typename;
the dependency relation is like this:
check_type_name_I <--- g_type_register_static <---- g_type_register_static_simple
@gtype.h
g_type_register_static_simple is defined in gtype.h
#define G_DEFINE_TYPE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN,
t_n, T_P, 0,
{})
#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)
_G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;}
_G_DEFINE_TYPE_EXTENDED_END()
G_DEFINE_TYPE_EXTENDED
@ webkit_web_view.cpp
G_DEFINE_TYPE_EXTENDED
(WebKitWebView,
webkit_web_view,
GTK_TYPE_CONTAINER,
0,
{});
the macro above generate codes:
GType webkit_web_view_get_type
(void)
{
static volatile gsize g_define_type_id__volatile =
0;
if (g_once_init_enter(&g_define_type_id__volatile))
{
GType g_define_type_id = g_type_register_static_simple
(GTK_TYPE_CONTAINER,g_intern_static_string("WebKitWebView"),sizeof(WebKitWebViewClass),
(GClassInitFunc)webkit_web_view_class_intern_init, sizeof(WebKitWebView),
(GInstanceInitFunc)webkit_web_view_init,(GTypeFlags) 0);
g_once_init_leave (&g_define_type_id__volatile,g_define_type_id);
return g_define_type_id__volatile;
}
WEBKIT_TYPE_WEB_VIEW == webkit_web_view_get_type
when calling webkit_web_view_new , WEBKIT_TYPE_WEB_VIEW is called, that’s why the error occures.
Until now, the problem has been located, but why the shared library was modify (the type info registered exists fater reload), dl mode is not COW ? i try to load all dependency library to make a copy, still the same....