[cffi-devel] loading foreign libraries in a top-level form

Luís Oliveira luismbo at gmail.com
Tue Oct 30 23:34:00 UTC 2012


On Mon, Oct 22, 2012 at 4:28 AM, Anton Vodonosov <avodonosov at yandex.ru> wrote:
> I think better idiom would be to not use top-lovel cffi:use-foreign-library,
> but instead have CL libraries to provide initialization routine which
> loads the foreign libraries.

That might work, but it's definitely not idiomatic amongst Lisp
libraries (using CFFI or other FFIs). I guess, it's much more
convenient to be able to just load some ASDF system and be start using
the API right away.


> A supporting argument against top-level cffi:use-foreign-library
> is that as far as I know when we save an image of lisp, many lisps
> will not reload the foreign libraries when we load the image next time.
> I.e. the lisp image does not contain information about loaded libraries.
> Here, even with the approach with top-level cffi:use-foreign-library
> the CL library anyway needs to provide a routine to load the
> foreign library. Therefore, we could avoid the top-level
> cffi:use-foreign-library at all.

As a solution for that, CFFI keeps track of what foreign libraries
have been loaded. (See CFFI:LIST-FOREIGN-LIBRARIES and
CFFI:RELOAD-FOREIGN-LIBRARIES.) It would be nice if CFFI helped with
setting up proper hooks to load the foreign libraries when an image is
loaded.

Regarding your use case, if CFFI added an IGNORE restart for
LOAD-FOREIGN-LIBRARY-ERROR conditions, would that help?

-- 
Luís Oliveira
http://r42.eu/~luis/




More information about the cffi-devel mailing list