FFI Array of Structs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI Array of Structs

Beckmann, Tom
Dear Squeak devs,

I'm trying to send an array of structs to a C library via FFI.
Scenario would look about as follows:

struct my_struct {
    float a;
    float b;
};
void myFunction(struct my_struct *list, int count);

So far I always failed at the point of "arguments could not be coerced" when trying to use a stamp like this:

apiMyFunction: anArray num: aNumber
  <apicall: void 'myFunction' (MyStruct* long) module: 'mylib.so'>

with MyStruct being an ExternalStructure with
#((a 'float') (b 'float'))
as its >>fields class method.

The open question is now how to call this from squeak code, failed attempts so far include:

- ​an "Array" with the MyStruct classes ("could not coerce arguments")
- a custom ArrayedCollection subclass ("could not coerce arguments"), even though I wasn't quite sure whether I implemented it correctly
- a custom ExternalData subclass "MyStructArray", passing an empty instance leads to a segfault, I'm not sure how I would fill it (<apicall: void 'myFunction' (MyStructArray long) module: 'mylib.so'>)

Any help is appreciated!

Regards
Tom