[erlang-questions] C Ports - how to deal wth C function pointers ?

Oscar Hellström oscar@REDACTED
Mon Apr 23 10:48:27 CEST 2007

Roberto Saccon wrote:
> I am experimenting with port drivers (building a port driver for cairo 
> graphics library). Everything goes well as long as I pass simple 
> arguments to call my c library.
> But I need to pass a function pointer to the library. And here comes my 
> problem. The c library now calls that function. How can I pass its 
> result back to Erlang ? Is there a way the c-side can initiate the 
> communication ?

You can send messages back to the process owning the port, using 
driver_output, driver_output_term and a few more 
Be aware though that this must be done from the main thread (the same as 
the emulator runs in) and not by any threads started by using either 
driver_async or pthreads etc. This makes it a bit troublesome working 
with C-code that can do blocking calls. If you need to store pointers, 
which the Erlang side should not see, you can you create space for this 
in your driver data structure.

There has also been some discussion earlier on this subject of using 
more can be found by a quick search through the archives.

> regards
> -- 
> Roberto Saccon
> ------------------------------------------------------------------------
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

Best Regards
Oscar Hellström, oscar@REDACTED
Erlang Training and Consulting

More information about the erlang-questions mailing list