[cffi-devel] CFFI-FSBV: libffi-type-pointer for foreign structures created when needed

Luís Oliveira luismbo at gmail.com
Thu Sep 15 23:44:57 UTC 2011


On Tue, Sep 13, 2011 at 4:37 AM, Liam Healy <lnp at healy.washington.dc.us> wrote:
> So I changed my approach, and in the process simplified the code a
> lot.  Instead of making the necessary libffi-type in the defcstruct
> expansion, it will be made on demand only, when a foreign struct is
> used by, e.g. defcfun.  This happens recursively, so if one structure
> uses another, both will be made.  Once they structure is made, it is
> attached to the plist of the symbol for the type, so it need not be
> recomputed.

That makes sense.


> I'm now dealing with built-in types and coming up against a problem
> I've struggled with before (in GSLL and Antik): how to map C types
> (:short, :int, etc.) into established byte sizes (:uint8, :uint16).
> The problem is that libffi defines the types by their size, and it's
> up to the user to figure out how to map the common C types to those
> sizes; this is a topic in C that has always confused me.  I notice
> that CFFI has a mapping in the code at the end of src/types.lisp, but
> it's not easily accessible to other code, so I think if I break that
> out as some kind of table it will be useful to generate the
> appropriate pointers for libffi.  Unless someone has a better way.

You can use FOREIGN-TYPE-SIZE (like the code you mention does), or you
can pass the various :[u]intx types to CFFI::FOLLOW-TYPEDEFS and what
they boil down to.

Cheers,

-- 
Luís Oliveira
http://r42.eu/~luis/




More information about the cffi-devel mailing list