[racket] FFI structs and custom offsets

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Feb 9 18:40:04 EST 2015

I think the value of `_list-struct` is mostly that computes offsets for
you based on the current platform's conventions. If you know the
offsets that you want to use, then you could make A C-type constructor
from scratch using `make-ctype` --- with `malloc` and `ptr-set!` in the
Racket-to-C function, and `ptr-ref` in the C-to-Racket function.

In the case of `define-cstruct`, an extension for explicit offsets
makes a little more sense to me, since `define-cstruct` does a lot more
than just compute offsets for you. We'd certainly consider a patch. (I
don't think I understand enough the situation where you'd want it to
try making the changes myself, though.)

At Mon, 9 Feb 2015 23:46:36 +0100, Bartosz Przygoda wrote:
> Hello,
> 
> While checking info on certain unix structures, it occured to me that the
> order of the fields is often not standardized and implementations are free
> to choose in this regard.
> 
> However, Racket FFI allows to define types that marshal data to and from
> basing on the offsets generated from the list of types. It seems like it
> should be doable (not that big modification) to also allow to pass custom
> offsets as an argument to _list-struct and (possibly, haven't yet
> understood its code fully) define-cstruct.
> 
> Am I on the right track, or am I missing something?
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.