giomodule: Port to new g_module_open_full() API

Port all existing calls in GLib to the new API so that they can receive
more detailed error information (although none of them actually make use
of it at the moment).

This also serves to test the new API better through use.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #203
This commit is contained in:
Philip Withnall 2021-07-21 21:54:35 +01:00
parent ee589aaa32
commit be012a8067
3 changed files with 18 additions and 6 deletions

View File

@ -81,7 +81,7 @@ query_dir (const char *dirname)
continue;
path = g_build_filename (dirname, name, NULL);
module = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
module = g_module_open_full (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL, &error);
g_free (path);
if (module)
@ -119,6 +119,12 @@ query_dir (const char *dirname)
g_module_close (module);
}
else
{
g_debug ("Failed to open module %s: %s", name, error->message);
}
g_clear_error (&error);
}
g_dir_close (dir);

View File

@ -342,6 +342,7 @@ static gboolean
g_io_module_load_module (GTypeModule *gmodule)
{
GIOModule *module = G_IO_MODULE (gmodule);
GError *error = NULL;
if (!module->filename)
{
@ -349,11 +350,12 @@ g_io_module_load_module (GTypeModule *gmodule)
return FALSE;
}
module->library = g_module_open (module->filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
module->library = g_module_open_full (module->filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL, &error);
if (!module->library)
{
g_printerr ("%s\n", g_module_error ());
g_printerr ("%s\n", error->message);
g_clear_error (&error);
return FALSE;
}

View File

@ -84,6 +84,7 @@ main (int argc,
gchar *plugin_a, *plugin_b;
SimpleFunc f_a, f_b, f_self;
GModuleFunc gmod_f;
GError *error = NULL;
g_test_init (&argc, &argv, NULL);
@ -95,18 +96,21 @@ main (int argc,
/* module handles */
module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
module_self = g_module_open_full (NULL, G_MODULE_BIND_LAZY, &error);
g_assert_no_error (error);
if (!module_self)
g_error ("error: %s", g_module_error ());
if (!g_module_symbol (module_self, "g_module_close", (gpointer *) &f_self))
g_error ("error: %s", g_module_error ());
module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
module_a = g_module_open_full (plugin_a, G_MODULE_BIND_LAZY, &error);
g_assert_no_error (error);
if (!module_a)
g_error ("error: %s", g_module_error ());
module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
module_b = g_module_open_full (plugin_b, G_MODULE_BIND_LAZY, &error);
g_assert_no_error (error);
if (!module_b)
g_error ("error: %s", g_module_error ());