This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Separate lisp and foreign name for cffi defcstruct?

4 posts · 3210 views

Is it possible to assign a separate lisp name for foreign structs in cffi?

ie. in LispWorks FLI one can do
(fli:define-c-struct (do-foo :foreign-name "do_foo") ...)
But as far as I can see there is no similar option for cffi.

Is it the case that the defcstruct name can be arbitrary and is not referenced against the exported c symbols? Arbitrary names do appear to work fine, but this isn't really spelled out in the docs.


-a

Re: Separate lisp and foreign name for cffi defcstruct?

sinnatagg wrote:Is it the case that the defcstruct name can be arbitrary and is not referenced against the exported c symbols?
I am reasonably sure that this is in fact the case. CFFI in general doesn't enforce type safety of foreign data, you can refer to any piece of memory you own as any type. And C doesn't export structure layouts anyway (as a standard, I googled a bit and maybe Windows DLLs, but the information seems confused), so there wouldn't really be any point in referencing those symbols.

Re: Separate lisp and foreign name for cffi defcstruct?

Natively, there is nothing like type safety when calling C code. That's why each piece of C code that needs to use a shared library (for instance dll) needs the header file with the function definitions and type definitions.
No such information is exported from the shared library; only the entry-point name and/or ordinal number to be able to refer to the right function, but nothing of the function signature is conveyed.

Re: Separate lisp and foreign name for cffi defcstruct?

Thanks, I didn't notice that structs aren't exported and is only described in the code.

Any symbol for the struct does indeed work fine.


-a