The setf-expansion for nested FOREIGN-SLOT-VALUE calls ist not quite correct:
CFFI> (macroexpand '(setf (foreign-slot-value (foreign-slot-value ptr `struct1 'slot1) `struct2 'slot2) val)) (LET* () (MULTIPLE-VALUE-BIND (#:G1997) VAL (PROGN (FOREIGN-SLOT-SET #:G1997 (FOREIGN-SLOT-VALUE PTR) 'STRUCT2 'SLOT2) #:G1997))) T ^^^^^^^^^^^^^^^^^^^^^^^^
Defining the expander like
(define-setf-expander foreign-slot-value (ptr type slot-name &environment env) (multiple-value-bind (temps vals stores store-form access-form) (get-setf-expansion ptr env) (declare (ignore store-form stores)) (let ((type-tmp (gensym "TYPE-")) (slot-name-tmp (gensym "SLOT-NAME-")) (store (gensym "STORE-"))) (values `(,type-tmp ,slot-name-tmp ,@temps) `(,type ,slot-name ,@vals) `(,store) `(progn (foreign-slot-set ,store ,access-form ,type-tmp ,slot-name-tmp) ,store) `(foreign-slot-value ,access-form ,type-tmp ,slot-name-tmp)))))
should do the job a bit better, though it might be optimized in some way (this is my first try to define a setf expander).
Btw. the manual contains an example use of FOREIGN-SLOT-VALUE with the simplified syntax
(foreign-slot-value ptr 'struct 'slot-1 'slot-2)
I think CFFI has all the informations at hand to handle this, so will it be implemented one day?
Regards,
Marco Gidde