The
sb-alien:deref
function returns the value pointed to by a foreign pointer, or the value of a foreign array element. When dereferencing a pointer, an optional single index can be specified to give the equivalent of C pointer arithmetic; this index is scaled by the size of the type pointed to. When dereferencing an array, the number of indices must be the same as the number of dimensions in the array type.deref
can be set withsetf
to assign a new value.
The
sb-alien:slot
function extracts the value of the slot named slot-name from a foreignstruct
orunion
. If struct-or-union is a pointer to a structure or union, then it is automatically dereferenced.sb-alien:slot
can be set withsetf
to assign a new value. Note that slot-name is evaluated, and need not be a compile-time constant (but only constant slot accesses are efficiently compiled).
As noted at the beginning of the chapter, the System Area Pointer
facilities allow untyped access to foreign memory. SAPs can
be converted to and from the usual typed foreign values using
sap-alien
and alien-sap
(described elsewhere), and also
to and from integers - raw machine addresses. They should thus be
used with caution; corrupting the Lisp heap or other memory with
SAPs is trivial.
Creates a SAP pointing at the virtual address machine-address.
Access the value of the memory location at offset bytes from sap. This form may also be used with
setf
to alter the memory at that location.
Similarly named functions exist for accessing other sizes of word,
other comparisons, and other conversions. The reader is invited to
use apropos
and describe
for more details
(apropos "sap" :sb-sys)