Introduction

CFFI, the Common Foreign Function Interface, purports to be a portable foreign function interface for Common Lisp. The CFFI library is composed of a Lisp-implementation-specific backend in the CFFI-SYS package, and a portable frontend in the CFFI package.

The CFFI-SYS backend package defines a low-level interface to the native FFI support in the Lisp implementation. It offers operators for allocating and dereferencing foreign memory, calling foreign functions, and loading shared libraries. The CFFI frontend provides a declarative interface for defining foreign functions, structures, typedefs, enumerated types. It is implemented in portable ANSI CL making use of the low-level operators exported by CFFI-SYS.

A UFFI compatibility layer is also being developed.

Implementation Status

CFFI is under heavy development, and not as mature as UFFI in terms of API stability. See chapter 2 of the CFFI User Manual: "Implementation Support."

The status of CFFI support for various Lisp implementations is summarized in the following table:

Lisp Implementation CFFI Status Comments
OpenMCL Working
SBCL Working some platforms don't support callbacks
CMU CL Working
CLISP Working requires clisp >=2.35
LispWorks Working
Allegro CL Working
Corman CL Partially Supported missing FOREIGN-FUNCALL (DEFCFUN is supported), a few bugs left (7 out of 71 tests fail). note: you will need to follow these instructions to use ASDF with Corman Lisp.
Digitool MCL Unknown probably similar to OpenMCL
Scieneer CL Working
ECL Working Requires the CVS version of ECL
GCL Broken port incomplete