1
0
Fork
You've already forked cffi
0
  • Common Lisp 94.3%
  • C 4.9%
  • Makefile 0.7%
Find a file
2026年03月26日 17:59:34 +03:00
.github/ISSUE_TEMPLATE Add Github bug report template 2022年07月05日 19:53:28 -04:00
doc Add support for ECL long double 2024年07月16日 22:38:15 +01:00
examples Improve c-toolchain 2017年01月29日 10:16:41 +01:00
grovel grovel: don't treat pkg-config stderr as compilation flags 2025年01月04日 09:25:48 +00:00
libffi libffi: clean up the ABI enum 2024年08月11日 16:16:01 +01:00
scripts scripts/release: better new-version-number-candidates implementation 2013年08月12日 22:29:52 +01:00
src leak-safe checks 2026年03月26日 17:59:34 +03:00
tests Add support for ECL long double 2024年07月16日 22:38:15 +01:00
toolchain Solaris ld doesn't do --export-dynamic 2020年07月08日 12:38:29 +01:00
uffi-compat uffi-compat: convert UFFI types at macro-expansion time if possible 2020年09月20日 22:54:38 +01:00
.gitignore gitignore doc/*.tps 2016年10月15日 09:36:35 +01:00
.travis.yml Switch to HTTPS for fetching dependencies from Git 2022年03月17日 12:10:22 -04:00
cffi-examples.asd New example: mapping.lisp 2007年04月13日 22:11:02 +08:00
cffi-grovel.asd Make the dependency on uiop in subsystems that use it explicit. 2025年01月29日 19:03:11 +00:00
cffi-libffi.asd Refactor libffi code, get rid of type descriptor caching. 2016年01月19日 23:21:10 +01:00
cffi-tests.asd Make the dependency on uiop in subsystems that use it explicit. 2025年01月29日 19:03:11 +00:00
cffi-toolchain.asd cffi-toolchain: don't reintroduce bugs to ECL's ASDF 2019年05月25日 18:44:51 +01:00
cffi-uffi-compat.asd More copyright header year updates. 2006年05月03日 14:42:25 +08:00
cffi.asd Split out darwin-frameworks specific handling to drop uiop dependency in cffi core system. 2025年01月29日 19:03:11 +00:00
COPYRIGHT New example: mapping.lisp 2007年04月13日 22:11:02 +08:00
HEADER New example: mapping.lisp 2007年04月13日 22:11:02 +08:00
Makefile ecl: add implementation to the Makefile 2017年10月05日 13:53:15 +01:00
README.md housekeeping: c2ffi README, and clarify a comment 2023年04月12日 09:28:37 +02:00
TODO cffi/c2ffi: record some TODO's and comments 2018年01月30日 22:46:00 +01:00

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.

  • cl-autowrap is another project that uses c2ffi to generate CFFI bindings.