

Plugins in C - malloc47
http://eli.thegreenplace.net/2012/08/24/plugins-in-c/

======
jawngee
Why not export a struct with function pointers like everyone else? You should
take a look at how VST plugins are implemented.

You load the dlo, call a function passing in your own struct of application
functions and get back a struct of plugin functions. No weird naming
conventions needed, easily version-able. Tried and true.

~~~
delinka
I don't know whether this was the author's intent, but it's better to start
simpler (not in designs but in concepts - arguably, structs are simpler than
funky naming conventions) for the beginner and less experienced dev. The
struct method is a powerful one, yet not one grokked simply by the neophyte.
There probably needs to be a Part II.

~~~
tptacek
On the contrary, setting up a regime of specially-named functions is error-
prone and clunky, and structures with function pointers are a language idiom
in C, and, finally, if you're too new to the language to understand function
pointers, you can't use either technique, because both rely on function
pointers.

Ultimately, the real problem is that teaching bad designs to people because
they're new to the language is counterproductive.

------
yorhel
On a related note: Be wary of the dlclose() function, it may not necessarily
free any resources[1] and not every libc implements it correctly[2].

1\. <http://www.openwall.com/lists/musl/2012/08/20/1> 2\.
<http://www.openwall.com/lists/musl/2012/08/23/20>

~~~
tptacek
If you really need to demand-load and demand-unload lots and lots and lots of
plugins --- and that's the only design I can think of where dlclose matters,
but maybe there are others --- fork a plugin host process from the main
process, and kill it off when you're done with the plugins. You can use
anonymous shared memory to communicate between the two processes (since
there's a simple parent/child relationship).

------
mmariani
Here's the link to the intro article, all in Python3.

[http://eli.thegreenplace.net/2012/08/07/fundamental-
concepts...](http://eli.thegreenplace.net/2012/08/07/fundamental-concepts-of-
plugin-infrastructures/)

------
ps2000
"While C itself is a relatively rigid language"

------
fdelapena
I use libpeas

bye

