Allowing GC in Allegro CL SMP during foreign function calls

Luís Oliveira loliveira at common-lisp.net
Wed Jul 31 08:55:13 UTC 2013


On Tue, Jul 30, 2013 at 4:33 PM, Felix Filozov <ffilozov at gmail.com> wrote:
> When defining a foreign function using def-foreign-call, there's an option
> one could set called :allow-gc. Setting it to :always, allows the garbage
> collector to run while the foreign function is executing.
>
> At the moment CFFI uses the default value for :allow-gc, which is :never.
> This prevents GC from running when a foreign function is executing.
>
> Moreover, once GC blocks, other processes can't make progress. In my case, I
> need GC to run during foreign function execution.

I understand the advantages of overriding ACL's default. What are the drawbacks?

Also, what do other Lisps do? We probably want to be as consistent as
possible across the platforms we support.


> What do you think about extending the defcfun and foreign-call interfaces to
> allow for native options to be passed? name-and-options could be extended to
> accept a new argument, :native-args, for example. Then you'd be able to use
> defcfun as follows:
>
> (defcfun ("strlen" :native-args (:allow-gc :always)) :int
>   (str :string))
>
> Another option is to create a global variable that holds native arguments,
> and def-foreign-call would read this directly.

I have nothing against this sort of thing. An alternative for this
particular case, though, would be to have an :allow-gc option to
defcfun and possibly have a range values like t, nil and :maybe where
the first two would signal an error if the underlying Lisp doesn't
support that functionality.

Cheers,

-- 
Luís Oliveira
http://kerno.org/~luis/



More information about the cffi-devel mailing list