[Ecls-list] Embedding/ffi question
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at googlemail.com
Fri Jun 25 08:14:39 UTC 2010
On Fri, Jun 25, 2010 at 7:31 AM, Neil Baylis <neil.baylis at gmail.com> wrote:
> I'm making a program that receives messages from the iPhone App touchOSC.
> These messages are packaged into UPD datagrams.[....]
> I want to make a c library that's callable from lisp. I was thinking of
> [...]
> void init_osc(int port, void(*callback)(char* data));[...]
>
When liblo receives an OSC message, it will call this callback, passing it
> an ordinary c string representation of the message.
>
Let's see, you want a function pointer that has that precise signature and
which executes some lisp code. This is doable and the FFI (and also CFFI)
provide methods. The problem is your precise requirement
This callback will be made in the context of a thread spawned by liblo
> during the init_osc() call.
>
This thread will not be managed by ECL, which means that the garbage
collector will have no information about its stack boundaries and will not
be able to function properly.
There exist functions in ECL for registering and de-registering a thread
with ECL / the garbage collector. However, this may be tricky and slow, and
those functions are not available in the lisp environment -- they only work
from C and would force you to first write the C wrapper, calling
extern ECL_API bool ecl_import_current_thread(cl_object process_name,
cl_object process_binding);
extern ECL_API void ecl_release_current_thread(void);
before and after the C code that actually invokes the lisp code.
A simpler solution would be to make your callback a trivial C wrapper that
communicates with a lisp thread, passing a message, something that does not
cons.
Alternatively we could extend ECL to execute callbacks in fresh new threads
-- they would be automatically registered with ECL because of our existing
interceptions of pthread_create and similar functions --. This should not be
difficult to do, but requires some knowledge of how ECL works and extending
the existing code for callbacks.
Juanjo
--
Instituto de FĂsica Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100625/bacd0812/attachment.html>
More information about the ecl-devel
mailing list