[squeak-dev] Re: FFI related questions

Andreas Raab andreas.raab at gmx.de
Thu Jan 7 01:25:54 UTC 2010


Igor Stasenko wrote:
> 2010/1/6 vagy <vagy at freemail.gr>:
>> I see, thanx for the info. Well then i'll put DoubleArrays on hold for now
>> and craft something special for my project's use case.
>> Did you take a look at the other issues i raised about FFI? (i can't paste a
>> link to the relevant message at the moment because the message archive
>> server
>> is down). But I would definitely like a word from you before going on with
>> it.
>> In a nutshell:
>> - Being able to change single values (and not only the values contained in
>> Arrays)
>>  when passed down to C through pointer arguments
>>  (for instance if you pass down an Integer through a long* argument, FFI
>> tells
>>  you that you cant treat an Integer like a pointer, when the intended usage
>> is
>>  treating it like in C, i.e. change the value of the pointed memory)
>> - Have FFI helper functions (that a C client can link against) that create
>>  whatever Smalltalk Arrays FFI is able to handle (this is inspired from
>> Java's JNI)
>> - Expose interpreterProxy through FFI for advanced uses (sic!) :-)
>>  (Though i don't completely understand the consequences of that and it feels
>> a little
>>  bit dangerous)
>>
> 
> Not a bit more dangerous than FFI itself :)
> 
> By changing a module-loading logic a bit (in sqNamedPrims.c -
> findAndLoadModule() function)
> to attempt to call the setInterpreter() function if it available, even
> for FFI module.

The alternative is to make a plugin with a single primitive and link the 
resulting C file with your libraries. As a result you have a "plugin" 
and a set of FFI entry points. Then call the plugin primitive first to 
ensure the plugin is correctly initialized (i.e., interpreterProxy is 
exported) and then call your FFI entry points. Works just as well and 
doesn't require custom VM hacks.

Cheers,
   - Andreas

> Then all you have to do in your module is to define that function, and
> you can use it to
> store pointer to VM API, which will let you create squeak objects and
> have fun :)
> 
>> Cheers
>>  - Vagelis
>>
> 




More information about the Squeak-dev mailing list