Liam Healy - Post a comment
Apr. 28th, 2012
06:31 pm - mem-aref and mem-aptr in CFFI
The master branch of CFFI has the cffi-libffi system, which permits passing and returning structures by value. As part of that addition, some of the syntax for structures has changed, even without loading that system. Before, "bare structure" references were permitted, and they were interpreted to mean pointers. Now, the syntax to specify a structure type is
(:struct name) for the structure by value, and
(:pointer (:struct name)) for the structure by reference. The bare structure form is still accepted, with a style warning.
mem-aref returns an element of the array, an object; since we now can translate foreign structures, that includes structures. If the type is designated as
(:struct name), that means a CL representation of the structure will be returned. By default (with no
translate-from-foreign method defined), that is a plist. If you want a pointer instead, use the new function
mem-aptr. As a special case, using the bare structure type specification,
mem-aref still returns a pointer, but if you use the new form, you need to call
mem-aptr to get the pointer instead of the object translated into CL.
(Rationale for the new function is here.)
If this isn't working as described, please post to cffi-devel.