[racket] handling "private" objects in FFI

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun Mar 20 03:41:50 EDT 2011

Hi all,

I've just started trying to use the FFI, and although I'm much afraid that being a person without any C programming experience and never having used a FFI either, I might not get too far with it, I don't want to give up early :-;

The first "bigger" problem that comes up is,-  I wonder how to handle composite objects (structs) returned by a library function that have themselves composite objects as fields, but these objects in turn are considered to be "private", as seen by them being declared like so:

typedef struct xy xy;

Now I'm not too clear about what a "private" object in C actually is, but from the normal user's point is seems to mean I can't access the struct fields directly, and anyway it's no problem because the user doesn't need to declare anything but the outer object...
But as a "foreign" user, I need to define this outer object somehow, and if I want to use define-cstruct as I assume is the normal way to proceed, I have to define-cstruct the inner objects in turn, and so on...

On the one hand, I don't even know if I could do so - because I'm not sure, would  it be possible that as a "foreign" user who gets everything from the *.so library, can I access those "private" objects in there, in contrast to a normal c user who cannot even compile his code because he's including just the one header file with the typedef (I'm asking this first question just to get a better understanding of how a FFI works :-;) ?

On the other hand, it's clear I'm just not supposed to access those private objects anyway - so my second question is, what can I do? Is there any way to define the structures as "opaque"  types and not do anything with them, so they're just  marshaled back and forth and never get changed by me?

Many thanks for any help,
Sigrid


Posted on the users mailing list.