This is the home page of the Foreign Function Interface (FFI) extension for Erlang/OTP: a method for calling native C functions from Erlang, making it easier to create library bindings and interfaces to C code.
All the details are described in a draft EEP (Erlang Enhancement Proposal) (available formats: HTML and TXT source) (last update: Thu, 15 Nov 2007 17:55:04 +0100).
The proposal is being discussed as EEP-0007. (Note: the version hosted on erlang.org may be slightly out of date)
The draft EEP has been implemented by patching the Erlang/OTP R11B-5 sources. Everything has been tested on GNU/Linux (i386, x86-64, powerpc, powerpc64).
You can download the changes as a single, big patch (see the diffstat) (last update: Tue, 29 Jul 2008 14:48:15 +0200).
Otherwise, you can download the changes as 14 small patches (for easier readability).
First patch series (last update: Wed, 12 Sep 2007 14:49:59 +0200):
ffi:call/3
BIF.
erl_ddll:load_library/3
BIF, without
preloading support.
erl_ddll:load_library/3
BIF.
ffi:call/2
BIF.
Second patch series, based on the Erlang-questions mailing list feedback (last update: Wed, 03 Oct 2007 10:34:04 +0200):
ffi:call/*
becomes ffi:raw_call/*
,
erl_ddll:load_library/2
,
erlang:open_port/1
, void
functions
return 'void'
).
ErlDrvBinary
'es). Also adds some new
C types (cstring
, nonnull
,
off_t
, pid_t
).
ErlIOVec
's).
erl_ddll:info/2
to return information
about preloaded functions.
ffi_hardcodes.hrl
, and type/range checks for
type-tagged values.
Third patch series, mostly based on developers feedback (last update: Tue, 29 Jul 2008 14:48:15 +0200):
kernel
to
the ffi
library, and makes the build process
warn when the FFI support could not be compiled. Also
performs some minor beautification
in erl_bif_ffi.c
(removes a compiler warning).
The small patches are incremental (i.e. they should be applied in the given order) and self-contained (every patch leaves a working Erlang/OTP source tree, with the related enhancements).
You will need all the standard dependencies for compiling the Erlang/OTP sources, plus GNU Autoconf and libffi (the GCC FFI library). If you are a Debian/Ubuntu user, you can install them easily:
apt-get install autoconf libffi4-dev
To patch and build Erlang/OTP with the FFI extension:
cd
in the main directory of the source tree;
patch -p1 < patch-filename.diff
./otp_build autoconf
README
file with instructions.
(last update: Mon, 03 Dec 2007
11:08:16 +0100)
The FFI extension proposal has been sent to the Erlang-questions mailing list. You can join the discussion there, or write directly to me (see the email address at the end of the page).
A first summary of the discussion so far is available here.
Copyright (C) 2007 by
CRS4 - Center for Advanced Studies, Research and Development in Sardinia
Author: Alceste Scalas <alceste (at) crs4 (dot) it>