[Geany-Devel] New plugin loader mechanisms

Thomas Martitz kugel at xxxxx
Mon Mar 30 21:07:59 UTC 2015


Am 30.03.2015 um 14:57 schrieb Colomban Wendling:
>
> If `pdata` is provided in geany_plugin_register(), how does it get
> released?  If it has to be a pointer to static data it's a bit limiting,
> and forces use of (static) globals, which is one thing that this new API
> tries to avoid, doesn't it?  We could also ask for a GDestroyNotify, but
> that's an additional arg we might not need.
>
> And also, providing the pdata in geany_load_module() might mean memory
> allocation, allocation that might never be used if the plugin isn't
> activated.
>
> OTOH, if `pdata` is a member of GeanyPlugin, it can be allocated in
> init() and freed in cleanup() without having to tell Geany how it has to
> free it.
>

I see what you mean. Indeed, this could be a problem.

I wanted the pdata parameter such that it is friendly to language 
bindings. This doesn't work if the user_data is hidden down in some 
other structs passed as parameter. For example, I wanted to make it 
possible to use vala member functions classes directly as plugin hooks. 
And this works, however there is indeed a leak. I have a prototype, see 
below.

Considering this use case I would rather take the GDestroyNotify than 
hiding down pdata in another param. Passing it to 
geany_plugin_register() also allows for using a member function for the 
init() hook already.

What do you think?


Best regards

Appendix: The prototype is like this:

using Geany;

class Tester
{
     public void init(Plugin p) { }

     public void help(Plugin p) { /* shows a dialog */ }

     public void cleanup(Plugin p) { }
}

private PluginHooks hooks;
public bool geany_load_module(Plugin p, GLib.Module mod, int geany_api_ver)
{
     hooks.init = Tester.init;
     hooks.help = Tester.help;
     hooks.cleanup = Tester.cleanup;
     p.register(Geany.API_VERSION, 224, Geany.ABI_VERSION,
         ref hooks, new Tester() /* LEAK */);

     mod.make_resident();

     /* ... */
     return true;
}



More information about the Devel mailing list