[cffi-devel] Design problem?

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Thu Oct 12 08:55:30 UTC 2006


Hi,

on looking at CFFI from a porters point of view, I find what I
consider a design failure. Namely, C functions are used without
declaring them or even with fake declarations.

First of all, every time you call a function with foreign-funcall you
have to supply the types of the arguments. The aliasing of all pointer
types to :pointer means that type information is lost. Not all pointer
type are equivalent, because some types have alignment restrictions.

Supplying the argument types is extremely tricky in some cases and
might not be enough type information. For example,
      int f1(int i, ...)
is not the same function as
      int f2(int i, int j)
even though when we invoke f1(1, 2) the (2) is coerced to type int.

The information about "..." is taken cared of by DEFCFUN, but not by
FOREIGN-FUNCALL. That may seem useless but really, it is not the same
thing to call f1 and f2, because the C compiler does produce different
assembly code. For instance, using AMD64, in the first case it has to
push the arguments on the stack, while in the second case everything
goes into registers Similar things happen with a PPC backend.

My current approach to coerce all functions to the first form is
really a hack. And I wonder whether this design will survive newer
architectures to come.

Regards,

Juanjo

--
Max-Planck-Institut für Quantenoptik
Hans-Kopfermann-Str. 1, Garching, D-85748, Germany
Phone: +49 89 32905 345   Fax: +49 89 32905 336
http://www.mpq.mpg.de/Theorygroup/CIRAC/



More information about the cffi-devel mailing list