* Attila Lendvai attila@lendvai.name CAE4vfcKMTRrYu37wy-WCRgTDrZjdB_h6nD6tRtq26civ6CibtQ@mail.gmail.com Wrote on Thu, 16 Jul 2020 10:06:46 +0200
The TODO entry was about specifically va_list. Now I'm not sure how the "new" stdargs API can be manipulated through CFFI - AFAIK it is purely a C compiler thing - you cannot foreign funcall to va_start and va_copy. The only way I could use it is through lisp implementations that support a form of c-inline, or through "grovelled" code which would be loaded through a shared library.
IIRC libffi has support for dealing with varargs.
there could be a new system called cffi/c2ffi+libffi, or somesuch, that expands to cffi+libffi definitions? or is the cffi + libffi integration transparent and loaded on-demand? looks like that.
yes when you call something that passes structures by value libffi will translate structures by value if libffi is loaded or it'll show you an error indicating you should load the cffi-libffi system.
[BTW *foreign-structures-by-value* is intially set to a lambda function which throws a restartable error. It offers a restart - to load the cffi-libffi system. when that system is loaded value of the variable will be overwritten.
But there is a bug: the restart won't proceed with the foreign funcall The last line withing that lambda form should be
(funcall *foreign-structures-by-value* args)
so that instead of returning to the caller it will proceed with the intended funcall ]
or straight out depend on libffi by cffi/c2ffi? i don't think that's a good idea, though, without some hard-pressing reasons.
i don't feel the urge to get into actually hacking on this, but i'll be happy to answer questions about the cffi/c2ffi code.
[I do have some other questions] But as luis noted varargs already works- eg. cffi/c2ffi translates functions of the form int foo(int a, ...) to a (defcfun foo :int ((a :int) &rest)) - which you can call as (foo 42 :char #\c)
However the varargs machinery seems to be old - it predates the fsbv machinery and so it doesn't work when the defcfun form has struct arguments. I expect to hit this corner case soon and I hope I'll be the fix will be trivial - since foreign-funcall already works.
I'd think that will be sufficient without having to introduce libffi machinery for varargs. Right?
[I vaguely remember seeing a comment by the author about some part of libffi which was not yet implemented - probably on the mailing list - or a comment or document in the code code was reorganized and removed. was it perhaps about varargs? ]
My initial post on this thread only dealt with functions of the form
int foo(int a, va_list arg)
which cffi/c2ffi was skipping without generating a defcfun because it didn't have a type for va_list. As I noted elsewhere these would be hard to use anyway,