Next Previous Up Top Contents Index

5 Function and Macro Reference

with-coerced-pointer

Macro

Summary

Makes a temporary copy of a pointer, executes a list of forms which may use and alter the copy of the pointer across the scope of the macro, and then deallocates the memory provided for the copy of the pointer.
Package

fli

Signature

with-coerced-pointer (binding-name &key type pointer-type) pointer &body body => last
Arguments

binding-name

A temporary name used to access a copy of pointer.

type

The type of the object pointed to by the temporary pointer. This keyword can be used to access the data at the pointer as a different type.

pointer-type

The pointer-type of the temporary pointer.

pointer

An FLI pointer of which a copy is made. The lifetime of the copy is across the scope of thewith-coerced-pointer macro.

body

A list of forms to be executed across the scope of the temporary pointer binding.

Values

last

The value of the last form in body.

Description

The macrowith-coerced-pointer makes a temporary copy of a pointer, and executes a list of forms which may use the copy across the scope of the macro. Once the macro has terminated the memory allocated to the copy of the pointer is automatically freed.
Example

In the following example an array of ten integers is defined, pointed to byarray-obj. The macrowith-coerced-pointer is used to return the values stored in the array, without alteringarray-obj, or permanently tying up memory for a second pointer.
(setf array-obj
      (fli:allocate-foreign-object :type :int
                  :nelems 10
                  :initial-contents 
                  '(0 1 2 3 4 5 6 7 8 9)))

(fli:with-coerced-pointer (temp) array-obj (dotimes (x 10) (print (fli:dereference temp)) (fli:incf-pointer temp)))

See Also

allocate-dynamic-foreign-object
free-foreign-object
with-dynamic-foreign-objects

LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker