[libpeas] Add peas_utils_get_loader_module_from_id()



commit bf43336ed9183b55c0c0e17a25676eec4c4160ad
Author: Garrett Regier <garrettregier gmail com>
Date:   Mon Sep 21 21:36:17 2015 -0700

    Add peas_utils_get_loader_module_from_id()
    
    This simplifies loading a plugin loader's module.

 libpeas/peas-engine.c |   17 +++--------------
 libpeas/peas-utils.c  |   20 ++++++++++++++++++--
 libpeas/peas-utils.h  |    2 ++
 3 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index d54a758..a667c88 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -647,26 +647,16 @@ static PeasObjectModule *
 get_plugin_loader_module (gint loader_id)
 {
   GlobalLoaderInfo *global_loader_info = &loaders[loader_id];
-  gint i, j;
-  const gchar *loader_name;
-  gchar *module_name, *module_dir;
+  const gchar *loader_name, *module_name;
+  gchar *module_dir;
 
   if (global_loader_info->module != NULL)
     return global_loader_info->module;
 
   loader_name = peas_utils_get_loader_from_id (loader_id);
-  module_name = g_strconcat (loader_name, "loader", NULL);
+  module_name = peas_utils_get_loader_module_from_id (loader_id);
   module_dir = peas_dirs_get_plugin_loader_dir (loader_name);
 
-  /* Remove '.'s from the module name */
-  for (i = 0, j = 0; module_name[i] != '\0'; ++i)
-    {
-      if (module_name[i] != '.')
-        module_name[j++] = module_name[i];
-    }
-
-  module_name[j] = '\0';
-
   /* Bind loaders globally, binding
    * locally can break the plugin loaders
    */
@@ -681,7 +671,6 @@ get_plugin_loader_module (gint loader_id)
     }
 
   g_free (module_dir);
-  g_free (module_name);
 
   return global_loader_info->module;
 }
diff --git a/libpeas/peas-utils.c b/libpeas/peas-utils.c
index ee8fef1..8237011 100644
--- a/libpeas/peas-utils.c
+++ b/libpeas/peas-utils.c
@@ -29,8 +29,14 @@
 
 #include "peas-utils.h"
 
-static const gchar *all_plugin_loaders[] = {"c", "lua5.1",
-                                            "python", "python3"};
+static const gchar *all_plugin_loaders[] = {
+  "c", "lua5.1", "python", "python3"
+};
+
+static const gchar *all_plugin_loader_modules[] = {
+  "cloader", "lua51loader", "pythonloader", "python3loader"
+};
+
 static const gint conflicting_plugin_loaders[PEAS_UTILS_N_LOADERS][2] = {
   { -1, -1 }, /* c       => {}          */
   { -1, -1 }, /* lua5.1  => {}          */
@@ -39,6 +45,7 @@ static const gint conflicting_plugin_loaders[PEAS_UTILS_N_LOADERS][2] = {
 };
 
 G_STATIC_ASSERT (G_N_ELEMENTS (all_plugin_loaders) == PEAS_UTILS_N_LOADERS);
+G_STATIC_ASSERT (G_N_ELEMENTS (all_plugin_loader_modules) == PEAS_UTILS_N_LOADERS);
 G_STATIC_ASSERT (G_N_ELEMENTS (conflicting_plugin_loaders) == PEAS_UTILS_N_LOADERS);
 
 static void
@@ -190,6 +197,15 @@ peas_utils_get_loader_from_id (gint loader_id)
   return all_plugin_loaders[loader_id];
 }
 
+const gchar *
+peas_utils_get_loader_module_from_id (gint loader_id)
+{
+  g_return_val_if_fail (loader_id >= 0, NULL);
+  g_return_val_if_fail (loader_id < PEAS_UTILS_N_LOADERS, NULL);
+
+  return all_plugin_loader_modules[loader_id];
+}
+
 const gint *
 peas_utils_get_conflicting_loaders_from_id (gint loader_id)
 {
diff --git a/libpeas/peas-utils.h b/libpeas/peas-utils.h
index aa00d54..df8e45b 100644
--- a/libpeas/peas-utils.h
+++ b/libpeas/peas-utils.h
@@ -35,6 +35,8 @@ gboolean  peas_utils_valist_to_parameter_list (GType         iface_type,
 gint     peas_utils_get_loader_id             (const gchar  *loader) G_GNUC_CONST;
 const gchar *
          peas_utils_get_loader_from_id        (gint          loader_id) G_GNUC_CONST;
+const gchar *
+         peas_utils_get_loader_module_from_id (gint          loader_id) G_GNUC_CONST;
 const gint *
          peas_utils_get_conflicting_loaders_from_id
                                               (gint          loader_id) G_GNUC_CONST;


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