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



commit 33397686e12c909bd6155ddf0576268e28c47e67
Author: Garrett Regier <alias301 gmail com>
Date:   Mon Feb 14 08:48:44 2011 -0800

    Fix C plugins that do not inherit from PeasExtensionBase

 loaders/c/peas-plugin-loader-c.c                   |   44 +++++++++++++------
 .../libpeas/plugins/extension-c/callable-plugin.c  |    2 +-
 .../libpeas/plugins/extension-c/callable-plugin.h  |    7 ++-
 3 files changed, 36 insertions(+), 17 deletions(-)
---
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 1d66be0..be41b79 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -119,32 +119,48 @@ 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);
 
-  /* 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);
+  is_extension_base = g_type_is_a (exten_type, PEAS_TYPE_EXTENSION_BASE);
 
-  /* 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);
+  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;
+    }
 
   instance = peas_object_module_create_object (module,
                                                exten_type,
-                                               n_parameters + 1,
+                                               n_parameters,
                                                exten_parameters);
 
-  g_value_unset (&exten_parameters[n_parameters].value);
-  g_free (exten_parameters);
+  if (is_extension_base)
+    {
+      g_value_unset (&exten_parameters[n_parameters - 1].value);
+      g_free (exten_parameters);
+    }
 
   if (instance == NULL)
     {
diff --git a/tests/libpeas/plugins/extension-c/callable-plugin.c b/tests/libpeas/plugins/extension-c/callable-plugin.c
index 8754cff..26d98fc 100644
--- a/tests/libpeas/plugins/extension-c/callable-plugin.c
+++ b/tests/libpeas/plugins/extension-c/callable-plugin.c
@@ -37,7 +37,7 @@ static void introspection_callable_iface_init (IntrospectionCallableInterface *i
 
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (TestingCallablePlugin,
                                 testing_callable_plugin,
-                                PEAS_TYPE_EXTENSION_BASE,
+                                G_TYPE_OBJECT,
                                 0,
                                 G_IMPLEMENT_INTERFACE_DYNAMIC (INTROSPECTION_TYPE_CALLABLE,
                                                                introspection_callable_iface_init))
diff --git a/tests/libpeas/plugins/extension-c/callable-plugin.h b/tests/libpeas/plugins/extension-c/callable-plugin.h
index 8fd8924..6ff988c 100644
--- a/tests/libpeas/plugins/extension-c/callable-plugin.h
+++ b/tests/libpeas/plugins/extension-c/callable-plugin.h
@@ -37,11 +37,14 @@ typedef struct _TestingCallablePlugin         TestingCallablePlugin;
 typedef struct _TestingCallablePluginClass    TestingCallablePluginClass;
 
 struct _TestingCallablePlugin {
-  PeasExtensionBase parent_instance;
+  /* Inherit from GObject and not PeasExtensionBase
+   * to check that it is possible
+   */
+  GObject parent_instance;
 };
 
 struct _TestingCallablePluginClass {
-  PeasExtensionBaseClass parent_class;
+  GObjectClass parent_class;
 };
 
 GType testing_callable_plugin_get_type (void) G_GNUC_CONST;



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