How to use ExternalAddress in callouts with new FFI?

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

How to use ExternalAddress in callouts with new FFI?

Mariano Martinez Peck
Hi Esteban,

Previously, I was doing with NB something like this:

pointer := NativeBoost allocate: 4.
self primitiveWhatever: pointer

and:

primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
^ self nbCall: #( int void (NBExternalAddress pointer ) )


But of course that doesn't work with latest FFI. So I tried instead:

pointer := ExternalAddress allocate: 4.
primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
 ^ self nbCall: #( int void (ExternalAddress pointer ) )

But then I get a ExternalAddress class #asExternalTypeOn:  which is sent in FFICallout >> resolveType:

Any idea how can I use ExternalAddress in the signature of the FFI primitive call?
What am I doing wrong?

Thanks in advance, 


--
Reply | Threaded
Open this post in threaded view
|

Re: How to use ExternalAddress in callouts with new FFI?

Mariano Martinez Peck


On Mon, Dec 28, 2015 at 5:11 PM, Mariano Martinez Peck <[hidden email]> wrote:
Hi Esteban,

Previously, I was doing with NB something like this:

pointer := NativeBoost allocate: 4.
self primitiveWhatever: pointer

and:

primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
^ self nbCall: #( int void (NBExternalAddress pointer ) )


But of course that doesn't work with latest FFI. So I tried instead:

pointer := ExternalAddress allocate: 4.
primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
 ^ self nbCall: #( int void (ExternalAddress pointer ) )


It looks like if I set "void*" rather than ExternalAddress it does work.
Is this the expected path?

 
But then I get a ExternalAddress class #asExternalTypeOn:  which is sent in FFICallout >> resolveType:

Any idea how can I use ExternalAddress in the signature of the FFI primitive call?
What am I doing wrong?


 
Thanks in advance, 


--



--
Reply | Threaded
Open this post in threaded view
|

Re: How to use ExternalAddress in callouts with new FFI?

EstebanLM

On 28 Dec 2015, at 23:11, Mariano Martinez Peck <[hidden email]> wrote:



On Mon, Dec 28, 2015 at 5:11 PM, Mariano Martinez Peck <[hidden email]> wrote:
Hi Esteban,

Previously, I was doing with NB something like this:

pointer := NativeBoost allocate: 4.
self primitiveWhatever: pointer

and:

primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
 ^ self nbCall: #( int void (NBExternalAddress pointer ) )


But of course that doesn't work with latest FFI. So I tried instead:

pointer := ExternalAddress allocate: 4.
primitiveWhatever: pointer
<primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode >
 ^ self nbCall: #( int void (ExternalAddress pointer ) )


It looks like if I set "void*" rather than ExternalAddress it does work.
Is this the expected path?

so.. ExternalAddress *should* map to void* by it self. If it does not, there is a bug (please report :P)
but yes, using void* as argument should work out of the box so should not get the error below (none of my tests caused that either, so I do not understand why it can happen… I guess something in your code I do not completely understand).
in general, I recommend to use the C type (void*) instead the pharo type (ExternalAddress)… the whole idea below NB was to provide an interfase where you can just copy and paste the C definition from a header file… even if that’s not the case all the time. 

Esteban


 
But then I get a ExternalAddress class #asExternalTypeOn:  which is sent in FFICallout >> resolveType:

Any idea how can I use ExternalAddress in the signature of the FFI primitive call?
What am I doing wrong?


 
Thanks in advance, 


-- 



--