[squeak-dev] FFI question: array of structures as parameter

Douglas McPherson djm1329 at san.rr.com
Sun Jun 10 04:12:13 UTC 2012


All,

I'm trying to call a function in an external library which takes an array of structures as one of its parameters. I can see how to define a subclass of ExternalStructure, and how that creates convenient field accessors which read/write an underlying ByteArray. I can see how to use such an ExternalStructure to pass the struct, or a pointer to it, to a function in the library. Is there a similar object I can create which allows me to read/write an array of these structs (i.e. does the proper marshaling to/from a ByteArray)? 

I got the i/f working by rolling my own -- directly filling up a ByteArray with the right number of instances of the serialized-by-hand structure, creating an ExternalData instance with said ByteArray as the handle, and passing this as the parameter. But this doesn't allow me to use the field accessor methods created by ExternalStructure, so it feels like I'm missing something. 

For concreteness, the API looks something like this:

typedef struct
{
    uint32_t someId;
    int32_t  someInt; 
} fooStruct;

int32_t apiFunction
(
 const  fooStruct *foo_list,
 uint32_t foo_list_size
 );

Any suggestions?

Thanks,
Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20120609/e9f300a4/attachment.htm


More information about the Squeak-dev mailing list