[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FFI... (any C hackers around?)



You might be interested in the FFI design survey I'm currently writing. 
(50-60% finished only so far)
  http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html  

And I'm interested in your FFI design more detailled. I will add it to my 
survey as well then.

For closures I would suggest looking to bruno haibles callback library.
  http://users.n.ml.org/nc/ffcall/callback.html or
  http://clisp.cons.org/~haible/packages-ffcall-README.html

BTW: Making it like ACL is a huge task. The ACL FFI design is the richest and 
probably the hardest to implement. I mean foreign pointers and the class 
abstraction. I would suggest doing it simplier. (eg. corman lisp like)
personally i try to make mine or the emacs elisp FFI Visual Basic like, with 
the drawback to loose support for arrays and structs.

Eli Barzilay wrote:
> 
> This is a bit too long, but the result of the story (marked with a
> "***") looks like something that can be useful...

> 1. Passing a variable number of arguments to a function, with varying
>    sizes - now I have a big & ugly case statement with only 32bit
>    types.

only solvable for callee with cdecl linkage, but there it's quite easy.
I have a brainsimple sample in assembler at my survey.
 
> 2. Missing any way of making a C closure that is callable from C -
>    something that can be passed on to some C function that will call
>    the Scheme function.  A crude solution will be to rely on such
>    callbacks to have a data pointer and play with that... 
> It should probably be very simple to make it work on other OS's as
> well, since only the shared library openning and getting a symbol's
> address are the OS-dependent parts, and that is pretty similar to the
> MzScheme source.

libcallback is portable, perl's C::Dynalib is also portable across multiple 
cpu's. the gcc sources are also worth to study for the different CPU function 
calling schemes.

alignment issues are also problematic. (if you want to deal with c-structs 
at all. I don't want to)

the worst is to deal with foreign memory.
-- 
Reini Urban    
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html