[Ecls-list] CFFI and DFFI

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Tue Jul 21 08:04:12 UTC 2009


On Tue, Jul 21, 2009 at 4:03 AM, Matthew Mondor<mm_lists at pulsar-zone.net> wrote:
> Since basic custom UFFI tests seemed to work, and considering that ECL
> appears to have native support for it and that the resulting assembly
> for UFFI stubs seemed much better than for CFFI ones (i.e. 2 vs 6
> function calls, 18 vs 30 instructions for a void (*)(void) function
> wrapper, I decided to then try cl-sdl which uses UFFI.

CFFI has some weird assumptions about what a foreign function
interface can and can not do. It assumes everything has to be dynamic
while ECL prefers to compile things (the resulting code is more
efficient), does not care that functions with varargs ("..." in C) may
be different from other functions (making our compiled code really
really unportable), etc. It was never built with ECL in mind and
development never accepted a twist in this direction, that made my
initial port very difficult and I have never had time to continue
supporting it. I do not know the status of CFFI support for ECL. On
the other hand, UFFI is much much easier to deal with, being closer to
C and keeping really a subset of what can be done on any platform.

> I first removed UFFI ASDF dependencies from the .asd files (ECL
> provides it and UFFI package mentions nothing about ECL support),
> then had to fix a few problems relating to how #+unix conditionals
> weren't being evaluated, and it started building, yet I then get some
> interesting errors at various function definitions using structures as
> arguments, despite those structures being previously defined:
>
> [...]
>
> (def-foreign-struct surface
>  (flags  uint32)
>  (format (:struct-pointer pixel-format))
>  (w      int)
>  (h      int)
>  (pitch uint16)
>  (pixels :pointer-void)
>  (offset int)
>  (hwdata :pointer-void) ; internally struct (opaque pointer)
>  (clip-rect (:struct rect))
>  (unused uint32)
>  (locked uint32)
>  (map    :pointer-void) ; internally struct (opaque pointer)
>  (format-version unsigned-int)
>  (ref-count int))
>
> [...]
>
> (def-foreign-routine ("SDL_Flip" flip) int
>  (screen (:struct-pointer surface)))

The following code would be the UFFI version. It compiles, except for
the fact that I do not have SDL installed and the linker complains
about a missing symbol. I presume that the cl-sdl macros do not expand
properly or have some eval-when (:compile-toplevel) statements
missing.

(ffi:def-struct surface
 (flags  uint32)
 (format (:struct-pointer pixel-format))
 (w      int)
 (h      int)
 (pitch uint16)
 (pixels :pointer-void)
 (offset int)
 (hwdata :pointer-void) ; internally struct (opaque pointer)
 (clip-rect (:struct rect))
 (unused uint32)
 (locked uint32)
 (map    :pointer-void) ; internally struct (opaque pointer)
 (format-version unsigned-int)
 (ref-count int))

(ffi:def-function ("SDL_Flip" flip) ((screen int) (surf (* surface)))
:returning int)

Juanjo

-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list