next up previous
Next: Content Backgrounds Up: Recent Developments Previous: Shared Libraries

C Code Wrappers

To use the new intermediate-level shared library mechanism one has to write wrapper functions that map an internal XLISP function to a native C function. This is a simple but tedious task that can be automated. Several tools for automated interface generation exist; one of the most widely used is SWIG [1]. One disadvantage of SWIG is that it appears to be hard to interface it as closely to the garbage collection system as is desirable. Therefore a similar system based on Lisp was developed. Many ideas were borrowed from the design of SWIG.

As a simple example, a file containing

(in-package "POSIX")
(wrap:c-lines "#include <unistd.h>")
(wrap:c-function getuid "getuid" () :integer)
(wrap:c-function getlogin "getlogin" () :string)
defines an interface to the POSIX getuid and getgid functions. The wrapper generator produces a C and Lisp file. After compiling the C file into a shared library and loading the Lisp file, the functions can be used:
> (posix:getuid)
100
> (posix:getlogin)
"luke"

As a more complex example, the code

(wrap:c-lines "#include <pwd.h>")
(wrap:c-pointer (:struct "passwd")
                (:get pw-name "pw_name" :string)
                (:get pw-uid "pw_uid" :integer)
                (:get pw-gid "pw_gid" :integer)
                (:get pw-dir "pw_dir" :string)
                (:get pw-shell "pw_shell" :string))
specifies an interface to the structure returned by the getpwnam function. Similar expressions would be used to define interfaces to C++ objects.

This system is not yet complete; in particular it does not yet include a mechanism for specifying callback functions, automatic makefile/project creation, or FORTRAN and C++ wrapping.


next up previous
Next: Content Backgrounds Up: Recent Developments Previous: Shared Libraries
Luke Tierney
5/27/1998