cvs commit: hugs98/src ffi.c static.c connect.h
Alastair Reid
alastair@reid-consulting-uk.ltd.uk
Fri, 03 Jan 2003 19:25:51 +0000
> Enable FFI modules to be used as statically linked plugins.
>
> If the generated C code for a module is compiled with
> -DSTATIC_LINKAGE, the initModule() function is renamed to
> something based on the module name, e.g. initFMAlloc() for
> Foreign.Marshal.Alloc (abbreviated for limited linkers).
IIRC, when I wrote the static linkage code, using this required you to
either modify plugins.c or compile plugins.c with
-DPLUGINS='{"Foreign.Marshal.Alloc", initFMAlloc}'
These work but could obviously get a bit tedious/ hard to maintain.
If you haven't already done so, it would be very, very cool to make
use of the ELF / DLL initializer feature.
My thought is that you could replace the 'pluginList' array in
plugins.c with a linked list (changing the 'havePlugin' code as
required) and that initializers would just add themselves to the
linked list. (Obviously, you'd want to retain a non-ELF/DLL option
as well.)
It's tempting to make the initFMAlloc function an ELF initializer
directly but that won't work because Hugs isn't initialized and
because the code that implements foreign export is supposed to be able
to perform a lookup when the module is initialized. (I say 'supposed'
because the frontend parts of foreign export still don't exist.)
--
Alastair