[Haskell-cafe] Re: Could FFI support pass-by-value of structs?

John Meacham john at repetae.net
Tue Jun 30 21:59:53 EDT 2009


On Tue, Jun 30, 2009 at 01:18:32AM +0100, Duncan Coutts wrote:
> On IA32 structs/unions passed as parameters go by value on the stack.
> For structs/unions as function results, they are stored into a
> caller-allocated area on the stack, pointed to by a "hidden" first arg.
> 
> It's different on each arch, but it's all completely specified.
> 
> > moreover, even for pointers-to-structures, there is no definitive
> > layout due to packing problem
> 
> Actually the padding is also specified by the C ABI. See section 3-3.
> Compiler pragmas to use packed layout are not ABI conformant (and so
> typically are only used internally).

Yup. Unfortunately this doesn't help us, since in order to pass
structures we need to know more than just the layout (offset and size)
of the type, but we need to know the underlying C types as well which a
Storable instance doesn't give us. depending on the ABI, struct passing
may not be as simple as 'pass on stack' vs 'pass in registers'. it may
be something like 'the floating point components get pulled out and put
in registers, which the other components get pushed onto the stack'. So,
without some compiler magic, like a 'deriving Storable' instance that
derived some hidden methods to contain this extra information, or
additions to storable, this won't work in general.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-Cafe mailing list