Ystok-FFC - foreign-function compatibility
Ystok-FFC is a small portable Common Lisp library
of wrapper functions and macros for the foreign function interface (FFI).
The package provides a compatibility layer and allows the application code to
call the native FFI functionality of various Common Lisp implementations in a
uniform manner.
Ystok-FFC includes primitives for the following:
- defining foreign functions, structures, and scalar types,
- calling foreign functions,
- allocating and dereferencing foreign memory on low-level ,
- loading shared libraries.
Design principles
- "Canonical" specifiers of foreign types
in Ystok-FFC are the same as in LispWorks.
Syntax of some macros and signature
of some functions were also borrowed from the LispWorks
package
fli
.
- For many operations, Ystok-FFC provides shorter names than
the LispWorks
fli
package.
- External format specifiers are not canonicalized. They are the same as defined
by the underlying Common Lisp implementation, e.g. LispWorks or SBCL.
UTF-8 is supported by all functions except %cstring-length
,
which is not exported.
- Though foreign calls are usual place to change character encoding, we
recommend to avoide encoding and decoding at all. Everybody should select the
foreign module version that relies on the external format that matches
the internal string representation on the Common Lisp implementation.
- Void pointers are preferred in FFI declaration where foreign string are
passed
This is due to SBCL sb-alien:make-alien-string
always returns
#<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP # :TYPE (* (SIGNED 8))>
even for wide-character external formats like
:UCS-2LE
.
- For SBCL, we rely on SBCL typed pointers (of type
alien-value
)
rather than untyped SAPs (in contrast to CFFI).
Limitations
- Foreign callables (callbacks) are not supported by the current version.
Ystok-FFC does not pretend to cover all the foreign function interface features
encountered in all modern Common Lisp implementations.
It is only targeting at the most popular platforms and
supports only the primitives that are really used in our projects.
Dependencies
Ystok-FFC is required by
Platforms
- LispWorks
- Tested in full on versions 4.4 and 6.1 for Windows.
-
- SBCL
- Tested on version 1.0.55 on Windows.
-
Download and installation
Ystok-FFC is available from
http://lisp.ystok.ru/yffc/yffc-0-1-002.zip or
http://lisp.ystok.ru/yffc/yffc-0-1-002.tgz.
The distribution package contains both
the ASDlite/ASDF-based yffc.asd
and the LispWorks-based defsys.lisp system definition files.
See change.log.