UFFI Reference Guide

Kevin M. Rosenberg

Heart Hospital of New Mexico

504 Elm Street N.E.
New Mexico

  • The UFFI package was designed and written by Kevin M. Rosenberg.

  • Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with the no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the UFFI distribution.

  • Allegro CL® is a registered trademark of Franz Inc.

  • Lispworks® is a registered trademark of Xanalys Inc.

  • Microsoft Windows® is a registered trademark of Microsoft Inc.

  • Other brand or product names are the registered trademarks or trademarks of their respective holders.

Table of Contents

1. Introduction
Supported Implementations
2. Programming Notes
Implementation Specific Notes
Foreign Object Representation and Access
Optimizing Code Using UFFI
Cross-Implementation Optimization
I. Declarations
def-type — Defines a Common Lisp type.
II. Primitive Types
def-constant — Binds a symbol to a constant.
def-foreign-type — Defines a new foreign type.
null-char-p — Tests a character for NULL value.
III. Aggregate Types
def-enum — Defines a C enumeration.
def-struct — Defines a C structure.
get-slot-value — Retrieves a value from a slot of a structure.
get-slot-pointer — Retrieves a pointer from a slot of a structure.
def-array-pointer — Defines a pointer to a array of type.
deref-array — Deference an array.
def-union — Defines a foreign union type.
IV. Objects
allocate-foreign-object — Allocates an instance of a foreign object.
free-foreign-object — Frees memory that was allocated for a foreign boject.
with-foreign-object — Wraps the allocation of a foreign object around a body of code.
size-of-foreign-type — Returns the number of data bytes used by a foreign object type.
pointer-address — Returns the address of a pointer.
deref-pointer — Deferences a pointer.
ensure-char-character — Ensures that a dereferenced :char pointer is a character.
ensure-char-integer — Ensures that a dereferenced :char pointer is an integer.
make-null-pointer — Create a NULL pointer.
null-pointer-p — Tests a pointer for NULL value.
+null-cstring-pointer+ — A constant NULL cstring pointer.
with-cast-pointer — Wraps a body of code with a pointer cast to a new type.
def-foreign-var — Defines a symbol macro to access a variable in foreign code
V. Strings
convert-from-cstring — Converts a cstring to a Lisp string.
convert-to-cstring — Converts a Lisp string to a cstring.
free-cstring — Free memory used by cstring.
with-cstring — Binds a newly created cstring.
convert-from-foreign-string — Converts a foreign string into a Lisp string.
convert-to-foreign-string — Converts a Lisp string to a foreign string.
allocate-foreign-string — Allocates space for a foreign string.
VI. Functions & Libraries
def-function — Declares a function.
load-foreign-library — Loads a foreign library.
find-foreign-library — Finds a foreign library file.
A. Installation
Download UFFI