Make the basic plugins verify that they've been called with the correct parameters
Testing Done:
Ran the unit tests but the perl load is being a pain and I'm considering dropping it. See the comment in the code for more information.
Reviewed at https://reviews.imfreedom.org/r/817/
--- a/gplugin/tests/plugins/basic-plugin.c Thu Jul 15 00:44:27 2021 -0500
+++ b/gplugin/tests/plugins/basic-plugin.c Fri Jul 23 04:07:52 2021 -0500
@@ -40,14 +40,28 @@
-basic_load(G_GNUC_UNUSED GPluginPlugin *plugin, G_GNUC_UNUSED GError **error)
+basic_load(GPluginPlugin *plugin, GError **error) + if(!GPLUGIN_IS_PLUGIN(plugin)) { + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "plugin was not set"); -basic_unload(G_GNUC_UNUSED GPluginPlugin *plugin, G_GNUC_UNUSED GError **error)
+ if(!GPLUGIN_IS_PLUGIN(plugin)) { + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "plugin was not set"); --- a/lua/tests/plugins/basic.lua Thu Jul 15 00:44:27 2021 -0500
+++ b/lua/tests/plugins/basic.lua Fri Jul 23 04:07:52 2021 -0500
@@ -34,9 +34,17 @@
function gplugin_load(plugin)
function gplugin_unload(plugin)
--- a/perl5/gplugin-perl5-loader.c Thu Jul 15 00:44:27 2021 -0500
+++ b/perl5/gplugin-perl5-loader.c Fri Jul 23 04:07:52 2021 -0500
@@ -77,6 +77,7 @@
GPluginPluginInfo *info = NULL;
PerlInterpreter *old = NULL;
@@ -95,17 +96,19 @@
- "gplugin_query did not return a GPluginPluginInfo");
+ /* ERRSV is a macro, so we store it instead of calling it multiple times. */ + const gchar *errmsg = SvPVutf8_nolen(err_tmp); + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg);
- const gchar *errmsg = SvPVutf8_nolen(ERRSV);
- g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg);
+ "gplugin_query did not return a GPluginPluginInfo"); info = (GPluginPluginInfo *)gperl_get_object(POPs);
@@ -128,59 +131,6 @@
-gplugin_perl_loader_call_boolean(
- PerlInterpreter *interpreter,
- PerlInterpreter *old = NULL;
- PERL_SET_CONTEXT(interpreter);
- count = call_pv(func, G_EVAL | G_SCALAR);
- "%s did not return a value",
- const gchar *errmsg = SvPVutf8_nolen(ERRSV);
- g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg);
/******************************************************************************
* GPluginLoaderInterface API
*****************************************************************************/
@@ -243,7 +193,9 @@
info = gplugin_perl_loader_call_gplugin_query(interpreter, error);
if(!GPLUGIN_IS_PLUGIN_INFO(info)) {
- g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "failed to query");
+ if(error != NULL && *error == NULL) { + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "failed to query"); @@ -268,11 +220,60 @@
GPluginPerlPlugin *pplugin = GPLUGIN_PERL_PLUGIN(plugin);
- PerlInterpreter *interpreter = NULL;
+ PerlInterpreter *old = NULL; + my_perl = gplugin_perl_plugin_get_interpreter(pplugin); + PERL_SET_CONTEXT(my_perl); + PUSHs(sv_2mortal(newSVGObject(G_OBJECT(pplugin)))); + count = call_pv("gplugin_load", G_EVAL | G_SCALAR); + /* ERRSV is a macro, so we store it instead of calling it multiple times. */ + const gchar *errmsg = SvPVutf8_nolen(err_tmp); - interpreter = gplugin_perl_plugin_get_interpreter(pplugin);
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg); + "gplugin_load did not return a value"); - return gplugin_perl_loader_call_boolean(interpreter, "gplugin_load", error);
+ /* this is magic and is keeping this working. Why I don't know, but we're + * debating chucking this loader out the window and I want to create this + * review request so I'm leaving it in for now... + g_message("load returning: %d for %s", r, gplugin_plugin_get_filename(plugin)); @@ -282,14 +283,54 @@
GPluginPerlPlugin *pplugin = GPLUGIN_PERL_PLUGIN(plugin);
- PerlInterpreter *interpreter = NULL;
+ PerlInterpreter *old = NULL; - interpreter = gplugin_perl_plugin_get_interpreter(pplugin);
+ my_perl = gplugin_perl_plugin_get_interpreter(pplugin); + PERL_SET_CONTEXT(my_perl); + PUSHs(sv_2mortal(newSVGObject(G_OBJECT(pplugin)))); + count = call_pv("gplugin_unload", G_EVAL | G_SCALAR); - return gplugin_perl_loader_call_boolean(
+ /* ERRSV is a macro, so we store it instead of calling it multiple times. */ + const gchar *errmsg = SvPVutf8_nolen(err_tmp); + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg); + "gplugin_unload did not return a value"); /******************************************************************************
--- a/perl5/tests/plugins/basic.pl Thu Jul 15 00:44:27 2021 -0500
+++ b/perl5/tests/plugins/basic.pl Fri Jul 23 04:07:52 2021 -0500
@@ -16,8 +16,10 @@
use Glib::Object::Introspection;
+use Scalar::Util qw(blessed); -Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0", package=> "GPlugin");
+Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0", return GPlugin::PluginInfo->new(
@@ -35,9 +37,21 @@
+ if(!defined($plugin) or (blessed($plugin) and !$plugin->isa("GPlugin::Plugin"))) { + die("plugin is not a GPlugin::Plugin"); + if(!defined($plugin) or (blessed($plugin) and !$plugin->isa("GPlugin::Plugin"))) { + die("plugin is not a GPlugin::Plugin"); --- a/perl5/tests/plugins/dependent.pl Thu Jul 15 00:44:27 2021 -0500
+++ b/perl5/tests/plugins/dependent.pl Fri Jul 23 04:07:52 2021 -0500
@@ -17,19 +17,20 @@
use Glib::Object::Introspection;
-Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0", package=> "GPlugin");
+Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0",
return GPlugin::PluginInfo->new(
id => "gplugin/perl5-dependent-plugin",
dependencies => ['dependency1', 'dependency2'],
--- a/perl5/tests/plugins/load-exception.pl Thu Jul 15 00:44:27 2021 -0500
+++ b/perl5/tests/plugins/load-exception.pl Fri Jul 23 04:07:52 2021 -0500
@@ -17,20 +17,21 @@
use Glib::Object::Introspection;
-Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0", package=> "GPlugin");
+Glib::Object::Introspection->setup(basename => "GPlugin", version => "1.0",
return GPlugin::PluginInfo->new(
id => "gplugin/perl5-load-exception",
--- a/python3/gplugin-python3-loader.c Thu Jul 15 00:44:27 2021 -0500
+++ b/python3/gplugin-python3-loader.c Fri Jul 23 04:07:52 2021 -0500
@@ -1,5 +1,5 @@
- * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com>
+ * Copyright (C) 2011-2021 Gary Kramlich <grim@reaperworld.com> * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -80,7 +80,10 @@
module = PyImport_ImportModuleEx(module_name, NULL, NULL, package_list);
g_warning(_("Failed to query %s"), filename);
+ *error = gplugin_python3_exception_to_gerror(); /* clean some stuff up */
@@ -219,7 +222,7 @@
*error = gplugin_python3_exception_to_gerror();
@@ -246,7 +249,8 @@
- PyObject *unload = NULL, *pyplugin = NULL, *result = NULL;
+ PyObject *unload = NULL, *result = NULL; + PyObject *pyplugin = NULL; g_object_get(G_OBJECT(plugin), "unload-func", &unload, NULL);
@@ -257,9 +261,11 @@
+ *error = gplugin_python3_exception_to_gerror(); --- a/python3/gplugin-python3-utils.c Thu Jul 15 00:44:27 2021 -0500
+++ b/python3/gplugin-python3-utils.c Fri Jul 23 04:07:52 2021 -0500
@@ -78,12 +78,14 @@
PyObject *type = NULL, *value = NULL, *trace = NULL;
PyObject *type_name = NULL, *value_str = NULL, *obj = NULL;
+ if(!PyErr_Occurred()) { PyErr_Fetch(&type, &value, &trace);
PyErr_NormalizeException(&type, &value, &trace);
--- a/python3/tests/plugins/basic.py Thu Jul 15 00:44:27 2021 -0500
+++ b/python3/tests/plugins/basic.py Fri Jul 23 04:07:52 2021 -0500
@@ -36,8 +36,15 @@
def gplugin_load(plugin):
+ if not isinstance(plugin, GPlugin.Plugin): + raise Exception('plugin is not a GPlugin.Plugin') def gplugin_unload(plugin):
+ if not isinstance(plugin, GPlugin.Plugin): + raise Exception('plugin is not a GPlugin.Plugin') --- a/vala/tests/genie-plugins/basic.gs Thu Jul 15 00:44:27 2021 -0500
+++ b/vala/tests/genie-plugins/basic.gs Fri Jul 23 04:07:52 2021 -0500
@@ -39,11 +39,19 @@
return new BasicPluginInfo()
def gplugin_load(plugin : GPlugin.Plugin, out error : Error) : bool
+ if not(plugin isa GPlugin.Plugin) + error = new Error(Quark.from_string("gplugin"), 0, "plugin was not set") -def gplugin_unload(plugin : GPlugin.Plugin, out error : Error) : bool
+def gplugin_unload(plugin : GPlugin.Plugin, shutdown : bool, out error : Error) : bool + if not(plugin isa GPlugin.Plugin) + error = new Error(Quark.from_string("gplugin"), 0, "plugin was not set") --- a/vala/tests/plugins/basic.vala Thu Jul 15 00:44:27 2021 -0500
+++ b/vala/tests/plugins/basic.vala Fri Jul 23 04:07:52 2021 -0500
@@ -42,12 +42,22 @@
public bool gplugin_load(GPlugin.Plugin plugin, out Error error) {
+ if(!(plugin is GPlugin.Plugin)) { + error = new Error(Quark.from_string("gplugin"), 0, "plugin as not set"); -public bool gplugin_unload(GPlugin.Plugin plugin, out Error error) {
+public bool gplugin_unload(GPlugin.Plugin plugin, bool shutdown, out Error error) { + if(!(plugin is GPlugin.Plugin)) { + error = new Error(Quark.from_string("gplugin"), 0, "plugin as not set");