[libpeas] Fix PeasEngine to be capable of being created multiple times
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Fix PeasEngine to be capable of being created multiple times
- Date: Wed, 9 Feb 2011 08:39:51 +0000 (UTC)
commit 115e2efcabd36f265014d45909c6c8e5b185365a
Author: Garrett Regier <alias301 gmail com>
Date: Sun Feb 6 03:34:37 2011 -0800
Fix PeasEngine to be capable of being created multiple times
libpeas/peas-engine.c | 31 ++++++++++--------------
loaders/c/peas-plugin-loader-c.c | 46 ++++++++++++-------------------------
2 files changed, 28 insertions(+), 49 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 3fe9e5e..99d150f 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -91,7 +91,6 @@ struct _PeasEnginePrivate {
GList *search_paths;
GList *plugin_list;
- GHashTable *loaders;
guint in_dispose : 1;
};
@@ -101,6 +100,9 @@ static void peas_engine_load_plugin_real (PeasEngine *engine,
static void peas_engine_unload_plugin_real (PeasEngine *engine,
PeasPluginInfo *info);
+static gboolean shutdown = FALSE;
+static GHashTable *loaders = NULL;
+
static void
load_plugin_info (PeasEngine *engine,
const gchar *filename,
@@ -288,7 +290,7 @@ add_loader (PeasEngine *engine,
info->loader = loader;
info->module = module;
- g_hash_table_insert (engine->priv->loaders, g_strdup (loader_id), info);
+ g_hash_table_insert (loaders, g_strdup (loader_id), info);
return info;
}
@@ -300,12 +302,6 @@ peas_engine_init (PeasEngine *engine)
PeasEnginePrivate);
engine->priv->in_dispose = FALSE;
-
- /* mapping from loadername -> loader object */
- engine->priv->loaders = g_hash_table_new_full (hash_lowercase,
- (GEqualFunc) equal_lowercase,
- (GDestroyNotify) g_free,
- (GDestroyNotify) loader_destroy);
}
static void
@@ -328,7 +324,7 @@ loader_garbage_collect (const gchar *id,
void
peas_engine_garbage_collect (PeasEngine *engine)
{
- g_hash_table_foreach (engine->priv->loaders,
+ g_hash_table_foreach (loaders,
(GHFunc) loader_garbage_collect,
NULL);
}
@@ -422,13 +418,6 @@ peas_engine_dispose (GObject *object)
peas_engine_unload_plugin (engine, info);
}
- /* unref the loaders */
- if (engine->priv->loaders != NULL)
- {
- g_hash_table_destroy (engine->priv->loaders);
- engine->priv->loaders = NULL;
- }
-
G_OBJECT_CLASS (peas_engine_parent_class)->dispose (object);
}
@@ -574,6 +563,12 @@ peas_engine_class_init (PeasEngineClass *klass)
/* We are doing some global initialization here as there is currently no
* global init function for libpeas. */
peas_debug_init ();
+
+ /* mapping from loadername -> loader object */
+ loaders = g_hash_table_new_full (hash_lowercase,
+ (GEqualFunc) equal_lowercase,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) loader_destroy);
}
static PeasObjectModule *
@@ -666,7 +661,7 @@ get_plugin_loader (PeasEngine *engine,
loader_id = info->loader;
- loader_info = (LoaderInfo *) g_hash_table_lookup (engine->priv->loaders,
+ loader_info = (LoaderInfo *) g_hash_table_lookup (loaders,
loader_id);
if (loader_info == NULL)
@@ -698,7 +693,7 @@ peas_engine_disable_loader (PeasEngine *engine,
g_return_if_fail (PEAS_IS_ENGINE (engine));
- loader_info = (LoaderInfo *) g_hash_table_lookup (engine->priv->loaders,
+ loader_info = (LoaderInfo *) g_hash_table_lookup (loaders,
loader_id);
if (loader_info != NULL && loader_info->module != NULL)
{
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 1a20a47..e933bcb 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -61,9 +61,9 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
PeasObjectModule *module;
const gchar *module_name;
+ module_name = g_intern_string (peas_plugin_info_get_module_name (info));
module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
- info);
- module_name = peas_plugin_info_get_module_name (info);
+ module_name);
if (module == NULL)
{
@@ -72,10 +72,8 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
peas_plugin_info_get_module_dir (info),
TRUE);
- /* Infos are available for all the lifetime of the loader.
- * If this changes, we should use weak refs or something */
-
- g_hash_table_insert (cloader->priv->loaded_plugins, info, module);
+ g_hash_table_insert (cloader->priv->loaded_plugins,
+ (gpointer) module_name, module);
g_debug ("Insert module '%s' into C module set", module_name);
}
@@ -97,9 +95,11 @@ peas_plugin_loader_c_provides_extension (PeasPluginLoader *loader,
{
PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
PeasObjectModule *module;
+ const gchar *module_name;
+ module_name = g_intern_string (peas_plugin_info_get_module_name (info));
module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
- info);
+ module_name);
g_return_val_if_fail (module != NULL, FALSE);
return peas_object_module_provides_object (module, exten_type);
@@ -116,9 +116,11 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
PeasObjectModule *module;
GParameter *exten_parameters;
gpointer instance;
+ const gchar *module_name;
+ module_name = g_intern_string (peas_plugin_info_get_module_name (info));
module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
- info);
+ 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
@@ -162,11 +164,13 @@ peas_plugin_loader_c_unload (PeasPluginLoader *loader,
{
PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
PeasObjectModule *module;
+ const gchar *module_name;
+ module_name = g_intern_string (peas_plugin_info_get_module_name (info));
module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
- info);
+ module_name);
- g_debug ("Unloading plugin '%s'", peas_plugin_info_get_module_name (info));
+ g_debug ("Unloading plugin '%s'", module_name);
g_type_module_unuse (G_TYPE_MODULE (module));
}
@@ -177,7 +181,7 @@ peas_plugin_loader_c_init (PeasPluginLoaderC *self)
PEAS_TYPE_PLUGIN_LOADER_C,
PeasPluginLoaderCPrivate);
- /* loaded_plugins maps PeasPluginInfo to a PeasObjectModule */
+ /* loaded_plugins maps PeasPluginInfo:module-name to a PeasObjectModule */
self->priv->loaded_plugins = g_hash_table_new (g_direct_hash,
g_direct_equal);
}
@@ -186,26 +190,6 @@ static void
peas_plugin_loader_c_finalize (GObject *object)
{
PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (object);
- GList *infos;
- GList *item;
-
- /* FIXME: this sanity check it's not efficient. Let's remove it
- * once we are confident with the code */
-
- infos = g_hash_table_get_keys (cloader->priv->loaded_plugins);
-
- for (item = infos; item; item = item->next)
- {
- PeasPluginInfo *info = (PeasPluginInfo *) item->data;
-
- if (peas_plugin_info_is_loaded (info))
- {
- g_warning ("There are still C plugins loaded during destruction");
- break;
- }
- }
-
- g_list_free (infos);
g_hash_table_destroy (cloader->priv->loaded_plugins);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]