[libpeas] Cleanup the plugin loaders
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Cleanup the plugin loaders
- Date: Sun, 6 Mar 2011 12:57:56 +0000 (UTC)
commit b2ae6235475b6ed8536f957012e62c368e3ffd13
Author: Garrett Regier <alias301 gmail com>
Date: Fri Mar 4 22:39:13 2011 -0800
Cleanup the plugin loaders
loaders/c/peas-plugin-loader-c.c | 14 +------
loaders/python/peas-plugin-loader-python.c | 54 ++++++++++------------------
loaders/seed/peas-plugin-loader-seed.c | 13 ++-----
3 files changed, 24 insertions(+), 57 deletions(-)
---
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 0e6cd34..c09aca1 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -31,8 +31,7 @@
#include <libpeas/peas-object-module.h>
#include <libpeas/peas-extension-base.h>
-struct _PeasPluginLoaderCPrivate
-{
+struct _PeasPluginLoaderCPrivate {
GHashTable *loaded_plugins;
};
@@ -76,7 +75,6 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
g_hash_table_insert (cloader->priv->loaded_plugins,
g_strdup (module_name), module);
- g_debug ("Insert module '%s' into C module set", module_name);
}
if (!g_type_module_use (G_TYPE_MODULE (module)))
@@ -102,7 +100,6 @@ peas_plugin_loader_c_provides_extension (PeasPluginLoader *loader,
module_name = 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, FALSE);
return peas_object_module_provides_object (module, exten_type);
}
@@ -123,7 +120,6 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
module_name = 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
@@ -151,12 +147,7 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
g_free (exten_parameters);
if (instance == NULL)
- {
- g_debug ("Plugin '%s' does not provide a '%s' extension",
- peas_plugin_info_get_module_name (info),
- g_type_name (exten_type));
- return NULL;
- }
+ return NULL;
g_return_val_if_fail (G_IS_OBJECT (instance), NULL);
g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (instance, exten_type), NULL);
@@ -176,7 +167,6 @@ peas_plugin_loader_c_unload (PeasPluginLoader *loader,
module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
module_name);
- g_debug ("Unloading plugin '%s'", module_name);
g_type_module_unuse (G_TYPE_MODULE (module));
}
diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c
index 13a9e53..95de6b9 100644
--- a/loaders/python/peas-plugin-loader-python.c
+++ b/loaders/python/peas-plugin-loader-python.c
@@ -54,7 +54,7 @@ typedef struct {
static PyObject *PyGObject_Type;
-static gboolean peas_plugin_loader_python_add_module_path (PeasPluginLoaderPython *self,
+static gboolean peas_plugin_loader_python_add_module_path (PeasPluginLoaderPython *pyloader,
const gchar *module_path);
G_DEFINE_TYPE (PeasPluginLoaderPython, peas_plugin_loader_python, PEAS_TYPE_PLUGIN_LOADER);
@@ -123,9 +123,6 @@ peas_plugin_loader_python_provides_extension (PeasPluginLoader *loader,
pyinfo = (PythonInfo *) g_hash_table_lookup (pyloader->priv->loaded_plugins, info);
- if (pyinfo == NULL)
- return FALSE;
-
state = pyg_gil_state_ensure ();
extension_type = find_python_extension_type (info, exten_type, pyinfo->module);
pyg_gil_state_release (state);
@@ -152,9 +149,6 @@ peas_plugin_loader_python_create_extension (PeasPluginLoader *loader,
pyinfo = (PythonInfo *) g_hash_table_lookup (pyloader->priv->loaded_plugins, info);
- if (pyinfo == NULL)
- return NULL;
-
state = pyg_gil_state_ensure ();
pytype = find_python_extension_type (info, exten_type, pyinfo->module);
@@ -318,17 +312,6 @@ peas_plugin_loader_python_unload (PeasPluginLoader *loader,
PeasPluginInfo *info)
{
PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader);
- PythonInfo *pyinfo;
- PyGILState_STATE state;
-
- pyinfo = (PythonInfo *) g_hash_table_lookup (pyloader->priv->loaded_plugins, info);
-
- if (!pyinfo)
- return;
-
- state = pyg_gil_state_ensure ();
- Py_XDECREF (pyinfo->module);
- pyg_gil_state_release (state);
g_hash_table_remove (pyloader->priv->loaded_plugins, info);
}
@@ -356,13 +339,11 @@ run_gc (PeasPluginLoaderPython *loader)
static void
peas_plugin_loader_python_garbage_collect (PeasPluginLoader *loader)
{
- PeasPluginLoaderPython *pyloader;
+ PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader);
- if (!Py_IsInitialized ())
+ if (pyloader->priv->init_failed)
return;
- pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader);
-
/*
* We both run the GC right now and we schedule
* a further collection in the main loop.
@@ -406,15 +387,15 @@ peas_python_shutdown (PeasPluginLoaderPython *loader)
*/
/* NOTE: This must be called with the GIL held */
static gboolean
-peas_plugin_loader_python_add_module_path (PeasPluginLoaderPython *self,
+peas_plugin_loader_python_add_module_path (PeasPluginLoaderPython *pyloader,
const gchar *module_path)
{
PyObject *pathlist, *pathstring;
- g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER_PYTHON (self), FALSE);
+ g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER_PYTHON (pyloader), FALSE);
g_return_val_if_fail (module_path != NULL, FALSE);
- if (!Py_IsInitialized ())
+ if (pyloader->priv->init_failed)
return FALSE;
pathlist = PySys_GetObject ((char*) "path");
@@ -450,6 +431,7 @@ peas_python_init (PeasPluginLoaderPython *loader)
if (prgname != NULL)
argv[0] = prgname;
+ /* See http://docs.python.org/c-api/init.html#PySys_SetArgvEx */
#if PY_VERSION_HEX < 0x02060600
PySys_SetArgv (1, (char**) argv);
PyRun_SimpleString ("import sys; sys.path.pop(0)\n");
@@ -540,27 +522,29 @@ static void
destroy_python_info (PythonInfo *info)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
- Py_XDECREF (info->module);
+
+ Py_DECREF (info->module);
+
pyg_gil_state_release (state);
g_free (info);
}
static void
-peas_plugin_loader_python_init (PeasPluginLoaderPython *self)
+peas_plugin_loader_python_init (PeasPluginLoaderPython *pyloader)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- PEAS_TYPE_PLUGIN_LOADER_PYTHON,
- PeasPluginLoaderPythonPrivate);
+ pyloader->priv = G_TYPE_INSTANCE_GET_PRIVATE (pyloader,
+ PEAS_TYPE_PLUGIN_LOADER_PYTHON,
+ PeasPluginLoaderPythonPrivate);
/* initialize python interpreter */
- peas_python_init (self);
+ peas_python_init (pyloader);
/* loaded_plugins maps PeasPluginInfo to a PythonInfo */
- self->priv->loaded_plugins = g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- NULL,
- (GDestroyNotify) destroy_python_info);
+ pyloader->priv->loaded_plugins = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ (GDestroyNotify) destroy_python_info);
}
static void
diff --git a/loaders/seed/peas-plugin-loader-seed.c b/loaders/seed/peas-plugin-loader-seed.c
index a7a9820..36261db 100644
--- a/loaders/seed/peas-plugin-loader-seed.c
+++ b/loaders/seed/peas-plugin-loader-seed.c
@@ -143,8 +143,6 @@ peas_plugin_loader_seed_provides_extension (PeasPluginLoader *loader,
SeedValue extension;
sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);
- if (!sinfo)
- return FALSE;
extension = seed_object_get_property (sinfo->context,
sinfo->extensions,
@@ -166,14 +164,14 @@ peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
guint i, j;
sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);
- if (!sinfo)
- return NULL;
/* FIXME: instantiate new object and pass the parameters */
extension_methods = seed_object_get_property (sinfo->context,
sinfo->extensions,
g_type_name (exten_type));
- if (!extension_methods || seed_value_is_undefined (sinfo->context, extension_methods) || seed_value_is_null (sinfo->context, extension_methods))
+ if (!extension_methods ||
+ seed_value_is_undefined (sinfo->context, extension_methods) ||
+ seed_value_is_null (sinfo->context, extension_methods))
return NULL;
if (!seed_value_is_object (sinfo->context, extension_methods))
@@ -234,11 +232,6 @@ peas_plugin_loader_seed_unload (PeasPluginLoader *loader,
PeasPluginInfo *info)
{
PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader);
- SeedInfo *sinfo;
-
- sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);
- if (!sinfo)
- return;
g_hash_table_remove (sloader->loaded_plugins, info);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]