Language Bindings for Erlang

Vance Shipley vances@REDACTED
Sat May 27 00:01:12 CEST 2006


On Thu, May 25, 2006 at 09:39:10AM -0700, Jeff Crane wrote:
}
}  The C Linked Driver (also uses Erl_interface) is a
}  static driver which I *think* would be most
}  appropriate, but I would like some input, thx!


There are some very good reasons why this approach might not
work at all.  Some real life examples from my past include; 
needing to service events other than file handles, using a
library in a language that is not C, incompatibilities between
OTP and 3rd party libraries.  In those cases I used ports.

I have a dynamic driver which pulls in shared libraries from
a commercial vendor.  It worked until a recent version where it
seems to have a dependency on libstdc++.  I've had to modify the 
Erlang/OTP build to make it work again.  This would probably
all be considered not-my-job and if I had kept to a seperate
process (i.e. a C Node) it wouldn't have consumed any of my
time.

On the other hand a linked in driver is a wonderful thing when
it works.  I have message passing applications which use a
linked in driver to move binaries between embedded processors 
and Erlang processes.  The driver receives a message from the
board and it sends an erlang term to the port owner which
includes the received message as a binary.  For large binaries
this is a zero copy operation.  I use GNU {automake|autoconf|libtool}
to make the Erlang binary handling portable, autoconf tests
drive the generation of erlang header files from templates.

E.g.:
Autoconf tests create the variables SIZEOF_foo and SIZEOF_bar.
Autoconf then creates messages.hrl from template messages.hrl.in:

-define(FOO, @SIZEOF_foo@/integer-unsigned-native-unit:8).
-define(BAR, @SIZEOF_bar@/integer-unsigned-native-unit:8).

-record(message1, {foo=0, bar=0}).


Then I have a codec module which maps from records to binaries
and vice versa:

-module(messages).
-export([message1/1]).
-include("messages.hrl").


message1(<<Foo:?FOO, Bar:?BAR>>) -> #message{foo=Foo, bar=Bar};
message1(#message{foo=Foo, bar=Bar}) -> <<Foo:?FOO, Bar:?BAR>>.


I've ported automatically from SPARC to Intel to Linux painlessly.


	-Vance





More information about the erlang-questions mailing list