Liam Healy (lhealy) wrote,
Liam Healy
lhealy

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 or (:pointer (:struct name)) for the structure by reference. The bare structure form is still accepted, with a style warning.

The function 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.
Tags: lisp
Subscribe

  • cl-plplot for simple x-y plots from Lisp

    I had need recently to create quick x-y plots on the screen. I have been generating TikZ and PGFplots from Lisp for journal and conference papers…

  • cffi-libffi in latest CFFI release 0.11.0

    A week ago CFFI version 0.11.0 was released. This includes cffi-libffi, which permits calling and returning with structures by value. It replaces an…

  • cffi-libffi

    CFFI now has (on the master branch, but not yet in quicklisp) the system cffi-libffi, which allows calling and returning structures by value. For…

  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments