[racket-dev] [racket] newbie: foreign C structure definition question

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Nov 18 22:06:34 EST 2010

[redirected to dev again]

15 minutes ago, Hendrik Boom wrote:
> On Tue, Nov 16, 2010 at 11:37:17PM -0500, Eli Barzilay wrote:
> > Three minutes ago, Jay McCarthy wrote:
> > > We could use a syntax parameter in define-cstruct to communicate to
> > > the vector syntax to give them the correct size in structs and make
> > > my macro's approach the normal behavior.
> > 
> > * Types in a cstruct are plain expressions (that should evaluate to
> >   ctype values).
> > 
> > * Arrays should be available as a type outside of cstructs too.
> An array of, say, ten elements should be passes the same way as a
> struct with the same ten elements.

Yes, what I said earlier is that it really boils down to being able to
define a libffi type descriptor with some manually specified size and
alignment.  It's also how the current hackarounds all work.

> That C doesn't do this is a flaw in its calling interface.

And that actually is another problem for Sam when he implements this
-- dealing with whatever situations make C expect the array to be
passed by value (a real one, with the whole array on the stack).

> But given that it's possible to pass references, it should be
> possible to pass references to C arrays when the C funtion is coded
> as if it expects an array (when, of course, it really expects a
> reference).

Right, this works assuming sane C, and IIRC, with small arrays it can
expect the whole array to be on the stack.  (But maybe the rules for
structs are the same, so it works out by size only.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.