[libpeas] Fix reloading C plugins.



commit feb6e7b7c08ba2aa811a58472c6531cbb0f7aa50
Author: Steve Frécinaux <code istique net>
Date:   Thu Jul 22 15:06:27 2010 +0200

    Fix reloading C plugins.
    
    GTypeModule expects all the types to be registered during the
    g_type_module_use() call. It implies doing the registration within the
    _load() virtual method, but we did it at a later stage.
    
    The warnings (and actual reloading) are fixed by moving the type
    registration process within the _load() virtual function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621233

 libpeas/peas-engine.c                              |    2 -
 libpeas/peas-object-module.c                       |   31 +++++++------------
 libpeas/peas-object-module.h                       |    1 -
 loaders/c/peas-plugin-loader-c.c                   |    3 +-
 .../helloworld/peasdemo-hello-world-configurable.c |    4 +-
 .../helloworld/peasdemo-hello-world-plugin.c       |    4 +-
 6 files changed, 17 insertions(+), 28 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 9292f79..522b120 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -595,8 +595,6 @@ load_plugin_loader (PeasEngine  *engine,
       return add_loader (engine, loader_id, NULL, NULL);
     }
 
-  /* make sure to load the type definition */
-  peas_object_module_register_types (module);
   loader = (PeasPluginLoader *) peas_object_module_create_object (module, PEAS_TYPE_PLUGIN_LOADER, 0, NULL);
 
   if (loader == NULL || !PEAS_IS_PLUGIN_LOADER (loader))
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index fdad671..1ed79bb 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -68,10 +68,18 @@ struct _PeasObjectModulePrivate {
   gchar *path;
   gchar *module_name;
 
-  gboolean types_registered : 1;
-  gboolean resident : 1;
+  guint resident : 1;
 };
 
+static void
+peas_object_module_register_types (PeasObjectModule *module)
+{
+  g_return_if_fail (PEAS_IS_OBJECT_MODULE (module));
+  g_return_if_fail (module->priv->register_func != NULL);
+
+  module->priv->register_func (module);
+}
+
 static gboolean
 peas_object_module_load (GTypeModule *gmodule)
 {
@@ -124,6 +132,8 @@ peas_object_module_load (GTypeModule *gmodule)
   if (module->priv->resident)
     g_module_make_resident (module->priv->library);
 
+  peas_object_module_register_types (module);
+
   return TRUE;
 }
 
@@ -275,17 +285,6 @@ peas_object_module_new (const gchar *module_name,
                                            NULL));
 }
 
-void
-peas_object_module_register_types (PeasObjectModule *module)
-{
-  g_return_if_fail (PEAS_IS_OBJECT_MODULE (module));
-  g_return_if_fail (module->priv->register_func != NULL);
-  g_return_if_fail (module->priv->types_registered == FALSE);
-
-  module->priv->register_func (module);
-  module->priv->types_registered = TRUE;
-}
-
 GObject *
 peas_object_module_create_object (PeasObjectModule *module,
                                   GType             interface,
@@ -297,9 +296,6 @@ peas_object_module_create_object (PeasObjectModule *module,
 
   g_return_val_if_fail (PEAS_IS_OBJECT_MODULE (module), NULL);
 
-  if (!module->priv->types_registered)
-    peas_object_module_register_types (module);
-
   impls = (InterfaceImplementation *) module->priv->implementations->data;
   for (i = 0; i < module->priv->implementations->len; ++i)
     if (impls[i].iface_type == interface)
@@ -317,9 +313,6 @@ peas_object_module_provides_object (PeasObjectModule *module,
 
   g_return_val_if_fail (PEAS_IS_OBJECT_MODULE (module), FALSE);
 
-  if (!module->priv->types_registered)
-    peas_object_module_register_types (module);
-
   impls = (InterfaceImplementation *) module->priv->implementations->data;
   for (i = 0; i < module->priv->implementations->len; ++i)
     if (impls[i].iface_type == interface)
diff --git a/libpeas/peas-object-module.h b/libpeas/peas-object-module.h
index 945cea1..a87fd2d 100644
--- a/libpeas/peas-object-module.h
+++ b/libpeas/peas-object-module.h
@@ -60,7 +60,6 @@ PeasObjectModule   *peas_object_module_new                    (const gchar
                                                                const gchar      *path,
                                                                gboolean          resident);
 
-void                peas_object_module_register_types         (PeasObjectModule *module);
 GObject            *peas_object_module_create_object          (PeasObjectModule *module,
                                                                GType             interface,
                                                                guint             n_parameters,
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index d07f423..827b845 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -88,8 +88,6 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
       return FALSE;
     }
 
-  peas_object_module_register_types (module);
-
   return TRUE;
 }
 
@@ -154,6 +152,7 @@ peas_plugin_loader_c_unload (PeasPluginLoader *loader,
   module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
                                                      info);
 
+  g_debug ("Unloading plugin '%s'", peas_plugin_info_get_module_name (info));
   g_type_module_unuse (G_TYPE_MODULE (module));
 }
 
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c
index 20ae458..2d7dabc 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c
@@ -14,8 +14,8 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldConfigurable,
                                 peasdemo_hello_world_configurable,
                                 PEAS_TYPE_EXTENSION_BASE,
                                 0,
-                                G_IMPLEMENT_INTERFACE (PEAS_UI_TYPE_CONFIGURABLE,
-                                                       peas_ui_configurable_iface_init))
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_UI_TYPE_CONFIGURABLE,
+                                                               peas_ui_configurable_iface_init))
 
 static void
 peasdemo_hello_world_configurable_init (PeasDemoHelloWorldConfigurable *plugin)
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 7687a72..015e9b4 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -15,8 +15,8 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldPlugin,
                                 peasdemo_hello_world_plugin,
                                 PEAS_TYPE_EXTENSION_BASE,
                                 0,
-                                G_IMPLEMENT_INTERFACE (PEAS_TYPE_ACTIVATABLE,
-                                                       peas_activatable_iface_init))
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
+                                                               peas_activatable_iface_init))
 
 static void
 peasdemo_hello_world_plugin_init (PeasDemoHelloWorldPlugin *plugin)



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