Log in

CFFI-FSBV first light - Liam Healy

Sep. 25th, 2011

11:33 pm - CFFI-FSBV first light

Previous Entry Share Next Entry

Luis and I have been working on merging FSBV into CFFI as a new system CFFI-FSBV. This will allow calling foreign functions with structures passed and/or returned by value. It uses libffi.

The new system will have some advantages over the old. From the users perspective, there won't be a need to download a separate repository, and there won't be a need to directly use anything from CFFI-FSBV; all calls by value look just like regular CFFI with the appropriate type declarations. Based on a discussion on the cffi-devel mailing list, we decided and Luis implemented the syntax (:struct foo) for the structure (by value) and (:pointer (:struct foo)) for the pointer. Using 'foo directly is accepted for now with a warning, but is deprecated.

We now have, as astronomers say about a new telescope, "first light". Using my favorite complex number example from GSL

(defcstruct (complex-double :class complex-type)
  (dat :double :count 2))

and then with a few more definitions, we can call the foreign functions with the structure passed by value,
(foreign-funcall "gsl_complex_conjugate"
 (:struct complex-double) #C(3.0d0 4.0d0) (:struct complex-double))
#C(3.0d0 -4.0d0)
(foreign-funcall "gsl_complex_abs" (:struct complex-double) #C(3.0d0 4.0d0) :double)

Soon I hope we can reduce the "few more definitions", which do the translation between Lisp and C and are given in fsbv/examples.lisp, to something like what's in the old system's definition of defcstruct, with :constructor and :deconstructor options.

There's a lot more to do before this is ready for release, but we've got a start. The work is in the fsbv branch.



Date:November 3rd, 2011 06:38 pm (UTC)
Love your site man keep up the good work

(Reply) (Thread)