AW: [UFFI-Users] get-slot-value and nested structures
Joerg-Cyril.Hoehle at t-systems.com
Mon Sep 6 03:32:31 MDT 2004
>> (use-package :uffi)
>> (def-struct i-s
>> (df :double))
>> (def-struct holder
>> (is i-s))
>> (defvar *f* (allocate-foreign-object 'holder))
>> (setf (get-slot-value (get-slot-value *f* 'holder 'i-s)
>> At heart, my question is, "Is this 'correct' UFFI?" Will
>this work on all UFFI-supported platforms?
>In quick testing on Lispworks, the answer is no. The code above is
>wrong. The form
> (get-slot-value *f* 'holder 'i-s)
>is an error on Lispworks.
What if you try 'is (field name) instead of 'i-s (type) as third argument to get-slot-value? Rif's code is in error here.
I'm somewhat relieved that you say that nested structures is not yet included in UFFI because allowing a nested get-slot-value would mean a complete different model of translation between UFFI and CLISP forms:
In the canonical translation model, uffi:get-slot-value maps to (FFI:FOREIGN-VALUE (FFI::%SLOT #)) (or just (FFI:SLOT #)), i.e. the foreign thing is converted to a Lisp object (a defstruct/#<STRUCTURE-CLASS> thing) with no more references to the foreign world. Thus, the outer get-slot-value would error out when presented this Lisp object instead of a foreign thing.
UFFI:get-slot-ref would be doable extension IMHO (not deeply thought throuh). It would map to just (FFI::%SLOT #) and perform no conversion. The result would be a pointer/reference to the substructure. Is that overkill?
(setf (get-slot-value (get-slot-ref *f* 'holder 'is &optional 'i-s)
'i-s 'df) 3.0d0)
More information about the UFFI-Users