I've always disliked the open-all-previously-known-libraries-at-startup that Bruno put into the FFI back when it was first created.
As I said in an old message, a bug was introduced when the update ilbrary pointer code was made to cause GC. It would not GC on AmigaOS in the old days. IIRC, it's the pathname encoding macros that may cause GC.
o get rid of the "try revalidation upon GC code", i.e. GC does nothing.
o Implement revalidation in a unique place, explicitly: foreign-call-out. That is, provide late-binding functionality.
o simplify GC -- currently, every invalid pointer causes walking through the list of open libraries, which is superfluous most of the time.
o User may use FOREIGN-LIBRARY explicitly to force revalidation of a library pointer (independently on function invocation) and thus control opening.
= user should observe no different behaviour by this change, at least, nothing annoying.
? I haven't thought yet about call-in behaviour
o Only few pointers are revalidatable, i.e. those of foreign libraries. Malloc'ed and other unknown memory objects cannot be revalidated (or at least, it shouldn't be CLISP built-in functionality), so the current behaviour is user unfriendly and a waste of resources.
It's user-unfriendly because clisp has never provided a good answer to the question "what if the library cannot be opened on startup"?
o silently failing is as stupid as
o throwing an error during startup -- why bother the user with some obscure library error when the user just want to start a new Lisp session.
That's my $0.01. I have no time to implement it in the next future.
I also believe that the current "early open" behaviour caused the problems with clisp-2.35-win32 -Kfull, where most users do not have postgres and/or the other modules which got in that binary. But I don't know for sure and it may as well have been caused by the static module's init functions.
What I mean is that one should be able to release an image, using only dynamic libraries and not get an error upon startup about things for which there's no intent of use.
>Von: Sam Steingold [mailto:sds@...]
>Gesendet: Mittwoch, 21. September 2005 21:08
>Cc: Hohle, Jorg-Cyril; Bruno Haible
>Betreff: clisp ffi gc bug: Fpointer_value maygc
>Fpointer_value may call validate_fpointer which calls update_library
>which calls open_library which maygc.
>Thus Fpointer_value and all its callers (e.g., Faddress_value) maygc.
>Fpointer_value is called 3 times.
>Faddress_value is called ~25 times.
>Note that they are MACROS, so they can only be called on STACK_*
>what can be done?
>update_library is useful only once per session, so why not call it
>update_library just once at startup?
>this will cost non-FFI users just a little bit.
>another alternative is fixing every use of Faddress_value...