Previous: , Up: Pointers   [Contents][Index]


with-foreign-pointer

with-foreign-pointer

Syntax

Macro: with-foreign-pointer (var size &optional size-var) &body body

Arguments and Values

var
size-var

A symbol.

size

An integer.

body

A list of forms to be executed.

Description

The with-foreign-pointer macro, binds var to size bytes of foreign memory during body. The pointer in var is invalid beyond the dynamic extend of body and may be stack-allocated if supported by the implementation.

If size-var is supplied, it will be bound to size during body.

Examples

  CFFI> (with-foreign-pointer (string 4 size)
          (setf (mem-ref string :char (1- size)) 0)
          (lisp-string-to-foreign "Popcorns" string size)
          (loop for i from 0 below size
                collect (code-char (mem-ref string :char i))))(#\P #\o #\p #\Null)

See Also

foreign-alloc
foreign-free