4.1.2 Creating foreign structure types Foreign pointer objects

Lisp views all foreign storage as Lisp objects of Lisp typeforeign-pointer. foreign pointers can be passed like any Lisp object.

A foreign pointer object has two attributes, an address and a type. The address can be any virtual address, and the type can be nil or any valid foreign type expressed as(:pointer foreign-type). The type attribute tells Lisp how to interpret the bits found at the address specified in the address portion of the foreign pointer object. A type attribute ofnil means that the pointer object has no foreign type.

When you use the macrodef-foreign-struct to create a foreign structure, a predicate, slot accessors, and a constructor function are automatically created for the structure. When you use the constructor function to make an instance of the foreign structure type, it creates a foreign pointer to the structure of type(:pointer foreign-structure-name). You can also use the functionmake-foreign-pointer to create foreign pointer objects. The Common Lisp function type-of recognizes foreign pointer objects.

Note that foreign storage itself is not associated with a type; rather, foreign pointers associate foreign storage with a type.

For example, assume that you have two foreign pointers of different types that point to the same storage area in memory. The first foreign pointer is of type(:pointer my-struct) and the second foreign pointer is of type(:pointer your-struct). When you access that storage with the first pointer, it is treated as an object of typemy-struct. When you access that same storage with the second pointer, it is treated as an object of typeyour-struct. If you change the type of the first pointer, it has no effect on the way the storage is treated when it is accessed by the second pointer. In other words, if several foreign pointers point at the same area of foreign storage, changes to one of the pointers do not propagate to the other pointers.

The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker