AW: [cffi-devel] bits from a new tutorial

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Thu Dec 22 16:48:39 UTC 2005


Luís Oliveira wrote:
>This tutorial shows the usefulness of foreign-funcall for C functions  
>with varargs. Lispworks unfortunately doesn't export this  
>functionality.
I consider it an omission in a foreign API if all that is provided is varargs. I'd bug the respective developers until they provide a function that takes an array of some such.
execv() is an excellent example of how it can be done right.
If there's some such function in the API, I urge you to call that, not the C varargs function. Calling the latter is like trying to call a macro at run-time in Lisp: macros and varargs are syntactic sugar for compile-time. At run-time, it's too late.

Considering the baroque calling conventions of C compilers (Duane Retting posted details in comp.lang.lisp about some exotic ones not too long ago), it's no surprise that varargs are not supported.  E.g. Duane Rettig's article made me wonder whether:
1. one can portably call syslog() from any foreign (non C) language, and
2. whether varags are compatible with full prototypes, which clisp's ffcall likes to use.

With that I mean that if I understand Duane right, the calling conventions for
foo(char *, ...); when called in C as
foo("abl",(double)x,(int)y,(whatever)z)
can be different from the calling convention that arises from a declaration as
foo(char*,double,int,whatever);
The call could crash?!?

Maybe I misunderstood Duane Rettig, but I feel like there's a problem. Well, I should take that to comp.lang.lisp again (or comp.lang.C or whatever).

W.r.t. syslog() (this one once came up in the clisp mailing list), probably the only sensible interface is to call it as
(foreign-funcall "syslog" "%s" <Lisp-formatted-string>)

Regards,
	Jörg Höhle.



More information about the cffi-devel mailing list