This is rquired to enable the plugin to call g_module_make_resident() within its geany_load_module(). This must be done if the plugin registers new GTypes within that function.
plugin_module_make_resident() doesn't work because it's not an allowed API function to call from there. Simply allowing it doesn't suffice because internally the built-in plugin loader isn't fully set up yet: plugin->proxy_data isn't set to the GModule at this point (by design), and plugin_module_make_resident() requires that to be set.
This changes a public API, but it is unreleased so far, so not a problem (by definition). You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/719
-- Commit Summary --
* plugins: pass GModule * to geany_load_module()
-- File Changes --
M plugins/demoplugin.c (2) M plugins/demoproxy.c (2) M src/plugindata.h (3) M src/plugins.c (4)
-- Patch Links --
https://github.com/geany/geany/pull/719.patch https://github.com/geany/geany/pull/719.diff
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719
Makes some sense, although it would be technically possible to simply set `subplugin->priv->proxy_data = module` in `plugin_load_gmodule()` before calling `geany_load_module()`.
If we go the additional arg way like this (which seem mostly OK to me, see below), we need to document `plugin_module_make_resident()` doesn't work with new-style API in `load()`, and probably deprecate it. Advertizing both functions depending on the call site seems overly odd to me.
However, most plugins probably only need to make the module resident after `init()` -- as `load()` will often not create `GType`s; and if a lot of plugins end up being resident when loaded (and all installed plugins gets "loaded"), it might have a largish and unwanted memory impact.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-152765257
Am 31.10.2015 um 20:23 schrieb Colomban Wendling:
Makes some sense, although it would be technically possible to simply set |subplugin->priv->proxy_data = module| in |plugin_load_gmodule()| before calling |geany_load_module()|.
Yea, I considered this as well. But I didn't like it as much (seems more like a hack to me) and earlier versions of new_hooks already had the parameter.
If we go the additional arg way like this (which seem mostly OK to me, see below), we need to document |plugin_module_make_resident()| doesn't work with new-style API in |load()|, and probably deprecate it. Advertizing both functions depending on the call site seems overly odd to me.
It is documented, since the documentation for |geany_load_module() has a whitelist of API function that are allowed. I don't have a problem with deprecating ||plugin_module_make_resident() and I would rather not extend the whitelist without good reason. To me it's useless because it's a plain wrapper around a glib function. However, it's needed for legacy plugins which do not know about their GModule*.|
However, most plugins probably only need to make the module resident after |init()| -- as |load()| will often not create |GType|s; and if a lot of plugins end up being resident when loaded (and all installed plugins gets "loaded"), it might have a largish and unwanted memory impact.
Yes, it would be better to do it in init() for best efficiency but IMO we should allow for doing it in |geany_load_module() too, might be necessary and/or more convenient for some plugins.
The difference between is normally not a problem, because it only kicks in after opening the PM dialog (where |||geany_load_module() is called for every plugin)|. For normal sessions ||geany_load_module() is only called for active ones on startup. |
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-152766371
Yes, it would be better to do it in `init()` for best efficiency but IMO we should allow for doing it in `geany_load_module()` too, might be necessary and/or more convenient for some plugins.
Yes, i.e. for your examples using instance methods on a (GObject) class for init/cleanup etc.
The thing is, if we remove `plugin_module_make_resident()`, it becomes very hard for a plugin to call `g_module_make_resident()` from `init()`, as it would have to save the module pointer. This is not trivial without using a global variable, as plugins can only `set_data()` once, so this can't be used if the plugin wants to delay data allocation in `init()` (which most plugins should do). …and I feel odd about advertizing a different function to do the very same thing just depending on whether it's called from `load_module()` or not… other opinions? @codebrainz @elextr
FTR, as @codebrainz already mentioned somewhere, note that GModule has [`g_module_check_init()`](https://developer.gnome.org/glib/unstable/glib-Dynamic-Loading-of-Modules.ht...) hook, so a plugin can already call `g_module_make_resident()` before `geany_load_module()`, even if it might look less integrated.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-152850416
Ah right, I already forgot about g_module_check_init() again. Yea, that can be used instead. So I'm OK with dropping this PR entirely.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-152853219
We need a decision before 1.26 on this, and either merge something like this, or maybe advertize using `g_module_check_init()` for this purpose? @codebrainz @elextr (and @eht16 @frlan @ntrel) I'd really like your opinion on this as it affects public plugin API.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156169386
Well if @kugel- is ok with dropping it then don't stress on deciding it before 1.26.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156263746
I like the idea of hiding it from plugins entirely, if it's feasible, as seems to be indicated above. My second favourite is to let plugins deal with this themselves by using `g_module_make_resident()` from within `g_module_check_init()`, or using dynamic type registration or whatever.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156287843
I would agree to either drop this PR as @kugel suggested or postpone it to 1.27. Though my opinion is not really based on detailed technical insight but rather the fact that I'm replying very late and 1.26 is about to come in less than a day.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156719424
I would agree to either drop this PR as @kugel suggested or postpone it to 1.27.
We can't really postpone it, as it changes the new plugin API, and then would mean we break the new API from 1.26 in 1.27 :)
But apparently we agree to drop this. IMO we should document this, so what about something like this: ```diff diff --git a/src/pluginutils.c b/src/pluginutils.c index e48b4c1..4470313 100644 --- a/src/pluginutils.c +++ b/src/pluginutils.c @@ -92,6 +92,24 @@ void plugin_add_toolbar_item(GeanyPlugin *plugin, GtkToolItem *item) * * @param plugin Must be @ref geany_plugin. * + * @warning This cannot be used from inside `geany_load_module()` using the new plugin API. + * You generally should only call this from your plugin's `GeanyPluginFuncs::init()` + * function if possible to avoid possible extra resource usage when your plugin isn't + * actually activated. If you really need your module to be resident whenever it has been + * loaded (i.e. you create GTypes directly in your `geany_load_module()`), you need to use + * GLib's + * [g_module_check_init()](https://developer.gnome.org/glib/stable/glib-Dynamic-Loading-of-Modules.html...) + * hook and call + * [g_module_make_resident()](https://developer.gnome.org/glib/unstable/glib-Dynamic-Loading-of-Modules.ht...) + * from there: + * @code + * const gchar *g_module_check_init(GModule *module) + * { + * g_module_make_resident(module); + * return NULL; + * } + * @endcode + * * @since 0.16 */ GEANY_API_SYMBOL ``` Which gives: 
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156722007
I would just deprecate it and recommendg_module_check_init() universally
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156729907
I would just deprecate it and recommend g_module_check_init() universally
But then it's tricky to only make the module resident in `init()`. Well, tricky meaning storing the module pointer and using it later, like if it was a `geany_load_module()` parameter.
```c static GModule *module_self = NULL;
G_MODULE_EXPORT const gchar* g_module_check_init(GModule *module) { module_self = module; return NULL; }
static gboolean myplugin_init(GeanyPlugin *plugin, gpointer data) { g_module_make_resident(module_self);
return TRUE; }
G_MODULE_EXPORT void geany_load_moule(GeanyPlugin *plugin) { /* ... */ plugin->funcs->init = myplugin_init; /* ... */ GEANY_PLUGIN_REGISTER(plugin, 234); }
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156730440
@b4n looks OK to me, we can still do something different after release if we wanted to as well, by just updating those docs again.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#issuecomment-156746162
Closed #719 via #760.
--- Reply to this email directly or view it on GitHub: https://github.com/geany/geany/pull/719#event-464756408
github-comments@lists.geany.org