Branch: refs/heads/master Author: Thomas Martitz kugel@rockbox.org Committer: Thomas Martitz kugel@rockbox.org Date: Sun, 23 Aug 2015 18:01:41 UTC Commit: 43c58e0fdde9e79fb902925a5854cde81db8db20 https://github.com/geany/geany/commit/43c58e0fdde9e79fb902925a5854cde81db8db...
Log Message: ----------- plugins: change return codes of geany_load_module() and GeanyPluginFuncs::init
- The return value from geany_load_module is removed (void). It was ignored anyway and we have to check separately whether the plugin loaded OK or not anyway. If the plugin specific code fails it should simply not call geany_plugin_register() (which it should only call iff all other conditions are good).
- GeanyPluginFuncs::init() now returns a bool to allow failing initialization. Some plugins might want to defer work to their init() (i.e. only do it when the plugin was activated by the user), and some of that work can possibly fail (e.g. GtkBuilder fails to load .xml).
Note that the GUI integration of the latter is less than ideal but this kind of GUI/policy work is out of scope for this patch set. Therefore a plugin failing to init is simply removed from the PM dialog as if it became incompatible. However, as the code that generates the list does not call init they will show up again if the PM dialog is re-opened.
Modified Paths: -------------- plugins/demoplugin.c src/plugindata.h src/plugins.c
Modified: plugins/demoplugin.c 8 lines changed, 5 insertions(+), 3 deletions(-) =================================================================== @@ -119,7 +119,7 @@ item_activate(GtkMenuItem *menuitem, gpointer gdata)
/* Called by Geany to initialize the plugin */ -static void demo_init(GeanyPlugin *plugin, gpointer data) +static gboolean demo_init(GeanyPlugin *plugin, gpointer data) { GtkWidget *demo_item; GeanyData *geany_data = plugin->geany_data; @@ -138,6 +138,8 @@ static void demo_init(GeanyPlugin *plugin, gpointer data) welcome_text = g_strdup(_("Hello World!"));
demo_callbacks[0].user_data = geany_data; + + return TRUE; }
@@ -202,7 +204,7 @@ static void demo_cleanup(GeanyPlugin *plugin, gpointer data) g_free(welcome_text); }
-gboolean geany_load_module(GeanyPlugin *plugin) +void geany_load_module(GeanyPlugin *plugin) { /* main_locale_init() must be called for your package before any localization can be done */ main_locale_init(LOCALEDIR, GETTEXT_PACKAGE); @@ -217,5 +219,5 @@ gboolean geany_load_module(GeanyPlugin *plugin) plugin->funcs->cleanup = demo_cleanup; plugin->funcs->callbacks = demo_callbacks;
- return GEANY_PLUGIN_REGISTER(plugin, 225); + GEANY_PLUGIN_REGISTER(plugin, 225); }
Modified: src/plugindata.h 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -275,7 +275,7 @@ void plugin_cleanup(void); * * @since 1.26 (API 225) */ -gboolean geany_load_module(GeanyPlugin *plugin); +void geany_load_module(GeanyPlugin *plugin);
#endif
@@ -295,7 +295,7 @@ struct GeanyPluginFuncs /** Array of plugin-provided signal handlers @see PluginCallback */ PluginCallback *callbacks; /** Called to initialize the plugin, when the user activates it (must not be @c NULL) */ - void (*init) (GeanyPlugin *plugin, gpointer pdata); + gboolean (*init) (GeanyPlugin *plugin, gpointer pdata); /** plugins configure dialog, optional (can be @c NULL) */ GtkWidget* (*configure) (GeanyPlugin *plugin, GtkDialog *dialog, gpointer pdata); /** Called when the plugin should show some help, optional (can be @c NULL) */
Modified: src/plugins.c 24 lines changed, 18 insertions(+), 6 deletions(-) =================================================================== @@ -330,10 +330,11 @@ struct LegacyRealFuncs };
/* Wrappers to support legacy plugins are below */ -static void legacy_init(GeanyPlugin *plugin, gpointer pdata) +static gboolean legacy_init(GeanyPlugin *plugin, gpointer pdata) { struct LegacyRealFuncs *h = pdata; h->init(plugin->geany_data); + return TRUE; }
static void legacy_cleanup(GeanyPlugin *plugin, gpointer pdata) @@ -427,9 +428,10 @@ static void register_legacy_plugin(Plugin *plugin, GModule *module) }
-static void +static gboolean plugin_load(Plugin *plugin) { + gboolean init_ok = TRUE; /* Start the plugin. Legacy plugins require additional cruft. */ if (PLUGIN_IS_LEGACY(plugin)) { @@ -449,6 +451,7 @@ plugin_load(Plugin *plugin) *plugin_fields = &plugin->fields; read_key_group(plugin);
+ /* Legacy plugin_init() cannot fail. */ plugin->cbs.init(&plugin->public, plugin->cb_data);
/* now read any plugin-owned data that might have been set in plugin_init() */ @@ -459,9 +462,12 @@ plugin_load(Plugin *plugin) } else { - plugin->cbs.init(&plugin->public, plugin->cb_data); + init_ok = plugin->cbs.init(&plugin->public, plugin->cb_data); }
+ if (! init_ok) + return FALSE; + /* new-style plugins set their callbacks in geany_load_module() */ if (plugin->cbs.callbacks) add_callbacks(plugin, plugin->cbs.callbacks); @@ -472,6 +478,7 @@ plugin_load(Plugin *plugin) active_plugin_list = g_list_insert_sorted(active_plugin_list, plugin, cmp_plugin_names);
geany_debug("Loaded: %s (%s)", plugin->filename, plugin->info.name); + return TRUE; }
@@ -485,7 +492,7 @@ plugin_new(const gchar *fname, gboolean load_plugin, gboolean add_to_list) { Plugin *plugin; GModule *module; - gboolean (*p_geany_load_module)(GeanyPlugin *); + void (*p_geany_load_module)(GeanyPlugin *);
g_return_val_if_fail(fname, NULL); g_return_val_if_fail(g_module_supported(), NULL); @@ -567,8 +574,13 @@ plugin_new(const gchar *fname, gboolean load_plugin, gboolean add_to_list) goto err; }
- if (load_plugin) - plugin_load(plugin); + if (load_plugin && !plugin_load(plugin)) + { + /* Handle failing init same as failing to load for now. In future we + * could present a informational UI or something */ + geany_debug("Plugin failed to initialize "%s" - ignoring plugin!", fname); + goto err; + }
if (add_to_list) plugin_list = g_list_prepend(plugin_list, plugin);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).