Luís Oliveira wrote:
>I was just testing CFFI/CLISP by loading the testsuite, dumping an  
>image, loading it and running the tests. CLISP crashes. There are two  
>problems:
>
>- The foreign library (in this case libtest.so) is not being  
>reloaded. [...]I recall CLISP's ffi:def-call-out taking care of this but
Hmm, did you try an absolute path? I suspect the library was not found.
I'd naively have expected this to work in the context of cffi as well as with 
direct uses of the FFI.


>- The callbacks become NULL pointers, thus all callback.* tests fail.  
>Any suggestions for fixing that? Randomly placing load-time-value  
>forms in %defcallback didn't seem to work. :-)
[replying without having thought much about this issue].
CLISP's image is not like an Emacs dump of memory. It doesn't preserve 
addresses.  It doesn't preserve malloc()'ed stuff, which I believe callbacks 
are (or parts thereof).
Actually, I would *not* expect any implementation to be able to reproduce the 
exact same address of anything when started from an image. CMUCL seems an 
exception, where there are additional constraints (like on Solaris, getting the 
linker to load a shared object file at a known location).

Similarly, any foreign library that stored a callback-pointer *must* *not* 
expect such a pointer to be valid when restarting. That library may itself be 
at a different address when reloaded, how could the callback not change?

IMHO, it might work in a scenario on Linux with naive tests where you exit and 
immediately restart, but what if you upgrade your system in between etc.?

Instead, my mental model is that callbacks must be re-established dynamically 
when an application starts.
-- which makes me think that the code for free'ing an old callback upon 
redefinition in cffi should add a ext:validp test before free'ing. I just added 
a check in my branch.

That's what I meant in my mail "unnamed callback" from 2005-12-19, where I 
wrote:
>(defun my-application
>  (let (x y)
>    ...code...
>    (register-callback 'close-window

I'd be happy to discuss this further.  Restarting from one's images is being 
neglected in the Lisp community these days IMHO.  Smalltalk implementations 
seems to behave better.

Regards,
        Jörg Höhle.
_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to