[cffi-devel] Mutable Pointers
Stuart Sierra
mail at stuartsierra.com
Fri Jul 14 15:18:15 UTC 2006
Luís Oliveira wrote:
> On 2006-jul-14, at 02:38, Stuart Sierra wrote:
>> But POINTER-ADDRESS is not setf-able, is it?
>
> Right. AFAICT, some of the Lisps supported by CFFI don't have mutable
> pointers.
I suspected as much. I couldn't find it in SBCL's FFI, at least.
> (setf *stack-pointer* (inc-pointer *stack-pointer* 1)) should work.
> You can abstract that with a simple macro:
>
> (defmacro incf-pointer (place &optional (offset 1))
> `(setf ,place (inc-pointer ,place ,offset)))
But won't that set the value that *STACK-POINTER* points to? In my
example, *STACK-POINTER* is not a Lisp object but a foreign global
variable accessed by name with DEFCVAR. As I understand CFFI's :POINTER
type, the above macro will modify the memory location that PLACE points
to but will not modify PLACE itself.
-Stuart
More information about the cffi-devel
mailing list