Separate lisp and foreign name for cffi defcstruct?

Discussion of Common Lisp

Separate lisp and foreign name for cffi defcstruct?

Postby sinnatagg » Sat Jun 16, 2012 3:46 am

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

ie. in LispWorks FLI one can do

Code: Select all
(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
sinnatagg
 
Posts: 28
Joined: Tue Apr 21, 2009 3:04 am

Re: Separate lisp and foreign name for cffi defcstruct?

Postby Ramarren » Sat Jun 16, 2012 7:13 am

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.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Separate lisp and foreign name for cffi defcstruct?

Postby MicroVirus » Mon Jun 18, 2012 5:37 am

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.
MicroVirus
 
Posts: 11
Joined: Sat Apr 07, 2012 6:20 am

Re: Separate lisp and foreign name for cffi defcstruct?

Postby sinnatagg » Thu Jun 21, 2012 1:52 am

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
sinnatagg
 
Posts: 28
Joined: Tue Apr 21, 2009 3:04 am


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 3 guests