descriptionThe Common Foreign Function Interface
homepage URLhttp://common-lisp.net/project/cffi
repository URLhttps://github.com/cffi/cffi.git
ownerloliveira@common-lisp.net
last changeSun, 11 Aug 2024 15:16:01 +0000 (11 16:16 +0100)
last refreshThu, 21 Nov 2024 07:41:19 +0000 (21 08:41 +0100)
content tags
add:
README.md

Build Status

What

CFFI, the Common Foreign Function Interface, purports to be a portable FFI for Common Lisp. It abstracts away the differences between the API of the native FFI's of the various Common Lisp implementations.

How

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 more comfortable, declarative interface for defining foreign functions, structures, typedefs, enumerated types, etc. It is implemented in portable ANSI CL making use of the low-level operators exported by CFFI-SYS.

The CFFI-LIBFFI subsystem loads support for passing structs by value. It requires libffi for that.

Please consult the manual for further details, including installation instructions.

Where

Please visit Github for bug reports, feature suggestions, the latest version, and to send your contributions. CFFI also has a mailing list, and a project page at cffi.common-lisp.dev.

Notes

CFFI/C2FFI

CFFI/C2FFI is an ASDF-integrated mechanism to automatically generate a complete CFFI binding from C header files.

Its input is one .h file (with possible #includes of course), and its final output is a lisp file with the relevant CFFI binding forms.

It requires a CLI tool called c2ffi, but only for the developers of the C binding libraries, not their users. c2ffi is written in C++, and it uses Clang as a library to parse the C code, and emit the result as JSON. To skip this step, these host-specific JSON files can be checked into the repos of the binding libraries. This breaks the dependence on a working c2ffi binary and the C header files, which can be a hurdle.

These JSON files are then used to automatically generate a CL file with the corresponding CFFI forms. The generated bindings mirror the C namespace into an empty CL package as closely as possible. This means that the upper/lower case of the C names are retained. It helps with reading the original docs and with rewriting C examples into lisp. #defines are also mirrored as CL defconstants.

Binding library developers are advised to introduce another package on top of this raw layer to add more lispy constructs where appropriate (e.g. with- macros that manage resources, etc).

Until CFFI/C2FFI is properly documented, you may check out these projects as examples: hu.dwim.zlib, hu.dwim.sdl, hu.dwim.bluez, and hu.dwim.mosquitto.

shortlog
2024-08-11 Luís Oliveiralibffi: clean up the ABI enummaster
2024-07-16 Tarn W. BurtonAdd support for ECL long double
2024-07-13 Bart Bottamake sure structs are big enough to hold all slots...
2024-05-16 Paul A. PatienceAdd WITH-POINTER-TO-VECTOR-DATA for Clasp (#385)
2024-05-16 Paul A. PatienceRemove iteration clause from LOOP body code
2024-03-08 GleefreFix use of ALEXANDRIA:FORMAT-SYMBOL
2024-01-03 Bart Bottatry to translate constant enum keywords at compile...
2023-10-11 Stuart DiltsFix / Improve with-foreign-pointer-as-string in manual
2023-09-10 Douglas KatzmanAvoid warning from C++ compiler
2023-06-10 GleefreWorkaround for defcfun.undefined test on CMUCL (#361)
2023-04-12 Attila Lendvaihousekeeping: c2ffi README, and clarify a comment
2022-11-29 Stas Boukarevcffi-sbcl: workaround Darwin issues in call-within...
2022-11-08 Stelian IonescuRefactor core package definitions
2022-11-08 Samuel HunterAdd compiler macro FOREIGN-TYPE-SIZE
2022-11-07 Stelian IonescuAdd compiler macro utils CONSTANT-FORM-P and CONSTANT...
2022-10-31 LisperWeaselAdd :NETBSD to LIBFFI library definition
...
tags
3 years ago v0.24.1
3 years ago v0.24.0
4 years ago v0.23.0
4 years ago v0.22.1
4 years ago v0.22.0
4 years ago v0.21.0
5 years ago v0.20.1
6 years ago v0.20.0
7 years ago v0.19.0
8 years ago v0.18.0
8 years ago v0.17.1
8 years ago v0.17.0
9 years ago v0.16.1
9 years ago v0.16.0
9 years ago v0.15.0
10 years ago v0.14.0
...
heads
3 months ago master
9 years ago enable-travis-osx
10 years ago wip-better-load-library-error
11 years ago foreign-string
12 years ago bugfix-v0.10.7.1
13 years ago grovel++