FFI Callbacks

Andreas Raab andreas.raab at gmx.de
Fri Sep 1 01:57:37 UTC 2006


Ron Teitelbaum wrote:
> A quick question, if callbacks are supported by the VM, and a plug-in can be
> written to handle callbacks couldn't someone (notice I didn't say "I" or
> "WE" hoping maybe one of the VM gurus would consider it) combine those
> features to write a generalized callback framework that would be available
> to the image?  For example it would define the function name return value
> and parameters, just like FFI but maybe be called <apicallback: ...>.  Then
> that callback could be invoked within a semaphore on a separate thread.

Yes. That is basically what I meant when I said "you need to pop the 
arguments from the C stack". What you have to do goes somewhat along the 
lines of the following:
1. Set up a pool of callback functions that are varargs based. This 
avoids the need to generate callbacks stubs (which may be preferrable on 
some platforms but it doesn't matter). These functions need to "put 
away" the stack pointer for the image to use, signal an FFI semaphore 
and callback into the interpreter.
2. When the callback is picked up in the image, the image needs to call 
a set of support functions to take the arguments correctly from the 
stack. This would be based on some ffi spec.
3. Once all the arguments are picked up, you run your callback code.
4. To return, you need to call another set of support functions for 
storing the return value and return from the callback.

See, it's only four steps. How hard could it possibly be? ;-)

Cheers,
   - Andreas



More information about the Squeak-dev mailing list