descriptionThe Common Foreign Function Interface
homepage URLhttp://common-lisp.net/project/cffi
repository URLhttps://github.com/cffi/cffi.git
ownerloliveira@common-lisp.net
last changeFri, 8 Mar 2024 13:54:20 +0000 (8 08:54 -0500)
last refreshSat, 27 Apr 2024 03:41:12 +0000 (27 05:41 +0200)
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-03-08 GleefreFix use of ALEXANDRIA:FORMAT-SYMBOLmaster
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
2022-10-06 Francisco VallarinoImport latest local-cpu and *target-archs* from cl...
2022-08-03 yuri@FreeBSDlibffi: load libffi.so on FreeBSD
2022-07-05 Stelian IonescuAdd Github bug report template
2022-06-15 Robert Smithallow libffi[32].so on unix platforms as fallback
2022-06-15 Tarn W. BurtonUse ASDF features
...
tags
3 years ago v0.24.1
3 years ago v0.24.0
3 years ago v0.23.0
3 years ago v0.22.1
3 years ago v0.22.0
4 years ago v0.21.0
4 years ago v0.20.1
5 years ago v0.20.0
6 years ago v0.19.0
7 years ago v0.18.0
8 years ago v0.17.1
8 years ago v0.17.0
8 years ago v0.16.1
8 years ago v0.16.0
9 years ago v0.15.0
9 years ago v0.14.0
...
heads
7 weeks ago master
8 years ago enable-travis-osx
10 years ago wip-better-load-library-error
10 years ago foreign-string
12 years ago bugfix-v0.10.7.1
13 years ago grovel++