Creates a dynamic-extent foreign pointer which points to the data in a given Lisp array while the forms are executed.
fli
with-dynamic-lisp-array-pointer (pointer-var lisp-array &key start type) &body body => last
pointer-var⇩ |
A variable to be bound to the foreign pointer. |
lisp-array⇩ |
A static or pinned Lisp array (a string or a byte/single-float/double-float array). |
start⇩ |
An index into the Lisp array. |
type⇩ |
A foreign type. The default is :void. |
body⇩ |
A list of forms. |
last |
The value of the last form in body. |
The macro with-dynamic-lisp-array-pointer
enables the data in a Lisp array to be shared directly with foreign code, without making a copy. A dynamic-extent pointer to the array's data can be used within body wherever the :pointer foreign type allows.
with-dynamic-lisp-array-pointer
creates a dynamic extent foreign pointer, with element type type, which is initialized to point to the element of lisp-array at index start. The default value of start is 0.
This foreign pointer is bound to pointer-var, the forms of body are executed and the value of the last form is returned.
Pointers created with this macro must be used with care. There are three restrictions:
An example of using a static array:
(let ((vector (make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(65 77 23) :allocation :static))) (fli:with-dynamic-lisp-array-pointer (ptr vector :start 1 :type '(:unsigned :byte)) (fli:dereference ptr))) => 77
An example of using a pinned array:
(let ((vector (make-array 3 :element-type '(unsigned-byte 8) :initial-contents '(65 77 23) :allocation :pinnable))) (with-pinned-objects (vector) (fli:with-dynamic-lisp-array-pointer (ptr vector :start 1 :type '(:unsigned :byte)) (fli:dereference ptr)))) => 77
Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:58