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

Anton Vodonosov avodonosov at yandex.ru
Wed Nov 7 00:32:37 UTC 2012



31.10.2012, 03:34, "Luís Oliveira" <luismbo at gmail.com>:
> 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.

I recently found this article: http://random-state.net/log/3311080770.html
It means, some time ago SBCL was unable to define foreign functions
until the foreign library is loaded.

Despite it is fixed in SBCL years ago, maybe other lisps can't 
define foreign functions/variables until the library is not loaded?
Do you remember details about other lisps? Are they all
now capable to compile and load lisp code with foreign
definitions without loading the foreign library?

>>  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?

Thanks for the suggestion, I am not sure, need to think about it.

Best regards,
- Anton




More information about the cffi-devel mailing list