[glib: 2/3] giomodule: Port to new g_module_open_full() API




commit be012a80676e5b15f6e02c2553073901d138a6bd
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Jul 21 21:54:35 2021 +0100

    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

 gio/gio-querymodules.c |  8 +++++++-
 gio/giomodule.c        |  6 ++++--
 tests/module-test.c    | 10 +++++++---
 3 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/gio/gio-querymodules.c b/gio/gio-querymodules.c
index eb5094f4d..cbeb9758e 100644
--- a/gio/gio-querymodules.c
+++ b/gio/gio-querymodules.c
@@ -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);
diff --git a/gio/giomodule.c b/gio/giomodule.c
index d3b5e482a..c1d451b5c 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -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;
     }
 
diff --git a/tests/module-test.c b/tests/module-test.c
index e0e6423f6..62473d29d 100644
--- a/tests/module-test.c
+++ b/tests/module-test.c
@@ -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 ());
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]