Bug 621213 – GDBusProxy and well-known names
[platform/upstream/glib.git] / gio / giomodule.c
index a7f8fc8..e1b1d17 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "giomodule.h"
 #include "giomodule-priv.h"
+#include "gmemorysettingsbackend.h"
 #include "glocalfilemonitor.h"
 #include "glocaldirectorymonitor.h"
 #include "gnativevolumemonitor.h"
  *  it uses the implementations that have been associated with it.
  *  Depending on the use case, it may use all implementations, or
  *  only the one with the highest priority, or pick a specific
- *  one by name. 
+ *  one by name.
+ *
+ *  To avoid opening all modules just to find out what extension
+ *  points they implement, GIO makes use of a caching mechanism,
+ *  see <link linkend="gio-querymodules">gio-querymodules</link>.
+ *  You are expected to run this command after installing a
+ *  GIO module.
  */
 struct _GIOModule {
   GTypeModule parent_instance;
@@ -270,7 +277,7 @@ g_io_modules_scan_all_in_directory (const char *dirname)
   const gchar *name;
   char *filename;
   GDir *dir;
-  struct stat statbuf;
+  GStatBuf statbuf;
   char *data;
   time_t cache_mtime;
   GHashTable *cache;
@@ -321,14 +328,14 @@ g_io_modules_scan_all_in_directory (const char *dirname)
            continue; /* Invalid line, ignore */
 
          *colon = 0; /* terminate filename */
-         file = strdup (line);
+         file = g_strdup (line);
          colon++; /* after colon */
 
          while (g_ascii_isspace (*colon))
            colon++;
 
          extension_points = g_strsplit (colon, ",", -1);
-         g_hash_table_insert (cache, g_strdup (file), extension_points);
+         g_hash_table_insert (cache, file, extension_points);
        }
       g_strfreev (lines);
     }
@@ -382,6 +389,8 @@ g_io_modules_scan_all_in_directory (const char *dirname)
   g_dir_close (dir);
 
   g_hash_table_destroy (cache);
+
+  g_free (filename);
 }
 
 
@@ -534,7 +543,6 @@ _g_io_modules_ensure_extension_points_registered (void)
 void
 _g_io_modules_ensure_loaded (void)
 {
-  GList *modules, *l;
   static gboolean loaded_dirs = FALSE;
   const char *module_path;
 
@@ -546,26 +554,25 @@ _g_io_modules_ensure_loaded (void)
     {
       loaded_dirs = TRUE;
 
-      modules = g_io_modules_load_all_in_directory (GIO_MODULE_DIR);
+      g_io_modules_scan_all_in_directory (GIO_MODULE_DIR);
 
       module_path = g_getenv ("GIO_EXTRA_MODULES");
 
       if (module_path)
-        {
-          int i = 0;
-          gchar **paths;
-          paths = g_strsplit (module_path, ":", 0);
-    
-          while (paths[i] != NULL)
-            { 
-              modules = g_list_concat (modules, g_io_modules_load_all_in_directory (paths[i]));
-              i++;
-            }
+       {
+         gchar **paths;
+         int i;
 
-          g_strfreev (paths);
-        }
+         paths = g_strsplit (module_path, ":", 0);
+
+         for (i = 0; paths[i] != NULL; i++)
+           g_io_modules_scan_all_in_directory (paths[i]);
+
+         g_strfreev (paths);
+       }
 
       /* Initialize types from built-in "modules" */
+      g_memory_settings_backend_get_type ();
 #if defined(HAVE_SYS_INOTIFY_H) || defined(HAVE_LINUX_INOTIFY_H)
       _g_inotify_directory_monitor_get_type ();
       _g_inotify_file_monitor_get_type ();
@@ -585,11 +592,6 @@ _g_io_modules_ensure_loaded (void)
       _g_winhttp_vfs_get_type ();
 #endif
       _g_local_vfs_get_type ();
-    
-      for (l = modules; l != NULL; l = l->next)
-       g_type_module_unuse (G_TYPE_MODULE (l->data));
-      
-      g_list_free (modules);
     }
 
   G_UNLOCK (loaded_dirs);