[cffi-devel] Re: CFFI defcallback closures?

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Thu Oct 5 13:41:31 UTC 2006


Nikodemus Siivola wrote:
>I would not like callbacks to ever be released by default, nor from
>the C-side.

Of course, I haven't looked at every FFI code every Lispnik wrote for
CLISP, but I believe the following is not too much invented:
(defun some-often-called-function ...
  (flet ((ignore-it (&rest args) (declare (ignore args)) nil)))
    (with-C-signal-handler (SIGINT/SIGxyz #'ignore-it)
      some-code ...)))
What I mean is
0. Assume with-signal handler installs the Lisp function as signal
handler
1. code involving lambda-callbacks may be called every so often
2. every such call creates a trampoline.
3. that application leaks memory like a sieve.

In summary, the language & library designers must not assume anything
about the pattern of use of a given construct, except for the worst
case.

Of course, the example is poorly chosen. The semantics of with-* are
that we should be able to invalidate the trampoline upon exit.

>I think the best we can do for callbacks
>(anonymous or not) is invalidate them: switch the C->Lisp tramp to
>point to an error-signalling Lisp function,

Your suggestion of changing the trampoline to point to an error
signaling function is nice for debugging (like it's nice to catch
duplicate calls to free()).  It's not so nice for production use, as
memory consumption would continuously grow...

>after which the original callback trampoline can be freed
I don't understand. Either the trampoline is free'd or it's not and can
point to error signaling code instead of the original function.

Regards,
	Jorg Hohle.



More information about the cffi-devel mailing list