[Ecls-list] CFFI and DFFI

Matthew Mondor mm_lists at pulsar-zone.net
Tue Jul 21 02:03:03 UTC 2009


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.

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 error being:

[...]
;;; Compiling (DEFUN VIDEO-MODE-OK ...).
;;; Compiling (DEFUN SET-VIDEO-MODE ...).
;;; Error: in file /home/mmondor/asdf/cl-sdl/sdl/sdl.lisp, position 12940, and form 
;;;   (DEF-FUNCTION (SDL_SetColors SET-COLORS) (# # # ...) ...)
;;; The macro form (FFI:DEF-FUNCTION ("SDL_SetColors" SET-COLORS) ((SURFACE (:STRUCT-POINTER SURFACE)) (COLORS (:STRUCT-POINTER COLOR)) (FIRSTCOLOR :INT) (NCOLORS :INT)) :RETURNING :INT :MODULE "sdl") was not expanded successfully.
;;; Error detected:

;;; Unsupported argument type: (STRUCT-POINTER (STRUCT (FLAGS
UNSIGNED-LONG) (FORMAT (STRUCT-POINTER (STRUCT ((STRUCT (NCOLORS INT)
(COLORS (STRUCT-POINTER (STRUCT (R UNSIGNED-BYTE) (G UNSIGNED-BYTE) (B
UNSIGNED-BYTE) (UNUSED UNSIGNED-BYTE))))) (STRUCT-POINTER (STRUCT
(NCOLORS INT) (COLORS (STRUCT-POINTER (STRUCT (R UNSIGNED-BYTE) (G
UNSIGNED-BYTE) (B UNSIGNED-BYTE) (UNUSED UNSIGNED-BYTE)))))))
(BITS-PER-PIXEL UNSIGNED-BYTE) (BYTES-PER-PIXEL UNSIGNED-BYTE) (R-LOSS
UNSIGNED-BYTE) (G-LOSS UNSIGNED-BYTE) (B-LOSS UNSIGNED-BYTE) (A-LOSS
UNSIGNED-BYTE) (R-SHIFT UNSIGNED-BYTE) (G-SHIFT UNSIGNED-BYTE) (B-SHIFT
UNSIGNED-BYTE) (A-SHIFT UNSIGNED-BYTE) (R-MASK UNSIGNED-LONG) (G-MASK
UNSIGNED-LONG) (B-MASK UNSIGNED-LONG) (A-MASK UNSIGNED-LONG) (COLOR-KEY
UNSIGNED-LONG) (ALPHA UNSIGNED-BYTE)))) (W INT) (H INT) (PITCH
UNSIGNED-SHORT) (PIXELS POINTER-VOID) (OFFSET INT) (HWDATA
POINTER-VOID) (CLIP-RECT (STRUCT (STRUCT (X SHORT) (Y SHORT) (W
UNSIGNED-SHORT) (H UNSIGNED-SHORT)))) (UNUSED UNSIGNED-LONG) (LOCKED
UNSIGNED-LONG) (MAP POINTER-VOID) (FORMAT-VERSION UNSIGNED-INT)
(REF-COUNT INT)))

;;; Warning: COMPILE-FILE warned while performing
             #<ASDF:COMPILE-OP NIL 152951784> on
             #<ASDF:CL-SOURCE-FILE "sdl" "sdl" 161838112>.
;;; Warning: COMPILE-FILE failed while performing
             #<ASDF:COMPILE-OP NIL 152951784> on
             #<ASDF:CL-SOURCE-FILE "sdl" "sdl" 161838112>.

I assume that the structure might be making use of some feature not
supported by ECL UFFI compatibility layer, but I've not been able to
investigate further yet.

Probably that I'll have to read the UFFI package, considering there
also seems to lack definitive documentation (at least according to the
page), and then to compare to ECL FFI source implementation, although
perhaps someone has interesting pointers that could help me locate more
easily what I'm looking for?

Unfortunately in this case, cl-sdl defines its own wrapper around UFFI
in ffi/uffi.lisp which complicates matters and could also be a
potential bug source.

Thanks,
-- 
Matt




More information about the ecl-devel mailing list