[cffi-devel] Re: Mutable Pointers

Stephen Compall s11 at member.fsf.org
Fri Jul 14 18:52:21 UTC 2006


Luís Oliveira wrote:
>> If I follow correctly, this can be more generally solved with a
>> cross-platform setf-expander for POINTER-ADDRESS that requires its PTR
>> arg to be a place, whereupon things like (incf (pointer-address
>> *ptr*)) and any other place-modifier should work.
> 
> Hmm. I find that a bit confusing. (incf (pointer-address foo)) really
> makes it look look that foo's address is mutable.

No more than (incf (ldb (byte 2 1) foo)) makes it look as if the
integer itself at FOO is mutable, unless you must take into account
the prevalence of 1-arg slot accessors.

> So, I propose incf-pointer again, this time without the double
> evaluation bug:
> 
> (define-modify-macro incf-pointer (&optional (offset 1)) inc-pointer)

Simple enough for anyone to duplicate for future modifiers, too.  I
should spend more time expanding my symbology.

For posterity, here is a setf-expander:

(define-setf-expander pointer-address (ptr &environment env)
  (multiple-value-bind (temp-vars value-forms store-vars
                        store-form access-form)
      (get-setf-expansion ptr env)
    (destructuring-bind (ptr-store-var) store-vars
      (with-unique-names (store-var)
        (values temp-vars value-forms
                (list store-var)
                `(let ((,ptr-store-var (make-pointer ,store-var)))
                   ,store-form
                   ,store-var)
                `(pointer-address ,access-form))))))

-- 
Stephen Compall
http://scompall.nocandysw.com/blog



More information about the cffi-devel mailing list