resttime/cl-liballegro

Passing FSBV to variadic functions (al:draw-textf and etc.)

Opened this issue · 4 comments

Description
Passing foreign structures by value to variadic functions will not work since cffi-libffi doesn't support it. CFFI needs to define ffi_prep_cif_var and update code to use it. This issue will exist until then and is technically a CFFI bug.

What this means is functions similar to printf that allow arbitrary number of function parameters like al:draw-textf won't work if one of the parameters is a struct (pointers remain fine).

;; tc is a struct returned by al:map-rgba-f
;; not a "struct pointer", an "actual struct"
(let ((tc (al:map-rgba-f 0 0 0 0.5))
      (font (al:create-builtin-font)))
  ;; The "Hello world!" is the extra parameter
  (al:draw-textf font tc 8 8 0 "%s" "Hello world!))

Workaround
Sometimes a workaround is possible like replacing calls to al:draw-textf with al:draw-text and the built-in FORMAT to achieve the same thing:

;; al:draw-textf is drawing text like printf
;; we can do the same thing with FORMAT
(al:draw-text font tc 8 8 0 (format nil "Filename: ~a" filename))

Bug reported and confirmed at CFFI's bug tracker. I'll give it a shot at fixing this when I get more time: https://bugs.launchpad.net/cffi/+bug/1882307

Being tracked on Github now: cffi/cffi#290

  • Define libffi function in CFFI
  • Get that merged in: cffi/cffi#347
  • Figure out where the libffi calls are being made with variadic args passing FSBV
  • Make changes that fix this
  • Get that merged in

My last comment on this issue may interest @resttime: cffi/cffi#285