[libpeas] Correctly Fix C plugins that do not inherit from PeasExtensionBase



commit 2fe3b1ae664d3d97bb15bf09e93cb25aec6c3b6c
Author: Garrett Regier <alias301 gmail com>
Date:   Sat Feb 19 06:08:47 2011 -0800

    Correctly Fix C plugins that do not inherit from PeasExtensionBase

 libpeas/peas-object-module.c     |    4 +-
 loaders/c/peas-plugin-loader-c.c |   50 ++++++++++++++-----------------------
 2 files changed, 21 insertions(+), 33 deletions(-)
---
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index 2589998..7c09331 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -419,10 +419,10 @@ create_gobject_from_type (guint       n_parameters,
    * called with a "plugin-info" property appended to the parameters.
    * Let's get rid of it if the actual type doesn't have such a
    * property to avoid a warning. */
-  if (n_parameters > 1 &&
+  if (n_parameters > 0 &&
       strcmp (parameters[n_parameters-1].name, "plugin-info") == 0 &&
       g_object_class_find_property (cls, "plugin-info") == NULL)
-    n_parameters --;
+    n_parameters--;
 
   instance = G_OBJECT (g_object_newv (exten_type, n_parameters, parameters));
 
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index be41b79..75c76cc 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -119,48 +119,36 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
   GParameter *exten_parameters;
   gpointer instance;
   const gchar *module_name;
-  gboolean is_extension_base;
 
   module_name = g_intern_string (peas_plugin_info_get_module_name (info));
   module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
                                                      module_name);
   g_return_val_if_fail (module != NULL, NULL);
 
-  is_extension_base = g_type_is_a (exten_type, PEAS_TYPE_EXTENSION_BASE);
-
-  if (!is_extension_base)
-    {
-      exten_parameters = parameters;
-    }
-  else
-    {
-      /* We want to add a "plugin-info" property so we can pass it to
-       * the extension if it inherits from PeasExtensionBase. No need to
-       * actually "duplicate" the GValues, a memcpy is sufficient as the
-       * source GValues are longer lived than our local copy.
-       */
-      exten_parameters = g_new (GParameter, n_parameters + 1);
-      memcpy (exten_parameters, parameters, sizeof (GParameter) * n_parameters);
-
-      /* Initialize our additional property */
-      exten_parameters[n_parameters].name = g_intern_static_string ("plugin-info");
-      memset (&exten_parameters[n_parameters].value, 0, sizeof (GValue));
-      g_value_init (&exten_parameters[n_parameters].value, PEAS_TYPE_PLUGIN_INFO);
-      g_value_set_boxed (&exten_parameters[n_parameters].value, info);
-
-      ++n_parameters;
-    }
+  /* We want to add a "plugin-info" property so we can pass it to
+   * the extension if it inherits from PeasExtensionBase. No need to
+   * actually "duplicate" the GValues, a memcpy is sufficient as the
+   * source GValues are longer lived than our local copy.
+   */
+  exten_parameters = g_new (GParameter, n_parameters + 1);
+  memcpy (exten_parameters, parameters, sizeof (GParameter) * n_parameters);
+
+  /* Initialize our additional property.
+   * If the instance does not have a plugin-info property
+   * then PeasObjectModule will remove the property.
+   */
+  exten_parameters[n_parameters].name = g_intern_static_string ("plugin-info");
+  memset (&exten_parameters[n_parameters].value, 0, sizeof (GValue));
+  g_value_init (&exten_parameters[n_parameters].value, PEAS_TYPE_PLUGIN_INFO);
+  g_value_set_boxed (&exten_parameters[n_parameters].value, info);
 
   instance = peas_object_module_create_object (module,
                                                exten_type,
-                                               n_parameters,
+                                               n_parameters + 1,
                                                exten_parameters);
 
-  if (is_extension_base)
-    {
-      g_value_unset (&exten_parameters[n_parameters - 1].value);
-      g_free (exten_parameters);
-    }
+  g_value_unset (&exten_parameters[n_parameters].value);
+  g_free (exten_parameters);
 
   if (instance == NULL)
     {



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