[libpeas] Replace plugin loader disabling with enabling
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Replace plugin loader disabling with enabling
- Date: Fri, 11 Feb 2011 10:38:29 +0000 (UTC)
commit a3bb19e23029f73628ef560773c8f68c84baf13d
Author: Garrett Regier <alias301 gmail com>
Date: Thu Feb 10 00:45:58 2011 -0800
Replace plugin loader disabling with enabling
This way applications are future proof in new
loaders are enabled that would have been disabled.
libpeas/peas-engine.c | 34 +++++++++-----------
libpeas/peas-engine.h | 2 +-
peas-demo/peas-demo.c | 3 ++
tests/libpeas/engine.c | 25 ++++----------
tests/libpeas/extension-python.c | 6 ++-
tests/libpeas/extension-seed.c | 6 ++-
tests/libpeas/testing/testing-extension.h | 6 +++
tests/libpeas/testing/testing.c | 49 +++++++++++++++-------------
tests/libpeas/testing/testing.h | 2 +
9 files changed, 68 insertions(+), 65 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index af96bf8..55e760f 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -303,6 +303,8 @@ peas_engine_init (PeasEngine *engine)
PeasEnginePrivate);
engine->priv->in_dispose = FALSE;
+
+ peas_engine_enable_loader (engine, "C");
}
static void
@@ -671,29 +673,31 @@ get_plugin_loader (PeasEngine *engine,
loader_id);
if (loader_info == NULL)
- loader_info = load_plugin_loader (engine, loader_id);
+ return NULL;
return loader_info->loader;
}
/**
- * peas_engine_disable_loader:
+ * peas_engine_enable_loader:
* @engine: A #PeasEngine.
- * @loader_id: The id of the loader to inhibit.
+ * @loader_id: The id of the loader to enable.
*
- * Disable a loader, avoiding using the plugins written using the
- * related language to be loaded. This method must be called before
- * any plugin relying on the loader @loader_id has been loaded.
+ * Enable a loader, enables a loader for plugins.
+ * The C plugin loader is always enabled.
*
- * For instance, the following code will prevent any python plugin
+ * For instance, the following code will enable python plugin
* from being loaded:
* |[
- * peas_engine_disable_loader (engine, "python");
+ * peas_engine_enable_loader (engine, "python");
* ]|
+ *
+ * Note: plugin loaders are shared across #PeasEngines so enabeling
+ * a loader on one #PeasEngine will enable it on all #PeasEngines.
**/
void
-peas_engine_disable_loader (PeasEngine *engine,
- const gchar *loader_id)
+peas_engine_enable_loader (PeasEngine *engine,
+ const gchar *loader_id)
{
LoaderInfo *loader_info;
@@ -701,17 +705,9 @@ peas_engine_disable_loader (PeasEngine *engine,
loader_info = (LoaderInfo *) g_hash_table_lookup (loaders,
loader_id);
- if (loader_info != NULL && loader_info->module != NULL)
- {
- g_warning ("Loader '%s' cannot be disabled as it is already loaded",
- loader_id);
- return;
- }
- /* By adding a NULL loader, we simulate a failed load attempt, effectively
- * disabling the loader for further use. */
if (loader_info == NULL)
- add_loader (engine, loader_id, NULL, NULL);
+ load_plugin_loader (engine, loader_id);
}
/**
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index 1a7b45b..e258fd5 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -77,7 +77,7 @@ void peas_engine_add_search_path (PeasEngine *engine,
const gchar *data_dir);
/* plugin management */
-void peas_engine_disable_loader (PeasEngine *engine,
+void peas_engine_enable_loader (PeasEngine *engine,
const gchar *loader_id);
void peas_engine_rescan_plugins (PeasEngine *engine);
const GList *peas_engine_get_plugin_list (PeasEngine *engine);
diff --git a/peas-demo/peas-demo.c b/peas-demo/peas-demo.c
index 20640cc..4f762f6 100644
--- a/peas-demo/peas-demo.c
+++ b/peas-demo/peas-demo.c
@@ -125,6 +125,9 @@ main (int argc,
peas_engine_add_search_path (engine, plugin_dir, plugin_dir);
g_free (plugin_dir);
+ peas_engine_enable_loader (engine, "python");
+ peas_engine_enable_loader (engine, "seed");
+
if (run_from_build_dir)
peas_engine_add_search_path (engine, "./plugins", NULL);
else
diff --git a/tests/libpeas/engine.c b/tests/libpeas/engine.c
index 9b8e97d..8506636 100644
--- a/tests/libpeas/engine.c
+++ b/tests/libpeas/engine.c
@@ -299,14 +299,13 @@ test_engine_nonexistent_loader (PeasEngine *engine)
}
static void
-test_engine_disable_loader (PeasEngine *engine)
+test_engine_enable_loader (PeasEngine *engine)
{
PeasPluginInfo *info;
- /* We have to use an unused loader because loaders
- * cannot be disabled after the loader has been loaded.
- *
- * The loader is disabled in testing_engine_new()
+ /* The extension tests implicitly test enabling a loader
+ * This is only to test that the engine will fail to load
+ * a plugin if it's loader is not enabled.
*/
info = peas_engine_get_plugin_info (engine, "loader-disabled");
@@ -316,18 +315,8 @@ test_engine_disable_loader (PeasEngine *engine)
g_assert (!peas_plugin_info_is_available (info, NULL));
- info = peas_engine_get_plugin_info (engine, "loadable");
-
- g_assert (peas_engine_load_plugin (engine, info));
-
- /* Cannot disable the C loader as it has already been enabled */
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
- {
- peas_engine_disable_loader (engine, "C");
- exit (0);
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*Loader 'C' cannot be disabled*");
+ /* Make sure loaders can be enabled multiple times */
+ peas_engine_enable_loader (engine, "C");
}
static void
@@ -403,7 +392,7 @@ main (int argc,
TEST ("loaded-plugins", loaded_plugins);
TEST ("nonexistent-loader", nonexistent_loader);
- TEST ("disable-loader", disable_loader);
+ TEST ("enable-loader", enable_loader);
/* MUST be last */
TEST ("shutdown", shutdown);
diff --git a/tests/libpeas/extension-python.c b/tests/libpeas/extension-python.c
index 7c4e602..3adef09 100644
--- a/tests/libpeas/extension-python.c
+++ b/tests/libpeas/extension-python.c
@@ -35,6 +35,10 @@ main (int argc,
g_type_init ();
+ testing_init ();
+
+ peas_engine_enable_loader (peas_engine_get_default (), "python");
+
testing_extension_set_plugin_ ("extension-" "python");
_EXTENSION_TEST ("python", "create-valid", create_valid);
@@ -57,7 +61,5 @@ main (int argc,
_EXTENSION_TEST ("python", "properties-readwrite", properties_readwrite);
#endif
- g_object_unref (peas_engine_get_default ());
-
return g_test_run ();
}
diff --git a/tests/libpeas/extension-seed.c b/tests/libpeas/extension-seed.c
index 738978e..42d3bc5 100644
--- a/tests/libpeas/extension-seed.c
+++ b/tests/libpeas/extension-seed.c
@@ -35,6 +35,10 @@ main (int argc,
g_type_init ();
+ testing_init ();
+
+ peas_engine_enable_loader (peas_engine_get_default (), "seed");
+
testing_extension_set_plugin_ ("extension-" "seed");
_EXTENSION_TEST ("seed", "create-valid", create_valid);
@@ -59,7 +63,5 @@ main (int argc,
_EXTENSION_TEST ("seed", "properties-readwrite", properties_readwrite);
#endif
- g_object_unref (peas_engine_get_default ());
-
return g_test_run ();
}
diff --git a/tests/libpeas/testing/testing-extension.h b/tests/libpeas/testing/testing-extension.h
index cbccec9..34b378b 100644
--- a/tests/libpeas/testing/testing-extension.h
+++ b/tests/libpeas/testing/testing-extension.h
@@ -24,6 +24,8 @@
#include <libpeas/peas-engine.h>
+#include "testing.h"
+
G_BEGIN_DECLS
typedef struct _TestingExtensionFixture_ TestingExtensionFixture_;
@@ -71,6 +73,10 @@ main (int argc, \
\
g_type_init (); \
\
+ testing_init (); \
+\
+ peas_engine_enable_loader (peas_engine_get_default (), loader); \
+\
testing_extension_set_plugin_ ("extension-" loader); \
\
_EXTENSION_TEST (loader, "create-valid", create_valid); \
diff --git a/tests/libpeas/testing/testing.c b/tests/libpeas/testing/testing.c
index e3da2c4..93a54c1 100644
--- a/tests/libpeas/testing/testing.c
+++ b/tests/libpeas/testing/testing.c
@@ -88,47 +88,50 @@ out:
abort ();
}
-PeasEngine *
-testing_engine_new (void)
+void
+testing_init (void)
{
GError *error = NULL;
static gboolean initialized = FALSE;
- if (engine != NULL)
- return engine;
+ if (initialized)
+ return;
- if (!initialized)
- {
- /* Don't always abort on warnings */
- g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
+ /* Don't always abort on warnings */
+ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
- default_log_func = g_log_set_default_handler (log_handler, NULL);
+ default_log_func = g_log_set_default_handler (log_handler, NULL);
- g_irepository_prepend_search_path (BUILDDIR "/libpeas");
+ g_irepository_prepend_search_path (BUILDDIR "/libpeas");
- g_setenv ("PEAS_PLUGIN_LOADERS_DIR", BUILDDIR "/loaders", TRUE);
+ g_setenv ("PEAS_PLUGIN_LOADERS_DIR", BUILDDIR "/loaders", TRUE);
- g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error);
- g_assert_no_error (error);
+ g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error);
+ g_assert_no_error (error);
- g_irepository_require_private (g_irepository_get_default (),
- BUILDDIR "/tests/libpeas/introspection",
- "Introspection", "1.0", 0, &error);
- g_assert_no_error (error);
+ g_irepository_require_private (g_irepository_get_default (),
+ BUILDDIR "/tests/libpeas/introspection",
+ "Introspection", "1.0", 0, &error);
+ g_assert_no_error (error);
- g_atexit (peas_engine_shutdown);
+ g_atexit (peas_engine_shutdown);
- initialized = TRUE;
- }
+ initialized = TRUE;
+}
+
+PeasEngine *
+testing_engine_new (void)
+{
+ if (engine != NULL)
+ return engine;
+
+ testing_init ();
/* Must be after requiring typelibs */
engine = peas_engine_get_default ();
g_object_add_weak_pointer (G_OBJECT (engine), (gpointer *) &engine);
- /* Disabled here incase another tests tries to load it */
- peas_engine_disable_loader (engine, "disabled");
-
peas_engine_add_search_path (engine, BUILDDIR "/tests/plugins", NULL);
peas_engine_add_search_path (engine, BUILDDIR "/tests/libpeas/plugins", NULL);
diff --git a/tests/libpeas/testing/testing.h b/tests/libpeas/testing/testing.h
index 31c486c..4c20595 100644
--- a/tests/libpeas/testing/testing.h
+++ b/tests/libpeas/testing/testing.h
@@ -26,6 +26,8 @@
G_BEGIN_DECLS
+void testing_init (void);
+
PeasEngine *testing_engine_new (void);
void testing_engine_free (PeasEngine *engine);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]