[cffi-devel] Re: CFFI defcallback closures?

Nikodemus Siivola nikodemus at random-state.net
Mon Sep 25 13:20:28 UTC 2006


"Luís Oliveira" <loliveira at common-lisp.net> writes:

> On 9/25/06, Lars Brinkhoff <lars at nocrew.org> wrote:
>> Can CFFI defcallbacks be closures, e.g.
>>
>>   (let ((x 42))
>>     (defcallback foo :int ((y :int))
>>       (+ x y)))
>
> Unfortunately, last time I checked, not all Lisps support non
> top-level DEFCALLBACKs. See:
> <http://common-lisp.net/project/cffi/manual/html_node/defcallback.html>

...and in even those that do (like SBCL), you should be aware that
whereas a call like
  (some-foreign-function callback) 
is likely to be decently efficient, each call like
  (let ((x 0)) (some-foreign-function (alien-lambda () (frob x))))
is likely to be a _lot_ more expensive, as each call needs to generate
a new callback.

Cheers,

  -- Nikodemus              Schemer: "Buddha is small, clean, and serious."
                   Lispnik: "Buddha is big, has hairy armpits, and laughs."




More information about the cffi-devel mailing list