gchar *file_name;
gpointer handle;
guint ref_count;
+ GModuleDeInit de_init;
GModule *next;
};
{
main_module = g_new (GModule, 1);
main_module->file_name = NULL;
+ main_module->handle = handle;
main_module->ref_count = 1;
+ main_module->de_init = NULL;
main_module->next = NULL;
- main_module->handle = handle;
}
}
handle = _g_module_open (file_name, (flags & G_MODULE_BIND_LAZY) != 0);
if (handle)
{
- GModule *module;
+ gchar *saved_error;
+ GModuleCheckInit check_init;
+ gboolean check_failed = FALSE;
/* search the module list by handle, since file names are not unique */
module = g_module_find_by_handle (handle);
return module;
}
+ saved_error = module_error;
+ module_error = NULL;
+ g_module_set_error (NULL);
+
module = g_new (GModule, 1);
module->file_name = g_strdup (file_name);
module->handle = handle;
- module->ref_count = 1;
+ module->ref_count = 0;
+ module->de_init = NULL;
+ module->next = NULL;
+
+ /* check initialization */
+ if (g_module_symbol (module, "g_module_check_init", &check_init))
+ check_failed = check_init (module);
+
+ /* should call de_init() on failed initializations also? */
+ if (!check_failed)
+ g_module_symbol (module, "g_module_de_init", &module->de_init);
+
+ module->ref_count += 1;
module->next = modules;
modules = module;
- return module;
+ if (check_failed)
+ {
+ g_module_close (module);
+ module = NULL;
+ g_module_set_error ("GModule initialization check failed");
+ }
+ else
+ g_module_set_error (saved_error);
+ g_free (saved_error);
}
- return NULL;
+ return module;
}
gboolean
GModule *last;
GModule *node;
- _g_module_close (&module->handle, FALSE);
- g_free (module->file_name);
-
last = NULL;
node = modules;
while (node)
last = node;
node = last->next;
}
+ module->next = NULL;
+
+ if (module->de_init)
+ module->de_init (module);
+
+ _g_module_close (&module->handle, FALSE);
+ g_free (module->file_name);
+
g_free (module);
}
#endif /* __cplusplus */
-/* exporting and importing functions */
+/* exporting and importing functions,
+ * we need autoconf support here for supporting windows.
+ */
#define G_MODULE_EXPORT
#define G_MODULE_IMPORT extern
G_MODULE_BIND_MASK = 0x01
} GModuleFlags;
-typedef struct _GModule GModule;
+typedef struct _GModule GModule;
+typedef gboolean (*GModuleCheckInit) (GModule *module);
+typedef void (*GModuleDeInit) (GModule *module);
/* return TRUE if dynamic module loading is supported */
gboolean g_module_supported (void);
*/
string = "gplugin_a_func";
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
- if (!g_module_symbol (module_a, string, &f_a))
+ if (!g_module_symbol (module_a, string, (gpointer) &f_a))
{
g_print ("error: %s\n", g_module_error ());
return 1;
}
string = "gplugin_b_func";
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
- if (!g_module_symbol (module_b, string, &f_b))
+ if (!g_module_symbol (module_b, string, (gpointer) &f_b))
{
g_print ("error: %s\n", g_module_error ());
return 1;
*/
string = "g_clash_func";
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
- if (!g_module_symbol (module_self, string, &f_self))
+ if (!g_module_symbol (module_self, string, (gpointer) &f_self))
{
g_print ("error: %s\n", g_module_error ());
return 1;
}
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
- if (!g_module_symbol (module_a, string, &f_a))
+ if (!g_module_symbol (module_a, string, (gpointer) &f_a))
{
g_print ("error: %s\n", g_module_error ());
return 1;
}
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
- if (!g_module_symbol (module_b, string, &f_b))
+ if (!g_module_symbol (module_b, string, (gpointer) &f_b))
{
g_print ("error: %s\n", g_module_error ());
return 1;
*/
string = "gplugin_clash_func";
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
- if (!g_module_symbol (module_a, string, &f_a))
+ if (!g_module_symbol (module_a, string, (gpointer) &f_a))
{
g_print ("error: %s\n", g_module_error ());
return 1;
}
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
- if (!g_module_symbol (module_b, string, &f_b))
+ if (!g_module_symbol (module_b, string, (gpointer) &f_b))
{
g_print ("error: %s\n", g_module_error ());
return 1;
*/
string = "gplugin_a_module_func";
g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
- if (!g_module_symbol (module_a, string, &gmod_f))
+ if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
{
g_print ("error: %s\n", g_module_error ());
return 1;