Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
resttime opened this issue May 4, 2020 · 4 comments
Open

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

resttime opened this issue May 4, 2020 · 4 comments
Labels

Comments

@resttime
Copy link
Owner

resttime commented May 4, 2020

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))
@resttime resttime changed the title Passing foreign structures by value to variadic functions Passing FSBV to variadic functions (al:draw-textf and etc.) May 4, 2020
@resttime resttime added the bug label May 22, 2020
@resttime
Copy link
Owner Author

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

@resttime
Copy link
Owner Author

Being tracked on Github now: cffi/cffi#290

@resttime
Copy link
Owner Author

resttime commented Nov 21, 2022

@theangelperalta
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants