How to use ExternalAddress in callouts with new FFI?
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, -- Mariano http://marianopeck.wordpress.com
On Mon, Dec 28, 2015 at 5:11 PM, Mariano Martinez Peck < marianopeck@gmail.com> 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,
-- Mariano http://marianopeck.wordpress.com
-- Mariano http://marianopeck.wordpress.com
On 28 Dec 2015, at 23:11, Mariano Martinez Peck <marianopeck@gmail.com> wrote:
On Mon, Dec 28, 2015 at 5:11 PM, Mariano Martinez Peck <marianopeck@gmail.com <mailto:marianopeck@gmail.com>> 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,
-- Mariano http://marianopeck.wordpress.com <http://marianopeck.wordpress.com/>
-- Mariano http://marianopeck.wordpress.com <http://marianopeck.wordpress.com/>
participants (2)
-
Esteban Lorenzano -
Mariano Martinez Peck