gplugin/gplugin

04f8758f9a72
Parents 4abae92ecef8
Children 9f181ca46179
Add the ability to disable the native plugin loader

Add support for the ability to disable the native plugin loader. This is primarily a debug tool right now. Fixes GPLUGIN-103

Testing Done:
Built and ran the unit tests locally.

Reviewed at https://reviews.imfreedom.org/r/110/
--- a/gplugin-gtk-viewer/gplugin-gtk-viewer.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin-gtk-viewer/gplugin-gtk-viewer.c Mon Sep 14 20:39:42 2020 -0500
@@ -207,7 +207,7 @@
gtk_init(&argc, &argv);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
if(add_default_paths)
gplugin_manager_add_default_paths();
--- a/gplugin-query/gplugin-query.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin-query/gplugin-query.c Mon Sep 14 20:39:42 2020 -0500
@@ -296,8 +296,6 @@
GOptionGroup *group = NULL;
gint i = 0, ret = 0;
- gplugin_init();
-
ctx = g_option_context_new("PLUGIN-ID...");
g_option_context_set_summary(ctx, _("Query installed plugins"));
g_option_context_set_translation_domain(ctx, GETTEXT_PACKAGE);
@@ -319,6 +317,11 @@
return EXIT_FAILURE;
}
+ /* This is just for consistency, but the gplugins-option will init the
+ * library for us.
+ */
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
+
if(output_paths) {
GList *path = NULL;
--- a/gplugin/gplugin-core.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-core.c Mon Sep 14 20:39:42 2020 -0500
@@ -50,6 +50,7 @@
/**
* gplugin_init:
+ * @flags: The #GPluginCoreFlags to set.
*
* Initializes the GPlugin library.
*
@@ -59,12 +60,18 @@
* gplugin_init().
*/
void
-gplugin_init(void)
+gplugin_init(GPluginCoreFlags flags)
{
+ gboolean register_native_loader = TRUE;
+
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
- gplugin_manager_private_init();
+ if(flags & GPLUGIN_CORE_FLAGS_DISABLE_NATIVE_LOADER) {
+ register_native_loader = FALSE;
+ }
+
+ gplugin_manager_private_init(register_native_loader);
}
/**
--- a/gplugin/gplugin-core.h Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-core.h Mon Sep 14 20:39:42 2020 -0500
@@ -27,9 +27,16 @@
#define GPLUGIN_DOMAIN (g_quark_from_static_string("gplugin"))
+/* clang-format off */
+typedef enum /*< flags,prefix=GPLUGIN_CORE_FLAGS,underscore_name=GPLUGIN_CORE >*/ {
+ GPLUGIN_CORE_FLAGS_NONE = 0,
+ GPLUGIN_CORE_FLAGS_DISABLE_NATIVE_LOADER = 1 << 0,
+} GPluginCoreFlags;
+/* clang-format on */
+
G_BEGIN_DECLS
-void gplugin_init(void);
+void gplugin_init(GPluginCoreFlags flags);
void gplugin_uninit(void);
G_END_DECLS
--- a/gplugin/gplugin-loader-tests.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-loader-tests.c Mon Sep 14 20:39:42 2020 -0500
@@ -256,7 +256,7 @@
const gchar *plugin_dir,
const gchar *short_name)
{
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_setenv("GI_TYPELIB_PATH", GI_TYPELIB_PATH, TRUE);
--- a/gplugin/gplugin-manager.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-manager.c Mon Sep 14 20:39:42 2020 -0500
@@ -90,6 +90,7 @@
GPluginManager *manager,
GType type,
GError **error);
+ GSList *(*get_loaders)(GPluginManager *manager);
void (*refresh)(GPluginManager *manager);
@@ -512,6 +513,12 @@
return TRUE;
}
+static GSList *
+gplugin_manager_real_get_loaders(GPluginManager *manager)
+{
+ return g_slist_copy_deep(manager->loaders, (GCopyFunc)g_object_ref, NULL);
+}
+
static void
gplugin_manager_real_refresh(GPluginManager *manager)
{
@@ -1190,6 +1197,7 @@
manager_class->register_loader = gplugin_manager_real_register_loader;
manager_class->unregister_loader = gplugin_manager_real_unregister_loader;
+ manager_class->get_loaders = gplugin_manager_real_get_loaders;
manager_class->refresh = gplugin_manager_real_refresh;
@@ -1374,7 +1382,7 @@
* Private API
*****************************************************************************/
void
-gplugin_manager_private_init(void)
+gplugin_manager_private_init(gboolean register_native_loader)
{
GError *error = NULL;
@@ -1384,12 +1392,16 @@
instance = g_object_new(GPLUGIN_TYPE_MANAGER, NULL);
- if(!gplugin_manager_register_loader(GPLUGIN_TYPE_NATIVE_LOADER, &error)) {
- if(error != NULL) {
- g_error("failed to register loader: %s", error->message);
- g_error_free(error);
- } else {
- g_error("failed to register loader: unknown failure");
+ if(register_native_loader) {
+ if(!gplugin_manager_register_loader(
+ GPLUGIN_TYPE_NATIVE_LOADER,
+ &error)) {
+ if(error != NULL) {
+ g_error("failed to register loader: %s", error->message);
+ g_error_free(error);
+ } else {
+ g_error("failed to register loader: unknown failure");
+ }
}
}
@@ -1619,6 +1631,29 @@
}
/**
+ * gplugin_manager_get_loaders:
+ *
+ * Returns a list of all registered #GPluginLoader's.
+ *
+ * Returns: (element-type GPlugin.Loader) (transfer full): Returns a list of all
+ * registered loaders.
+ */
+GSList *
+gplugin_manager_get_loaders(void)
+{
+ GPluginManager *manager = GPLUGIN_MANAGER_INSTANCE;
+ GPluginManagerClass *klass = NULL;
+
+ g_return_val_if_fail(GPLUGIN_IS_MANAGER(manager), FALSE);
+
+ klass = GPLUGIN_MANAGER_GET_CLASS(manager);
+ if(klass && klass->get_loaders)
+ return klass->get_loaders(manager);
+
+ return NULL;
+}
+
+/**
* gplugin_manager_refresh:
*
* Forces a refresh of all plugins found in the search paths.
--- a/gplugin/gplugin-manager.h Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-manager.h Mon Sep 14 20:39:42 2020 -0500
@@ -46,6 +46,7 @@
gboolean gplugin_manager_register_loader(GType type, GError **error);
gboolean gplugin_manager_unregister_loader(GType type, GError **error);
+GSList *gplugin_manager_get_loaders(void);
void gplugin_manager_refresh(void);
--- a/gplugin/gplugin-options.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-options.c Mon Sep 14 20:39:42 2020 -0500
@@ -36,7 +36,7 @@
/******************************************************************************
* Options
*****************************************************************************/
-static gboolean add_default_paths = TRUE;
+static gboolean add_default_paths = TRUE, register_native_loader = TRUE;
static gchar **paths = NULL;
static gboolean
@@ -51,6 +51,17 @@
return TRUE;
}
+static gboolean
+gplugin_options_no_native_loader_cb(
+ G_GNUC_UNUSED const gchar *n,
+ G_GNUC_UNUSED const gchar *v,
+ G_GNUC_UNUSED gpointer d,
+ G_GNUC_UNUSED GError **e)
+{
+ register_native_loader = FALSE;
+
+ return TRUE;
+}
/* clang-format off */
static GOptionEntry entries[] = {
{
@@ -59,6 +70,11 @@
N_("Do not search the default plugin paths"),
NULL,
}, {
+ "no-native-loader", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ gplugin_options_no_native_loader_cb,
+ N_("Do not register the native plugin loaders"),
+ NULL,
+ }, {
"path", 'p', 0, G_OPTION_ARG_STRING_ARRAY,
&paths, N_("Additional path to look for plugins"),
NULL,
@@ -75,9 +91,14 @@
G_GNUC_UNUSED gpointer data,
G_GNUC_UNUSED GError **error)
{
+ GPluginCoreFlags flags = GPLUGIN_CORE_FLAGS_NONE;
gint i = 0;
- gplugin_init();
+ if(!register_native_loader) {
+ flags |= GPLUGIN_CORE_FLAGS_DISABLE_NATIVE_LOADER;
+ }
+
+ gplugin_init(flags);
if(add_default_paths)
gplugin_manager_add_default_paths();
--- a/gplugin/gplugin-private.h Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/gplugin-private.h Mon Sep 14 20:39:42 2020 -0500
@@ -30,7 +30,7 @@
G_BEGIN_DECLS
-void gplugin_manager_private_init(void);
+void gplugin_manager_private_init(gboolean register_native_loader);
void gplugin_manager_private_uninit(void);
gboolean gplugin_boolean_accumulator(
--- a/gplugin/meson.build Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/meson.build Mon Sep 14 20:39:42 2020 -0500
@@ -62,6 +62,7 @@
# gplugin-enum.[ch] generation
###############################################################################
ENUM_HEADERS = [
+ 'gplugin-core.h',
'gplugin-plugin.h',
]
--- a/gplugin/tests/test-bind-global.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-bind-global.c Mon Sep 14 20:39:42 2020 -0500
@@ -54,7 +54,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
/* test the load on query flag */
g_test_add_func("/loaders/native/bind-global", test_bind_global);
--- a/gplugin/tests/test-core.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-core.c Mon Sep 14 20:39:42 2020 -0500
@@ -58,22 +58,22 @@
static void
test_gplugin_init_uninit(void)
{
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_uninit();
}
static void
test_gplugin_init_init_uninit(void)
{
- gplugin_init();
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_uninit();
}
static void
test_gplugin_init_uninit_with_refresh(void)
{
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_manager_refresh();
gplugin_uninit();
}
@@ -81,7 +81,7 @@
static void
test_gplugin_init_uninit_with_refresh_plugins(void)
{
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_manager_append_path(TEST_DIR);
gplugin_manager_refresh();
gplugin_uninit();
@@ -92,7 +92,7 @@
{
gint f_ids = 0, s_ids = 0, f_plugins = 0, s_plugins = 0;
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_manager_append_path(TEST_DIR);
gplugin_manager_append_path(TEST_ID_DIR);
@@ -113,6 +113,16 @@
gplugin_uninit();
}
+static void
+test_gplugin_init_no_native_loader(void)
+{
+ gplugin_init(GPLUGIN_CORE_FLAGS_DISABLE_NATIVE_LOADER);
+
+ g_assert_null(gplugin_manager_get_loaders());
+
+ gplugin_uninit();
+}
+
/******************************************************************************
* Main
*****************************************************************************/
@@ -133,5 +143,9 @@
"/core/init_uninit_with_double_refresh_plugins",
test_gplugin_init_uninit_with_double_refresh_plugins);
+ g_test_add_func(
+ "/core/init/no-native-loader",
+ test_gplugin_init_no_native_loader);
+
return g_test_run();
}
--- a/gplugin/tests/test-dynamic-type.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-dynamic-type.c Mon Sep 14 20:39:42 2020 -0500
@@ -77,7 +77,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
/* test dynamic types */
g_test_add_func("/loaders/native/dynamic-type", test_dynamic_type);
--- a/gplugin/tests/test-find-plugins.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-find-plugins.c Mon Sep 14 20:39:42 2020 -0500
@@ -82,7 +82,7 @@
gint UNLOADED = 3; /* unloaded plugins go back to the queried state */
gint UNLOAD_FAILED = 1;
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_manager_append_path(TEST_DIR);
gplugin_manager_refresh();
--- a/gplugin/tests/test-id-collision.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-id-collision.c Mon Sep 14 20:39:42 2020 -0500
@@ -51,7 +51,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func("/loaders/native/id-collision", test_id_collision);
--- a/gplugin/tests/test-load-on-query.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-load-on-query.c Mon Sep 14 20:39:42 2020 -0500
@@ -83,7 +83,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
/* test the load on query flag */
g_test_add_func("/loaders/native/load-on-query/pass", test_load_on_query);
--- a/gplugin/tests/test-loader-registration.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-loader-registration.c Mon Sep 14 20:39:42 2020 -0500
@@ -98,7 +98,7 @@
gboolean ret;
gplugin_manager_private_uninit();
- gplugin_manager_private_init();
+ gplugin_manager_private_init(TRUE);
ret = gplugin_manager_register_loader(TEST_GPLUGIN_TYPE_LOADER, &error);
@@ -118,7 +118,7 @@
gboolean ret;
gplugin_manager_private_uninit();
- gplugin_manager_private_init();
+ gplugin_manager_private_init(TRUE);
ret = gplugin_manager_register_loader(TEST_GPLUGIN_TYPE_LOADER, &error);
g_assert_true(ret);
@@ -142,7 +142,7 @@
gboolean ret;
gplugin_manager_private_uninit();
- gplugin_manager_private_init();
+ gplugin_manager_private_init(TRUE);
ret = gplugin_manager_register_loader(TEST_GPLUGIN_TYPE_LOADER, &error);
g_assert_true(ret);
@@ -168,7 +168,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func(
"/manager/loader/register_unregister",
--- a/gplugin/tests/test-native-loader.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-native-loader.c Mon Sep 14 20:39:42 2020 -0500
@@ -89,7 +89,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_loader_tests_main(NULL, TEST_DIR, "native");
--- a/gplugin/tests/test-newest-version.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-newest-version.c Mon Sep 14 20:39:42 2020 -0500
@@ -95,7 +95,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func(
"/manager/find_plugin_newest_version/multiple-semantic",
--- a/gplugin/tests/test-plugin-info.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-plugin-info.c Mon Sep 14 20:39:42 2020 -0500
@@ -391,7 +391,7 @@
{
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func(
"/plugin-info/construction",
--- a/gplugin/tests/test-plugin-manager-paths.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-plugin-manager-paths.c Mon Sep 14 20:39:42 2020 -0500
@@ -212,7 +212,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func(
"/plugins/paths/add_remove_single",
--- a/gplugin/tests/test-signals.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-signals.c Mon Sep 14 20:39:42 2020 -0500
@@ -397,7 +397,7 @@
{
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
g_test_add_func(
"/manager/signals/normal",
--- a/gplugin/tests/test-unresolved-symbol.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-unresolved-symbol.c Mon Sep 14 20:39:42 2020 -0500
@@ -50,7 +50,7 @@
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
/* test the load on query flag */
g_test_add_func(
--- a/gplugin/tests/test-version-compare.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-version-compare.c Mon Sep 14 20:39:42 2020 -0500
@@ -154,7 +154,7 @@
{
g_test_init(&argc, &argv, NULL);
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
/* bad versions */
g_test_add_func(
--- a/gplugin/tests/test-versioned-dependencies.c Mon Sep 14 20:36:36 2020 -0500
+++ b/gplugin/tests/test-versioned-dependencies.c Mon Sep 14 20:39:42 2020 -0500
@@ -46,7 +46,7 @@
GError *error = NULL;
gboolean ret = FALSE;
- gplugin_init();
+ gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
gplugin_manager_append_path(TEST_VERSIONED_DEPENDENCY_DIR);
gplugin_manager_refresh();