[cffi-devel] Design problem?
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Thu Oct 12 23:32:25 UTC 2006
2006/10/13, Luís Oliveira <luismbo at gmail.com>:
> On 10/12/06, Juan Jose Garcia-Ripoll <jjgarcia at users.sourceforge.net> wrote:
> > 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.
>
> Can you give me an example?
I have no longer access to this machine, but my interpreter of lisp at
some point broke because I was using converting (char*) pointers to
(short *) pointers, where "short" was the right size of the bytecodes
and "char" was the pointer to the buffer. Now it turns out that I was
not careful enough and the pointers in the buffer were not aligned on
32-bit boundary and reading the short cause a signal. There are other
examples like this.
> > 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.
>
> On all platforms I have access too they seem to behave the same since
> we manage to call varargs functions and the various Lisps don't know
> anything about their varargs-ness. I hear that might not always be
> true, so see below.
These lisps play a trick which is to copy all arguments onto the
stack, no matter what the function signature is. I am still learning
PPC and AMD64 ABIs to understand how to implement a dynamic FFI on
those platforms, but those solutions seem to be very fragile.
> If ECL can do something special about varargs, we can go ahead and use that!
It is not that it can do something special, it is rather that such
information is required. See the post by James Bielman.
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