[libpeas] Allow writing C extensions not inheriting from PeasExtensionBase.



commit 9622432d05718ee14d14eab314ae35813284ec49
Author: Steve Frécinaux <code istique net>
Date:   Mon Jun 28 17:40:02 2010 +0200

    Allow writing C extensions not inheriting from PeasExtensionBase.
    
    PeasExtensionBase ought to be an optional base class allowing the
    extension implementer to get the plugin-info instance and the
    information it contains.  The introduction of the "plugin-info"
    construct property broke the ability to use GObject (or something else)
    as the base class.
    
    We restore this ability by dropping this property from the construct
    property vales if the object doesn't have this property.  This
    behaviour also makes it possible to use a GInterface to get the
    "plugin-info" property.

 libpeas/peas-object-module.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index 5dba731..6d54f06 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -385,9 +385,28 @@ create_gobject_from_type (guint       n_parameters,
                           GParameter *parameters,
                           gpointer    user_data)
 {
-  return g_object_newv (GPOINTER_TO_SIZE (user_data),
-                        n_parameters,
-                        parameters);
+  GType exten_type;
+  GObjectClass *cls;
+  GObject *instance;
+
+  exten_type = GPOINTER_TO_SIZE (user_data);
+
+  cls = g_type_class_ref (exten_type);
+
+  /* If we are instantiating a plugin, then the factory function is
+   * 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 &&
+      strcmp (parameters[n_parameters-1].name, "plugin-info") == 0 &&
+      g_object_class_find_property (cls, "plugin-info") != NULL)
+    n_parameters --;
+
+  instance = g_object_newv (exten_type, n_parameters, parameters);
+
+  g_type_class_unref (cls);
+
+  return instance;
 }
 
 /**



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