[squeak-dev] Re: FFI structs

Alain Rastoul alf.mmm.cat at gmail.com
Fri Oct 31 22:23:02 UTC 2014


Hi Annick,

you can't pass smalltalk strings or objects to ffi as parameters,
you have to allocate the buffer member of your structure
on the external heap ( plus to avoid being gc'd before ffi call)
with ExternalAddress allocate: <your buffer/string size +1 for string 
null termination>
fill your buffer with byteAt:put: method,
and release this memory with free when you have finished.

not sure, but you could try something like:

s := '05:45' copyWith: (Character value: 0).
a := ExternalAddress allocate: s size.
s asByteArray withIndexDo: [ :b :i | a byteAt: i put: b  ].
myStruct time: a.
... call your ffi ...
a free


Regards,

Alain

Le 29/10/2014 11:59, Annick Fron a écrit :
> I I have a C struct with a char*
>
> struct result {
> 	char* time }
>
> I define an ExternalStructure in FFI , with one field of type char* (note that the syntax char [5] is not accepted ! ).
>
> defineFields generates the accessors time and time:
>
> If I use
> time: ’05:45’
>
> I get an error.
> How do I set a string value in an ExternalStructure ?
>
> Annick
>
>
>
>
>




More information about the Squeak-dev mailing list